Skip to content

Commit

Permalink
add LevelEnabled function
Browse files Browse the repository at this point in the history
  • Loading branch information
cnotch committed Dec 8, 2020
1 parent 3f063d0 commit cfda439
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions global.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func ReplaceGlobal(logger *Logger) func() {
return func() { ReplaceGlobal(prev) }
}

// LevelEnabled 日志对象指定的级别是否启用
func LevelEnabled(lvl Level) bool {
return L().LevelEnabled(lvl)
}

// Debug logs a message at DebugLevel. The message includes any fields passed
// at the log site, as well as any fields accumulated on the logger.
func Debug(msg string, fields ...Field) {
Expand Down
8 changes: 8 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ func (l *Logger) With(opts ...Option) *Logger {
return c
}

// LevelEnabled 日志对象指定的级别是否启用
func (l *Logger) LevelEnabled(lvl Level) bool {
if lvl < DebugLevel || lvl > FatalLevel {
return false
}
return l.core.Enabled(lvl)
}

// Debug logs a message at DebugLevel. The message includes any fields passed
// at the log site, as well as any fields accumulated on the logger.
func (l *Logger) Debug(msg string, fields ...Field) {
Expand Down

0 comments on commit cfda439

Please sign in to comment.