• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

benchmarks/H13-Nov-2019-1,168946

buffer/H13-Nov-2019-311160

internal/H13-Nov-2019-647351

zapcore/H13-Nov-2019-6,2044,442

zapgrpc/H13-Nov-2019-217136

zaptest/H13-Nov-2019-1,153648

.codecov.ymlH A D13-Nov-2019801 1815

.gitignoreH A D13-Nov-2019320 3326

.readme.tmplH A D13-Nov-20193.8 KiB11080

.travis.ymlH A D13-Nov-2019334 2419

CHANGELOG.mdH A D13-Nov-201912.3 KiB353260

CODE_OF_CONDUCT.mdH A D13-Nov-20193.1 KiB7657

CONTRIBUTING.mdH A D13-Nov-20192.4 KiB8260

FAQ.mdH A D13-Nov-20196 KiB156116

MakefileH A D13-Nov-20191.6 KiB5843

README.mdH A D13-Nov-20195.1 KiB135105

array.goH A D13-Nov-20197.8 KiB321211

array_test.goH A D13-Nov-20195 KiB10878

checklicense.shH A D13-Nov-2019294 1813

common_test.goH A D13-Nov-20192 KiB5829

config.goH A D13-Nov-20198.6 KiB244143

config_test.goH A D13-Nov-20193.8 KiB10977

doc.goH A D13-Nov-20195.1 KiB1141

encoder.goH A D13-Nov-20192.7 KiB7643

encoder_test.goH A D13-Nov-20193.3 KiB8955

error.goH A D13-Nov-20192.7 KiB8138

error_test.goH A D13-Nov-20193.7 KiB10067

example_test.goH A D13-Nov-20199.8 KiB328178

field.goH A D13-Nov-201916.2 KiB526338

field_test.goH A D13-Nov-201913.2 KiB260222

flag.goH A D13-Nov-20191.6 KiB4010

flag_test.goH A D13-Nov-20193.2 KiB10368

glide.yamlH A D13-Nov-2019771 3534

global.goH A D13-Nov-20195.2 KiB169106

global_go112.goH A D13-Nov-20191.2 KiB272

global_prego112.goH A D13-Nov-20191.2 KiB272

global_test.goH A D13-Nov-20199.2 KiB281220

go.modH A D13-Nov-2019221 129

go.sumH A D13-Nov-20195.1 KiB5756

http_handler.goH A D13-Nov-20192.4 KiB8243

http_handler_test.goH A D13-Nov-20194.2 KiB13287

level.goH A D13-Nov-20194.6 KiB13355

level_test.goH A D13-Nov-20193.7 KiB11885

logger.goH A D13-Nov-20199.8 KiB306171

logger_bench_test.goH A D13-Nov-20195.4 KiB223172

logger_test.goH A D13-Nov-201913.5 KiB433366

options.goH A D13-Nov-20193.8 KiB11049

sink.goH A D13-Nov-20194.5 KiB162113

sink_test.goH A D13-Nov-20193.2 KiB10166

stacktrace.goH A D13-Nov-20193.8 KiB12778

stacktrace_ext_test.goH A D13-Nov-20196.6 KiB192115

stacktrace_test.goH A D13-Nov-20192.5 KiB7649

sugar.goH A D13-Nov-201910.2 KiB305154

sugar_test.goH A D13-Nov-201913 KiB375318

time.goH A D13-Nov-20191.2 KiB285

time_test.goH A D13-Nov-20191.5 KiB4319

tools.goH A D13-Nov-20191.2 KiB294

writer.goH A D13-Nov-20193.5 KiB10046

writer_test.goH A D13-Nov-20195.7 KiB186141

README.md

1# :zap: zap [![GoDoc][doc-img]][doc] [![Build Status][ci-img]][ci] [![Coverage Status][cov-img]][cov]
2
3Blazing fast, structured, leveled logging in Go.
4
5## Installation
6
7`go get -u go.uber.org/zap`
8
9Note that zap only supports the two most recent minor versions of Go.
10
11## Quick Start
12
13In contexts where performance is nice, but not critical, use the
14`SugaredLogger`. It's 4-10x faster than other structured logging
15packages and includes both structured and `printf`-style APIs.
16
17```go
18logger, _ := zap.NewProduction()
19defer logger.Sync() // flushes buffer, if any
20sugar := logger.Sugar()
21sugar.Infow("failed to fetch URL",
22  // Structured context as loosely typed key-value pairs.
23  "url", url,
24  "attempt", 3,
25  "backoff", time.Second,
26)
27sugar.Infof("Failed to fetch URL: %s", url)
28```
29
30When performance and type safety are critical, use the `Logger`. It's even
31faster than the `SugaredLogger` and allocates far less, but it only supports
32structured logging.
33
34```go
35logger, _ := zap.NewProduction()
36defer logger.Sync()
37logger.Info("failed to fetch URL",
38  // Structured context as strongly typed Field values.
39  zap.String("url", url),
40  zap.Int("attempt", 3),
41  zap.Duration("backoff", time.Second),
42)
43```
44
45See the [documentation][doc] and [FAQ](FAQ.md) for more details.
46
47## Performance
48
49For applications that log in the hot path, reflection-based serialization and
50string formatting are prohibitively expensive — they're CPU-intensive
51and make many small allocations. Put differently, using `encoding/json` and
52`fmt.Fprintf` to log tons of `interface{}`s makes your application slow.
53
54Zap takes a different approach. It includes a reflection-free, zero-allocation
55JSON encoder, and the base `Logger` strives to avoid serialization overhead
56and allocations wherever possible. By building the high-level `SugaredLogger`
57on that foundation, zap lets users *choose* when they need to count every
58allocation and when they'd prefer a more familiar, loosely typed API.
59
60As measured by its own [benchmarking suite][], not only is zap more performant
61than comparable structured logging packages — it's also faster than the
62standard library. Like all benchmarks, take these with a grain of salt.<sup
63id="anchor-versions">[1](#footnote-versions)</sup>
64
65Log a message and 10 fields:
66
67| Package | Time | Time % to zap | Objects Allocated |
68| :------ | :--: | :-----------: | :---------------: |
69| :zap: zap | 862 ns/op | +0% | 5 allocs/op
70| :zap: zap (sugared) | 1250 ns/op | +45% | 11 allocs/op
71| zerolog | 4021 ns/op | +366% | 76 allocs/op
72| go-kit | 4542 ns/op | +427% | 105 allocs/op
73| apex/log | 26785 ns/op | +3007% | 115 allocs/op
74| logrus | 29501 ns/op | +3322% | 125 allocs/op
75| log15 | 29906 ns/op | +3369% | 122 allocs/op
76
77Log a message with a logger that already has 10 fields of context:
78
79| Package | Time | Time % to zap | Objects Allocated |
80| :------ | :--: | :-----------: | :---------------: |
81| :zap: zap | 126 ns/op | +0% | 0 allocs/op
82| :zap: zap (sugared) | 187 ns/op | +48% | 2 allocs/op
83| zerolog | 88 ns/op | -30% | 0 allocs/op
84| go-kit | 5087 ns/op | +3937% | 103 allocs/op
85| log15 | 18548 ns/op | +14621% | 73 allocs/op
86| apex/log | 26012 ns/op | +20544% | 104 allocs/op
87| logrus | 27236 ns/op | +21516% | 113 allocs/op
88
89Log a static string, without any context or `printf`-style templating:
90
91| Package | Time | Time % to zap | Objects Allocated |
92| :------ | :--: | :-----------: | :---------------: |
93| :zap: zap | 118 ns/op | +0% | 0 allocs/op
94| :zap: zap (sugared) | 191 ns/op | +62% | 2 allocs/op
95| zerolog | 93 ns/op | -21% | 0 allocs/op
96| go-kit | 280 ns/op | +137% | 11 allocs/op
97| standard library | 499 ns/op | +323% | 2 allocs/op
98| apex/log | 1990 ns/op | +1586% | 10 allocs/op
99| logrus | 3129 ns/op | +2552% | 24 allocs/op
100| log15 | 3887 ns/op | +3194% | 23 allocs/op
101
102## Development Status: Stable
103
104All APIs are finalized, and no breaking changes will be made in the 1.x series
105of releases. Users of semver-aware dependency management systems should pin
106zap to `^1`.
107
108## Contributing
109
110We encourage and support an active, healthy community of contributors &mdash;
111including you! Details are in the [contribution guide](CONTRIBUTING.md) and
112the [code of conduct](CODE_OF_CONDUCT.md). The zap maintainers keep an eye on
113issues and pull requests, but you can also report any negative conduct to
114oss-conduct@uber.com. That email list is a private, safe space; even the zap
115maintainers don't have access, so don't hesitate to hold us to a high
116standard.
117
118<hr>
119
120Released under the [MIT License](LICENSE.txt).
121
122<sup id="footnote-versions">1</sup> In particular, keep in mind that we may be
123benchmarking against slightly older versions of other packages. Versions are
124pinned in the [benchmarks/go.mod][] file. [↩](#anchor-versions)
125
126[doc-img]: https://godoc.org/go.uber.org/zap?status.svg
127[doc]: https://godoc.org/go.uber.org/zap
128[ci-img]: https://travis-ci.com/uber-go/zap.svg?branch=master
129[ci]: https://travis-ci.com/uber-go/zap
130[cov-img]: https://codecov.io/gh/uber-go/zap/branch/master/graph/badge.svg
131[cov]: https://codecov.io/gh/uber-go/zap
132[benchmarking suite]: https://github.com/uber-go/zap/tree/master/benchmarks
133[benchmarks/go.mod]: https://github.com/uber-go/zap/blob/master/benchmarks/go.mod
134
135