Skip to content

Commit

Permalink
Merge pull request #120 from hashicorp/f-getlevel
Browse files Browse the repository at this point in the history
Add GetLevel to Logger interface
  • Loading branch information
evanphx committed Dec 6, 2022
2 parents 0d6179f + 0b22181 commit 8b7499a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion intlogger.go
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
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
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

0 comments on commit 8b7499a

Please sign in to comment.