Skip to content

Commit

Permalink
Merge pull request #15 from leonidasdeim/get-level
Browse files Browse the repository at this point in the history
Get level
  • Loading branch information
leodeim authored Dec 22, 2023
2 parents 555c433 + 5158cf6 commit 6f26168
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func defaultLogger() {

func customLevel() {
l := log.New(log.WithName("cust"), log.WithLevel(log.Warning))
l.Warning().Msg("I only logging Warning level and above")
l.Warning().Prop("level", string(l.Level())).Msg("I only logging Warning level and above")
l.Info().Msg("This will not be writter to the log")
}

Expand Down
18 changes: 18 additions & 0 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
type Logger interface {
NewLocal(opts ...Op) Logger
SetLevel(level Level) error
Level() Level
Close()
Info() *message
Error() *message
Expand All @@ -37,6 +38,14 @@ var levels = map[Level]int{
Fatal: 4,
}

var levelsRev = map[int]Level{
0: Debug,
1: Info,
2: Warning,
3: Error,
4: Fatal,
}

const (
DefaultLevel = Info
DefaultName = "<...>"
Expand Down Expand Up @@ -192,6 +201,15 @@ func (l *log) SetLevel(level Level) error {
return nil
}

// Get log level for current logger instance
func (l *log) Level() Level {
if v, ok := levelsRev[l.local.level]; ok {
return v
}

return ""
}

// Close logger, should be closed before application exit in case of non blocking mode
func (l *log) Close() {
defer func() {
Expand Down

0 comments on commit 6f26168

Please sign in to comment.