Skip to content

Commit

Permalink
fix: slog rename levels from XLevel to LevelX
Browse files Browse the repository at this point in the history
  • Loading branch information
mdigger committed Dec 14, 2022
1 parent 53f5b02 commit 241f397
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/mdigger/graylog

go 1.19

require golang.org/x/exp v0.0.0-20221205204356-47842c84f3db
require golang.org/x/exp v0.0.0-20221212164502-fae10dda9338
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db h1:D/cFflL63o2KSLJIwjlcIt8PR064j/xsmdEJL/YvY/o=
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/exp v0.0.0-20221212164502-fae10dda9338 h1:OvjRkcNHnf6/W5FZXSxODbxwD+X7fspczG7Jn/xQVD4=
golang.org/x/exp v0.0.0-20221212164502-fae10dda9338/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
4 changes: 2 additions & 2 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type handler struct {

// Enabled reports whether the handler handles records at the slog.DebugLevel.
func (h handler) Enabled(l slog.Level) bool {
return l >= slog.DebugLevel
return l >= slog.LevelDebug
}

// Handle send the log Record to Graylog server.
Expand Down Expand Up @@ -60,7 +60,7 @@ func (h handler) Handle(r slog.Record) error {
}

// add source file info on warning and errors only
if r.Level >= slog.WarnLevel {
if r.Level >= slog.LevelWarn {
if file, line := r.SourceLine(); line != 0 {
_ = writeAttrValue(buf, "file", file+":"+strconv.Itoa(line))
}
Expand Down
18 changes: 9 additions & 9 deletions level.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ const (

func level(l slog.Level) priority {
switch {
case l < slog.DebugLevel:
return log_DEBUG + priority(slog.DebugLevel-l.Level())
case l < slog.InfoLevel:
case l < slog.LevelDebug:
return log_DEBUG + priority(slog.LevelDebug-l.Level())
case l < slog.LevelInfo:
return log_DEBUG
case l == slog.InfoLevel:
case l == slog.LevelInfo:
return log_INFO
case l < slog.WarnLevel:
case l < slog.LevelWarn:
return log_NOTICE
case l < slog.ErrorLevel:
case l < slog.LevelError:
return log_WARNING
case l == slog.ErrorLevel:
case l == slog.LevelError:
return log_ERR
case l == slog.ErrorLevel+1:
case l == slog.LevelError+1:
return log_CRIT
case l == slog.ErrorLevel+2:
case l == slog.LevelError+2:
return log_ALERT
default:
return log_EMERG
Expand Down

0 comments on commit 241f397

Please sign in to comment.