mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-08 08:10:30 +00:00
test(logging): add logtest.NewLogger (#1300)
Return a `Logger` and its recording `Handler` together, so tests no longer need the two-line setup. Stacked on https://gitea.com/gitea/runner/pulls/1295. Assisted-by: Codet Co-authored-by: bircni <[email protected]> Reviewed-on: https://gitea.com/gitea/runner/pulls/1300 Reviewed-by: bircni <[email protected]>
This commit is contained in:
1 parent
de961b91eb
commit
3bc5cc03f8
7 files changed
+21
-32
No files matched your search
@@ -92,8 +92,7 @@ func frameOf(t *testing.T, pc uintptr) runtime.Frame {
|
||||
}
|
||||
|
||||
func TestCallerPC(t *testing.T) {
|
||||
h := logtest.New()
|
||||
l := logging.New(h)
|
||||
l, h := logtest.NewLogger()
|
||||
l.Infof("method")
|
||||
l.Info("method")
|
||||
for _, r := range h.AllRecords() {
|
||||
|
||||
@@ -29,6 +29,12 @@ func New() *Handler {
|
||||
return NewWithLevel(logging.LevelInfo)
|
||||
}
|
||||
|
||||
// NewLogger returns a Logger writing to a new Handler from New, and that Handler.
|
||||
func NewLogger() (*logging.Logger, *Handler) {
|
||||
h := New()
|
||||
return logging.New(h), h
|
||||
}
|
||||
|
||||
func NewWithLevel(minLevel logging.Level) *Handler {
|
||||
return &Handler{store: &store{}, minLevel: minLevel}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user