Skip to content

Commit

Permalink
Use slog from the standard library
Browse files Browse the repository at this point in the history
Instead of x/exp.
  • Loading branch information
Theo Willows committed Aug 10, 2023
1 parent 65e13ae commit 4fe6ecf
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
go-version:
- '1.20'
- '1.21'

steps:
- uses: actions/checkout@v3
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

Slug is a [`slog.Handler`] that writes human-readable logs.

[`slog`] isn’t finalised yet. Slug is even more unstable.
Slug is still in early development and can be a bit unstable.

![](./_doc/img/screenshot.png)

Expand All @@ -27,5 +27,4 @@ Slug is a [`slog.Handler`] that writes human-readable logs.

The output is meant for human eyes only, not to be parsed

[`slog`]: https://pkg.go.dev/golang.org/x/exp/slog
[`slog.Handler`]: https://pkg.go.dev/golang.org/x/exp/slog#Handler
[`slog.Handler`]: https://pkg.go.dev/log/slog#Handler
2 changes: 1 addition & 1 deletion _doc/img/screenshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"context"
"errors"
"fmt"
"log/slog"
"os"
"time"

"github.com/dotse/slug"
"golang.org/x/exp/slog"
)

func main() {
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
module github.com/dotse/slug

go 1.20
go 1.21

require (
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/logrusorgru/aurora/v4 v4.0.0
github.com/stretchr/testify v1.8.2
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0
golang.org/x/text v0.8.0
github.com/stretchr/testify v1.8.4
golang.org/x/text v0.12.0
)

require (
Expand Down
17 changes: 4 additions & 13 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
Expand All @@ -7,19 +6,11 @@ github.com/logrusorgru/aurora/v4 v4.0.0 h1:sRjfPpun/63iADiSvGGjgA1cAYegEWMPCJdUp
github.com/logrusorgru/aurora/v4 v4.0.0/go.mod h1:lP0iIa2nrnT/qoFXcOZSrZQpJ1o6n2CUf/hyHi2Q4ZQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 h1:pVgRXcIictcr+lBQIFeiwuwtDIs4eL21OuM9nyAADmo=
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
5 changes: 3 additions & 2 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"context"
"fmt"
"io"
"log/slog"
"runtime"
"strings"
"sync"

"github.com/dotse/slug/internal"
"github.com/logrusorgru/aurora/v4"
"golang.org/x/exp/slog"
"golang.org/x/text/language"
"golang.org/x/text/message"
)
Expand Down Expand Up @@ -93,8 +93,9 @@ func (h *Handler) Handle(_ context.Context, r slog.Record) error {
h.printAttr(prefix, attr)
}

r.Attrs(func(attr slog.Attr) {
r.Attrs(func(attr slog.Attr) bool {
h.printAttr(prefix, attr)
return true
})

if h.shared.options.AddSource && r.PC != 0 {
Expand Down
6 changes: 3 additions & 3 deletions handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package slug_test
import (
"context"
"errors"
"log/slog"
"net/netip"
"regexp"
"strings"
"testing"
"time"

log "github.com/dotse/slug"
"github.com/dotse/slug"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slog"
)

func TestHandler(t *testing.T) {
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestHandler(t *testing.T) {

var (
buffer strings.Builder
h = log.NewHandler(log.HandlerOptions{
h = slug.NewHandler(slug.HandlerOptions{
HandlerOptions: slog.HandlerOptions{
AddSource: true,
},
Expand Down

0 comments on commit 4fe6ecf

Please sign in to comment.