Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GetLevel to Logger interface #120

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion intlogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ func needsQuoting(str string) bool {
// 2. Color the whole log line, based on the level.
// 3. Color only the header (level) part of the log line.
// 4. Color both the header and fields of the log line.
//
func (l *intLogger) logPlain(t time.Time, name string, level Level, msg string, args ...interface{}) {

if !l.disableTime {
Expand Down Expand Up @@ -845,6 +844,11 @@ func (l *intLogger) SetLevel(level Level) {
atomic.StoreInt32(l.level, int32(level))
}

// Returns the current level
func (l *intLogger) GetLevel() Level {
return Level(atomic.LoadInt32(l.level))
}

// Create a *log.Logger that will send it's data through this Logger. This
// allows packages that expect to be using the standard library log to actually
// use this logger.
Expand Down
3 changes: 3 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ type Logger interface {
// implementation cannot update the level on the fly, it should no-op.
SetLevel(level Level)

// Returns the current level
GetLevel() Level

// Return a value that conforms to the stdlib log.Logger interface
StandardLogger(opts *StandardLoggerOptions) *log.Logger

Expand Down
2 changes: 2 additions & 0 deletions nulllogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func (l *nullLogger) ResetNamed(name string) Logger { return l }

func (l *nullLogger) SetLevel(level Level) {}

func (l *nullLogger) GetLevel() Level { return NoLevel }

func (l *nullLogger) StandardLogger(opts *StandardLoggerOptions) *log.Logger {
return log.New(l.StandardWriter(opts), "", log.LstdFlags)
}
Expand Down