Skip to content

Commit daaf96c

Browse files
authored
Merge pull request #79 from cdr/simplify
Remove Value interface and ForceJSON
2 parents a13a242 + 56c5fd9 commit daaf96c

File tree

11 files changed

+179
-219
lines changed

11 files changed

+179
-219
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ log := sloghuman.Make(os.Stdout)
4040
log.Info(context.Background(), "my message here",
4141
slog.F("field_name", "something or the other"),
4242
slog.F("some_map", slog.M(
43-
slog.F("nested_fields", "wowow"),
43+
slog.F("nested_fields", time.Date(2000, time.February, 5, 4, 4, 4, 0, time.UTC)),
4444
)),
4545
slog.Error(
4646
xerrors.Errorf("wrap1: %w",
@@ -52,7 +52,7 @@ log.Info(context.Background(), "my message here",
5252
)
5353
```
5454

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

5757
## Why?
5858

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

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

example_forcejson_test.go

Lines changed: 0 additions & 30 deletions
This file was deleted.

example_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net"
77
"os"
88
"testing"
9+
"time"
910

1011
"go.opencensus.io/trace"
1112
"golang.org/x/xerrors"
@@ -22,7 +23,7 @@ func Example() {
2223
log.Info(context.Background(), "my message here",
2324
slog.F("field_name", "something or the other"),
2425
slog.F("some_map", slog.M(
25-
slog.F("nested_fields", "wowow"),
26+
slog.F("nested_fields", time.Date(2000, time.February, 5, 4, 4, 4, 0, time.UTC)),
2627
)),
2728
slog.Error(
2829
xerrors.Errorf("wrap1: %w",
@@ -33,7 +34,7 @@ func Example() {
3334
),
3435
)
3536

36-
// 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"}} ...
37+
// 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"}} ...
3738
// "error": wrap1:
3839
// main.main
3940
// /Users/nhooyr/src/cdr/scratch/example.go:22

example_value_test.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

go.mod

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ module cdr.dev/slog
33
go 1.13
44

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

0 commit comments

Comments
 (0)