Skip to content

Commit

Permalink
move slogex to separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
viatoriche committed Oct 17, 2024
1 parent 319ed42 commit c265fa8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/acronis/go-stacktrace

go 1.22.6
go 1.20.6
5 changes: 5 additions & 0 deletions slogex/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module slogex

go 1.22.6

require github.com/acronis/go-stacktrace v0.2.0
2 changes: 2 additions & 0 deletions slogex/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/acronis/go-stacktrace v0.2.0 h1:aUME2BnO2WwBpmidhSq+C2cCm6T0i7u1mwraetKPyjQ=
github.com/acronis/go-stacktrace v0.2.0/go.mod h1:FOvjPOpMOpJhNgt2adD+FEnOpzcOzUBeiRkPaAd2aLQ=
8 changes: 5 additions & 3 deletions slogex.go → slogex/slogex.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package stacktrace
package slogex

import (
"fmt"
"log/slog"

"github.com/acronis/go-stacktrace"
)

func ErrToSlogAttr(err error, opts ...TracesOpt) slog.Attr {
func ErrToSlogAttr(err error, opts ...stacktrace.TracesOpt) slog.Attr {
if err == nil {
return slog.Attr{}
}

st, ok := Unwrap(err)
st, ok := stacktrace.Unwrap(err)
if !ok {
return slog.String("error", err.Error())
}
Expand Down
14 changes: 8 additions & 6 deletions slogex_test.go → slogex/slogex_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package stacktrace
package slogex

import (
"fmt"
"log/slog"
"reflect"
"testing"

"github.com/acronis/go-stacktrace"
)

func TestErrToSlogAttr(t *testing.T) {
type args struct {
err error
opts []TracesOpt
opts []stacktrace.TracesOpt
}
tests := []struct {
name string
Expand All @@ -20,8 +22,8 @@ func TestErrToSlogAttr(t *testing.T) {
{
name: "Test simple",
args: args{
err: New("error message", "location.raml"),
opts: []TracesOpt{},
err: stacktrace.New("error message", "location.raml"),
opts: []stacktrace.TracesOpt{},
},
want: slog.Group(
"tracebacks", "traces", []slog.Attr{
Expand All @@ -43,15 +45,15 @@ func TestErrToSlogAttr(t *testing.T) {
name: "Test is not a stacktrace",
args: args{
err: fmt.Errorf("error message"),
opts: []TracesOpt{},
opts: []stacktrace.TracesOpt{},
},
want: slog.String("error", "error message"),
},
{
name: "Test nil err",
args: args{
err: nil,
opts: []TracesOpt{},
opts: []stacktrace.TracesOpt{},
},
want: slog.Attr{},
},
Expand Down

0 comments on commit c265fa8

Please sign in to comment.