Skip to content

Commit

Permalink
make the log levels customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed Oct 25, 2023
1 parent 1a9c050 commit 7aeabab
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Other global parameters:
```go
slogzap.SourceKey = "source"
slogzap.ErrorKeys = []string{"error", "err"}
slogzap.LogLevels = map[slog.Level]zerolog.Level{...}
```

### Example
Expand Down
2 changes: 1 addition & 1 deletion handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (h *ZapHandler) Handle(ctx context.Context, record slog.Record) error {
converter = h.option.Converter
}

level := levelMap[record.Level]
level := LogLevels[record.Level]
fields := converter(h.option.AddSource, h.option.ReplaceAttr, h.attrs, h.groups, &record)

h.option.Logger.Log(level, record.Message, fields...)
Expand Down
2 changes: 1 addition & 1 deletion zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"go.uber.org/zap/zapcore"
)

var levelMap = map[slog.Level]zapcore.Level{
var LogLevels = map[slog.Level]zapcore.Level{
slog.LevelDebug: zap.DebugLevel,
slog.LevelInfo: zap.InfoLevel,
slog.LevelWarn: zap.WarnLevel,
Expand Down

0 comments on commit 7aeabab

Please sign in to comment.