Skip to content

Commit

Permalink
feat(log): add Logger() method for Helper (#3443)
Browse files Browse the repository at this point in the history
* feat(log): add Logger() method for Helper

* chore(log): add test case for Helper.Logger()
  • Loading branch information
DCjanus authored Nov 5, 2024
1 parent 3ecb1d6 commit f8b97f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions log/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ func (h *Helper) Enabled(level Level) bool {
return true
}

// Logger returns logger in the helper.
func (h *Helper) Logger() Logger {
return h.logger
}

// Log Print log by level and keyvals.
func (h *Helper) Log(level Level, keyvals ...interface{}) {
_ = h.logger.Log(level, keyvals...)
Expand Down
13 changes: 12 additions & 1 deletion log/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import (
)

func TestHelper(_ *testing.T) {
logger := With(DefaultLogger, "ts", DefaultTimestamp, "caller", DefaultCaller)
logger := With(
DefaultLogger,
"ts", DefaultTimestamp,
"caller", DefaultCaller,
"module", "test",
)
log := NewHelper(logger)

log.Log(LevelDebug, "msg", "test debug")
Expand All @@ -19,6 +24,12 @@ func TestHelper(_ *testing.T) {
log.Warn("test warn")
log.Warnf("test %s", "warn")
log.Warnw("log", "test warn")

subLogger := With(log.Logger(),
"module", "sub",
)
subLog := NewHelper(subLogger)
subLog.Infof("sub logger test with level %s", "info")
}

func TestHelperWithMsgKey(_ *testing.T) {
Expand Down

0 comments on commit f8b97f6

Please sign in to comment.