Skip to content

Commit

Permalink
Flatten convertLevel
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Mar 6, 2024
1 parent 95ccf15 commit 51829bd
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions bridges/sloghandler/handler.go
Expand Up @@ -56,7 +56,9 @@ func (h *Handler) Handle(ctx context.Context, r slog.Record) error {
var record log.Record
record.SetTimestamp(r.Time)
record.SetBody(log.StringValue(r.Message))
record.SetSeverity(convertLevel(r.Level))

const sevOffset = slog.Level(log.SeverityDebug) - slog.LevelDebug
record.SetSeverity(log.Severity(r.Level + sevOffset))

record.AddAttributes(h.attrs...)
if h.group != nil {
Expand Down Expand Up @@ -126,10 +128,6 @@ func (h *Handler) WithGroup(name string) slog.Handler {
return &h2
}

func convertLevel(l slog.Level) log.Severity {
return log.Severity(l + 9)
}

func convertAttr(attr slog.Attr) []log.KeyValue {
if attr.Key == "" {
if attr.Value.Kind() == slog.KindGroup {
Expand Down

0 comments on commit 51829bd

Please sign in to comment.