Skip to content

Commit

Permalink
update slog library
Browse files Browse the repository at this point in the history
  • Loading branch information
mdigger committed Mar 13, 2023
1 parent 99ff729 commit 0db9ab6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions attrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ func writeAttr(w *buffer, attr slog.Attr, prefix string) {
}

switch attr.Value.Kind() {
case slog.GroupKind:
case slog.KindGroup:
attrs := attr.Value.Group()
for i := range attrs {
writeAttr(w, attrs[i], name)
}
case slog.LogValuerKind:
case slog.KindLogValuer:
attr := slog.Attr{Key: name, Value: attr.Value.Resolve()}
writeAttr(w, attr, "")
default:
Expand Down
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-20230113152452-c42ee1cf562e
require golang.org/x/exp v0.0.0-20230310171629-522b1b587ee0
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-20230113152452-c42ee1cf562e h1:uGuXqQsI2BAE8xNqSqNxhTdDdhlvpBvWFw/KBwtCtjI=
golang.org/x/exp v0.0.0-20230113152452-c42ee1cf562e/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/exp v0.0.0-20230310171629-522b1b587ee0 h1:LGJsf5LRplCck6jUCH3dBL2dmycNruWNF5xugkSlfXw=
golang.org/x/exp v0.0.0-20230310171629-522b1b587ee0/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
17 changes: 9 additions & 8 deletions handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package graylog

import (
"context"
"strconv"
"time"

Expand All @@ -14,12 +15,12 @@ type handler struct {
}

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

// Handle send the log Record to Graylog server.
func (h handler) Handle(r slog.Record) error {
func (h handler) Handle(_ context.Context, r slog.Record) error {
buf := newBuffer()
defer buf.Free()

Expand Down Expand Up @@ -58,12 +59,12 @@ func (h handler) Handle(r slog.Record) error {
buf.WriteString(strconv.Quote(h.w.facility))
}

// add source file info on warning and errors only
if r.Level >= slog.LevelWarn {
if file, line := r.SourceLine(); line != 0 {
_ = writeAttrValue(buf, "file", file+":"+strconv.Itoa(line))
}
}
// FIXME: add source file info on warning and errors only
// if r.Level >= slog.LevelWarn {
// if file, line := r.SourceLine(); line != 0 {
// _ = writeAttrValue(buf, "file", file+":"+strconv.Itoa(line))
// }
// }

// add stored attributes
if len(h.attrs) > 0 {
Expand Down

0 comments on commit 0db9ab6

Please sign in to comment.