Skip to content

Commit

Permalink
up go-stacktrace version for slogex
Browse files Browse the repository at this point in the history
  • Loading branch information
viatoriche committed Oct 17, 2024
1 parent df1b34c commit 31618e1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion slogex/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module slogex

go 1.22.6

require github.com/acronis/go-stacktrace v0.3.0
require github.com/acronis/go-stacktrace v0.4.0
4 changes: 2 additions & 2 deletions slogex/go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github.com/acronis/go-stacktrace v0.3.0 h1:wVYCuxJ/qYG4pLtJoXBMDeM53wBs/Bb3Osxpg6GfRuI=
github.com/acronis/go-stacktrace v0.3.0/go.mod h1:7Yf4nTbD//u5yR21BhiLzitxh8lU8Vb8SakHhoRAyqQ=
github.com/acronis/go-stacktrace v0.4.0 h1:rL+6LxDnQ1/KcaCvF6ftC1Hjg91rjuPjPxS7+xH81xk=
github.com/acronis/go-stacktrace v0.4.0/go.mod h1:7Yf4nTbD//u5yR21BhiLzitxh8lU8Vb8SakHhoRAyqQ=
18 changes: 14 additions & 4 deletions slogex/slogex.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,20 @@ func ErrToSlogAttr(err error, opts ...stacktrace.TracesOpt) slog.Attr {
key := fmt.Sprintf("%d", stackIndex)
stackAttr := slog.Group(
key,
slog.String("type", string(stack.Type)),
slog.String("severity", string(stack.Severity)),
slog.String("position", stack.LinePos),
slog.String("message", stack.Message),
func() []any {
attrs := []any{}
if stack.Type != nil {
attrs = append(attrs, slog.String("type", stack.Type.String()))
}
if stack.Severity != nil {
attrs = append(attrs, slog.String("severity", stack.Severity.String()))
}
if stack.LinePos != nil {
attrs = append(attrs, slog.String("position", *stack.LinePos))
}
attrs = append(attrs, slog.String("message", stack.Message))
return attrs
}()...,
)
stackAttrs = append(stackAttrs, stackAttr)
}
Expand Down
6 changes: 5 additions & 1 deletion slogex/slogex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ func TestErrToSlogAttr(t *testing.T) {
{
name: "Test simple",
args: args{
err: stacktrace.New("error message", "location.raml"),
err: stacktrace.New("error message",
stacktrace.WithLocation("location.raml"),
stacktrace.WithSeverity("error"),
stacktrace.WithType("parsing"),
),
opts: []stacktrace.TracesOpt{},
},
want: slog.Group(
Expand Down

0 comments on commit 31618e1

Please sign in to comment.