Skip to content

Remove Value interface and ForceJSON #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ log := sloghuman.Make(os.Stdout)
log.Info(context.Background(), "my message here",
slog.F("field_name", "something or the other"),
slog.F("some_map", slog.M(
slog.F("nested_fields", "wowow"),
slog.F("nested_fields", time.Date(2000, time.February, 5, 4, 4, 4, 0, time.UTC)),
)),
slog.Error(
xerrors.Errorf("wrap1: %w",
Expand All @@ -52,7 +52,7 @@ log.Info(context.Background(), "my message here",
)
```

![Example output screenshot](https://i.imgur.com/7MJM0VE.png)
![Example output screenshot](https://i.imgur.com/KGRmQFo.png)

## Why?

Expand Down Expand Up @@ -97,9 +97,7 @@ Here is a list of reasons how we improved on zap with slog.
- zap is hard and confusing to extend. There are too many structures and configuration options.

1. Structured logging of Go structures with `json.Marshal`
- All values will be logged with `json.Marshal` unless they implement `fmt.Stringer` or `error`.
- You can force JSON by using [`slog.ForceJSON`](https://godoc.org/cdr.dev/slog#ForceJSON).
- One may implement [`slog.Value`](https://godoc.org/cdr.dev/slog#Value) to override the representation completely.
- Entire encoding process is documented on [godoc](https://godoc.org/cdr.dev/slog#Map.MarshalJSON).
- With zap, We found ourselves often implementing zap's
[ObjectMarshaler](https://godoc.org/go.uber.org/zap/zapcore#ObjectMarshaler) to log Go structures. This was
verbose and most of the time we ended up only implementing `fmt.Stringer` and using `zap.Stringer` instead.
Expand Down
30 changes: 0 additions & 30 deletions example_forcejson_test.go

This file was deleted.

5 changes: 3 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"os"
"testing"
"time"

"go.opencensus.io/trace"
"golang.org/x/xerrors"
Expand All @@ -22,7 +23,7 @@ func Example() {
log.Info(context.Background(), "my message here",
slog.F("field_name", "something or the other"),
slog.F("some_map", slog.M(
slog.F("nested_fields", "wowow"),
slog.F("nested_fields", time.Date(2000, time.February, 5, 4, 4, 4, 0, time.UTC)),
)),
slog.Error(
xerrors.Errorf("wrap1: %w",
Expand All @@ -33,7 +34,7 @@ func Example() {
),
)

// 2019-12-09 05:04:53.398 [INFO] <example.go:16> my message here {"field_name": "something or the other", "some_map": {"nested_fields": "wowow"}} ...
// 2019-12-09 05:04:53.398 [INFO] <example.go:16> my message here {"field_name": "something or the other", "some_map": {"nested_fields": "2000-02-05T04:04:04Z"}} ...
// "error": wrap1:
// main.main
// /Users/nhooyr/src/cdr/scratch/example.go:22
Expand Down
32 changes: 0 additions & 32 deletions example_value_test.go

This file was deleted.

24 changes: 14 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ module cdr.dev/slog
go 1.13

require (
cloud.google.com/go v0.43.0
github.com/alecthomas/chroma v0.6.6
cloud.google.com/go v0.49.0
github.com/alecthomas/chroma v0.7.0
github.com/dlclark/regexp2 v1.2.0 // indirect
github.com/fatih/color v1.7.0
github.com/kylelemons/godebug v1.1.0
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.9 // indirect
go.opencensus.io v0.22.1
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd // indirect
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
google.golang.org/genproto v0.0.0-20190716160619-c506a9f90610
github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 // indirect
github.com/google/go-cmp v0.3.2-0.20191216170541-340f1ebe299e
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.11 // indirect
go.opencensus.io v0.22.2
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
golang.org/x/sys v0.0.0-20191210023423-ac6580df4449 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1
google.golang.org/grpc v1.25.1 // indirect
)
Loading