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

..08-Nov-2019-

buffer/H08-Nov-2019-16675

internal/H08-Nov-2019-14249

zapcore/H08-Nov-2019-2,5871,558

.codecov.ymlH A D08-Nov-2019801 1815

.gitignoreH A D08-Nov-2019293 2923

.readme.tmplH A D08-Nov-20193.8 KiB10980

.travis.ymlH A D08-Nov-2019316 2221

CHANGELOG.mdH A D08-Nov-201910.8 KiB306225

CODE_OF_CONDUCT.mdH A D08-Nov-20193.1 KiB7657

CONTRIBUTING.mdH A D08-Nov-20192.4 KiB8260

FAQ.mdH A D08-Nov-20196 KiB156116

MakefileH A D08-Nov-20192.2 KiB7761

README.mdH A D08-Nov-20195 KiB137108

array.goH A D08-Nov-20197.8 KiB321211

check_license.shH A D08-Nov-2019294 1813

config.goH A D08-Nov-20198.6 KiB244143

doc.goH A D08-Nov-20195.1 KiB1141

encoder.goH A D08-Nov-20192.7 KiB7643

error.goH A D08-Nov-20192.7 KiB8138

field.goH A D08-Nov-201910.3 KiB311185

flag.goH A D08-Nov-20191.6 KiB4010

glide.lockH A D08-Nov-20192.5 KiB7776

glide.yamlH A D08-Nov-2019804 3635

global.goH A D08-Nov-20195.3 KiB170107

http_handler.goH A D08-Nov-20192.4 KiB8243

level.goH A D08-Nov-20194.6 KiB13355

logger.goH A D08-Nov-20199.8 KiB306171

options.goH A D08-Nov-20193.8 KiB11049

sink.goH A D08-Nov-20194.5 KiB162113

stacktrace.goH A D08-Nov-20193.8 KiB12778

sugar.goH A D08-Nov-201910.2 KiB305154

time.goH A D08-Nov-20191.2 KiB285

writer.goH A D08-Nov-20193.5 KiB10046

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 | Objects Allocated |
68| :--- | :---: | :---: |
69| :zap: zap | 3131 ns/op | 5 allocs/op |
70| :zap: zap (sugared) | 4173 ns/op | 21 allocs/op |
71| zerolog | 16154 ns/op | 90 allocs/op |
72| lion | 16341 ns/op | 111 allocs/op |
73| go-kit | 17049 ns/op | 126 allocs/op |
74| logrus | 23662 ns/op | 142 allocs/op |
75| log15 | 36351 ns/op | 149 allocs/op |
76| apex/log | 42530 ns/op | 126 allocs/op |
77
78Log a message with a logger that already has 10 fields of context:
79
80| Package | Time | Objects Allocated |
81| :--- | :---: | :---: |
82| :zap: zap | 380 ns/op | 0 allocs/op |
83| :zap: zap (sugared) | 564 ns/op | 2 allocs/op |
84| zerolog | 321 ns/op | 0 allocs/op |
85| lion | 7092 ns/op | 39 allocs/op |
86| go-kit | 20226 ns/op | 115 allocs/op |
87| logrus | 22312 ns/op | 130 allocs/op |
88| log15 | 28788 ns/op | 79 allocs/op |
89| apex/log | 42063 ns/op | 115 allocs/op |
90
91Log a static string, without any context or `printf`-style templating:
92
93| Package | Time | Objects Allocated |
94| :--- | :---: | :---: |
95| :zap: zap | 361 ns/op | 0 allocs/op |
96| :zap: zap (sugared) | 534 ns/op | 2 allocs/op |
97| zerolog | 323 ns/op | 0 allocs/op |
98| standard library | 575 ns/op | 2 allocs/op |
99| go-kit | 922 ns/op | 13 allocs/op |
100| lion | 1413 ns/op | 10 allocs/op |
101| logrus | 2291 ns/op | 27 allocs/op |
102| apex/log | 3690 ns/op | 11 allocs/op |
103| log15 | 5954 ns/op | 26 allocs/op |
104
105## Development Status: Stable
106
107All APIs are finalized, and no breaking changes will be made in the 1.x series
108of releases. Users of semver-aware dependency management systems should pin
109zap to `^1`.
110
111## Contributing
112
113We encourage and support an active, healthy community of contributors &mdash;
114including you! Details are in the [contribution guide](CONTRIBUTING.md) and
115the [code of conduct](CODE_OF_CONDUCT.md). The zap maintainers keep an eye on
116issues and pull requests, but you can also report any negative conduct to
117oss-conduct@uber.com. That email list is a private, safe space; even the zap
118maintainers don't have access, so don't hesitate to hold us to a high
119standard.
120
121<hr>
122
123Released under the [MIT License](LICENSE.txt).
124
125<sup id="footnote-versions">1</sup> In particular, keep in mind that we may be
126benchmarking against slightly older versions of other packages. Versions are
127pinned in zap's [glide.lock][] file. [↩](#anchor-versions)
128
129[doc-img]: https://godoc.org/go.uber.org/zap?status.svg
130[doc]: https://godoc.org/go.uber.org/zap
131[ci-img]: https://travis-ci.org/uber-go/zap.svg?branch=master
132[ci]: https://travis-ci.org/uber-go/zap
133[cov-img]: https://codecov.io/gh/uber-go/zap/branch/master/graph/badge.svg
134[cov]: https://codecov.io/gh/uber-go/zap
135[benchmarking suite]: https://github.com/uber-go/zap/tree/master/benchmarks
136[glide.lock]: https://github.com/uber-go/zap/blob/master/glide.lock
137