Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nhooyr committed Dec 16, 2019
1 parent a3fbba1 commit 56c5fd9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
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
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

0 comments on commit 56c5fd9

Please sign in to comment.