diff --git a/go.mod b/go.mod index fce4d29..acb4d5d 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/acronis/go-stacktrace -go 1.22.6 +go 1.20.6 diff --git a/slogex/go.mod b/slogex/go.mod new file mode 100644 index 0000000..e8d35ef --- /dev/null +++ b/slogex/go.mod @@ -0,0 +1,5 @@ +module slogex + +go 1.22.6 + +require github.com/acronis/go-stacktrace v0.2.0 diff --git a/slogex/go.sum b/slogex/go.sum new file mode 100644 index 0000000..6a7e323 --- /dev/null +++ b/slogex/go.sum @@ -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= diff --git a/slogex.go b/slogex/slogex.go similarity index 86% rename from slogex.go rename to slogex/slogex.go index fa7bb89..b7e7be9 100644 --- a/slogex.go +++ b/slogex/slogex.go @@ -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()) } diff --git a/slogex_test.go b/slogex/slogex_test.go similarity index 82% rename from slogex_test.go rename to slogex/slogex_test.go index 45b05fc..b68de0a 100644 --- a/slogex_test.go +++ b/slogex/slogex_test.go @@ -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 @@ -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{ @@ -43,7 +45,7 @@ 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"), }, @@ -51,7 +53,7 @@ func TestErrToSlogAttr(t *testing.T) { name: "Test nil err", args: args{ err: nil, - opts: []TracesOpt{}, + opts: []stacktrace.TracesOpt{}, }, want: slog.Attr{}, },