status-im / status-go

The Status module that consumes go-ethereum
https://status.im
Mozilla Public License 2.0
727 stars 247 forks source link

feat(logging)_: introduce custom zap.Core enabling runtime changes #6024

Closed osmaczko closed 4 days ago

osmaczko commented 3 weeks ago

Geth logger allows overriding the log level, format and writer at runtime. To make it interchangeable with zap.Logger, a custom zap.Core has been introduced to enable these features as well.

closes: #6023

status-im-auto commented 3 weeks ago

Jenkins Builds

Click to see older builds (24) | :grey_question: | Commit | :hash: | Finished (UTC) | Duration | Platform | Result | |-|-|-|-|-|-|-| | :heavy_check_mark: | f7c4237c | [#1](https://ci.status.im/job/status-go/job/prs/job/macos/job/aarch64/job/main/job/PR-6024/1/) | 2024-10-31 19:16:51 | ~4 min | `macos` | [:package:`zip`](https://status-im-prs.ams3.cdn.digitaloceanspaces.com/status-go-macos-241031-191246-f7c423-pr6024.zip) | | :heavy_check_mark: | f7c4237c | [#1](https://ci.status.im/job/status-go/job/prs/job/ios/job/PR-6024/1/) | 2024-10-31 19:17:51 | ~5 min | `ios` | [:package:`zip`](https://status-im-prs.ams3.cdn.digitaloceanspaces.com/status-go-ios-241031-191244-f7c423-pr6024.zip) | | :heavy_check_mark: | f7c4237c | [#1](https://ci.status.im/job/status-go/job/prs/job/windows/job/x86_64/job/main/job/PR-6024/1/) | 2024-10-31 19:17:59 | ~5 min | `windows` | [:package:`zip`](https://status-im-prs.ams3.cdn.digitaloceanspaces.com/status-go-windows-241031-191251-f7c423-pr6024.zip) | | :heavy_check_mark: | f7c4237c | [#1](https://ci.status.im/job/status-go/job/prs/job/tests-rpc/job/PR-6024/1/) | 2024-10-31 19:18:05 | ~5 min | `tests-rpc` | [:page_facing_up:`log`](https://ci.status.im/job/status-go/job/prs/job/tests-rpc/job/PR-6024/1//consoleText) | | :heavy_check_mark: | f7c4237c | [#1](https://ci.status.im/job/status-go/job/prs/job/linux/job/x86_64/job/main/job/PR-6024/1/) | 2024-10-31 19:18:26 | ~5 min | `linux` | [:package:`zip`](https://status-im-prs.ams3.cdn.digitaloceanspaces.com/status-go-linux-241031-191246-f7c423-pr6024.zip) | | :heavy_check_mark: | f7c4237c | [#1](https://ci.status.im/job/status-go/job/prs/job/android/job/PR-6024/1/) | 2024-10-31 19:19:03 | ~6 min | `android` | [:package:`aar`](https://status-im-prs.ams3.cdn.digitaloceanspaces.com/status-go-android-241031-191243-f7c423-pr6024.aar) | | :heavy_check_mark: | f7c4237c | [#1](https://ci.status.im/job/status-go/job/prs/job/macos/job/x86_64/job/main/job/PR-6024/1/) | 2024-10-31 19:19:22 | ~6 min | `macos` | [:package:`zip`](https://status-im-prs.ams3.cdn.digitaloceanspaces.com/status-go-macos-241031-191248-f7c423-pr6024.zip) | | :heavy_check_mark: | f7c4237c | [#1](https://ci.status.im/job/status-go/job/prs/job/tests/job/PR-6024/1/) | 2024-10-31 19:47:46 | ~34 min | `tests` | [:page_facing_up:`log`](https://ci.status.im/job/status-go/job/prs/job/tests/job/PR-6024/1//consoleText) | | | | | | | | | | :heavy_check_mark: | 1f4b14b6 | [#2](https://ci.status.im/job/status-go/job/prs/job/macos/job/aarch64/job/main/job/PR-6024/2/) | 2024-10-31 19:20:48 | ~3 min | `macos` | [:package:`zip`](https://status-im-prs.ams3.cdn.digitaloceanspaces.com/status-go-macos-241031-191655-1f4b14-pr6024.zip) | | :heavy_check_mark: | 1f4b14b6 | [#2](https://ci.status.im/job/status-go/job/prs/job/windows/job/x86_64/job/main/job/PR-6024/2/) | 2024-10-31 19:21:54 | ~3 min | `windows` | [:package:`zip`](https://status-im-prs.ams3.cdn.digitaloceanspaces.com/status-go-windows-241031-191805-1f4b14-pr6024.zip) | | :heavy_check_mark: | 1f4b14b6 | [#2](https://ci.status.im/job/status-go/job/prs/job/tests-rpc/job/PR-6024/2/) | 2024-10-31 19:22:29 | ~4 min | `tests-rpc` | [:page_facing_up:`log`](https://ci.status.im/job/status-go/job/prs/job/tests-rpc/job/PR-6024/2//consoleText) | | :heavy_check_mark: | 1f4b14b6 | [#2](https://ci.status.im/job/status-go/job/prs/job/ios/job/PR-6024/2/) | 2024-10-31 19:22:38 | ~4 min | `ios` | [:package:`zip`](https://status-im-prs.ams3.cdn.digitaloceanspaces.com/status-go-ios-241031-191756-1f4b14-pr6024.zip) | | :heavy_check_mark: | 1f4b14b6 | [#2](https://ci.status.im/job/status-go/job/prs/job/linux/job/x86_64/job/main/job/PR-6024/2/) | 2024-10-31 19:24:05 | ~5 min | `linux` | [:package:`zip`](https://status-im-prs.ams3.cdn.digitaloceanspaces.com/status-go-linux-241031-191829-1f4b14-pr6024.zip) | | :heavy_check_mark: | 1f4b14b6 | [#2](https://ci.status.im/job/status-go/job/prs/job/android/job/PR-6024/2/) | 2024-10-31 19:25:25 | ~6 min | `android` | [:package:`aar`](https://status-im-prs.ams3.cdn.digitaloceanspaces.com/status-go-android-241031-191911-1f4b14-pr6024.aar) | | :heavy_check_mark: | 1f4b14b6 | [#2](https://ci.status.im/job/status-go/job/prs/job/macos/job/x86_64/job/main/job/PR-6024/2/) | 2024-10-31 19:25:42 | ~6 min | `macos` | [:package:`zip`](https://status-im-prs.ams3.cdn.digitaloceanspaces.com/status-go-macos-241031-191927-1f4b14-pr6024.zip) | | :heavy_check_mark: | 1f4b14b6 | [#2](https://ci.status.im/job/status-go/job/prs/job/tests/job/PR-6024/2/) | 2024-10-31 20:22:30 | ~34 min | `tests` | [:page_facing_up:`log`](https://ci.status.im/job/status-go/job/prs/job/tests/job/PR-6024/2//consoleText) | | | | | | | | | | :heavy_check_mark: | f596a4da | [#3](https://ci.status.im/job/status-go/job/prs/job/windows/job/x86_64/job/main/job/PR-6024/3/) | 2024-11-21 12:53:36 | ~4 min | `windows` | [:package:`zip`](https://status-im-prs.ams3.cdn.digitaloceanspaces.com/status-go-windows-241121-124911-f596a4-pr6024.zip) | | :heavy_check_mark: | f596a4da | [#3](https://ci.status.im/job/status-go/job/prs/job/macos/job/aarch64/job/main/job/PR-6024/3/) | 2024-11-21 12:53:43 | ~4 min | `macos` | [:package:`zip`](https://status-im-prs.ams3.cdn.digitaloceanspaces.com/status-go-macos-241121-124905-f596a4-pr6024.zip) | | :heavy_check_mark: | f596a4da | [#3](https://ci.status.im/job/status-go/job/prs/job/ios/job/PR-6024/3/) | 2024-11-21 12:54:00 | ~4 min | `ios` | [:package:`zip`](https://status-im-prs.ams3.cdn.digitaloceanspaces.com/status-go-ios-241121-124903-f596a4-pr6024.zip) | | :heavy_check_mark: | f596a4da | [#3](https://ci.status.im/job/status-go/job/prs/job/android/job/PR-6024/3/) | 2024-11-21 12:55:25 | ~6 min | `android` | [:package:`aar`](https://status-im-prs.ams3.cdn.digitaloceanspaces.com/status-go-android-241121-124901-f596a4-pr6024.aar) | | :heavy_check_mark: | f596a4da | [#3](https://ci.status.im/job/status-go/job/prs/job/linux/job/x86_64/job/main/job/PR-6024/3/) | 2024-11-21 12:57:16 | ~8 min | `linux` | [:package:`zip`](https://status-im-prs.ams3.cdn.digitaloceanspaces.com/status-go-linux-241121-124904-f596a4-pr6024.zip) | | :heavy_check_mark: | f596a4da | [#3](https://ci.status.im/job/status-go/job/prs/job/tests-rpc/job/PR-6024/3/) | 2024-11-21 12:58:44 | ~9 min | `tests-rpc` | [:page_facing_up:`log`](https://ci.status.im/job/status-go/job/prs/job/tests-rpc/job/PR-6024/3//consoleText) | | :heavy_check_mark: | f596a4da | [#3](https://ci.status.im/job/status-go/job/prs/job/macos/job/x86_64/job/main/job/PR-6024/3/) | 2024-11-21 12:58:52 | ~9 min | `macos` | [:package:`zip`](https://status-im-prs.ams3.cdn.digitaloceanspaces.com/status-go-macos-241121-124907-f596a4-pr6024.zip) | | :heavy_check_mark: | f596a4da | [#3](https://ci.status.im/job/status-go/job/prs/job/tests/job/PR-6024/3/) | 2024-11-21 13:28:24 | ~39 min | `tests` | [:page_facing_up:`log`](https://ci.status.im/job/status-go/job/prs/job/tests/job/PR-6024/3//consoleText) |
:grey_question: Commit :hash: Finished (UTC) Duration Platform Result
:heavy_multiplication_x: 6135d64b #4 2024-11-21 15:49:34 ~4 min tests :page_facing_up:log
:heavy_check_mark: 6135d64b #4 2024-11-21 15:50:05 ~4 min linux :package:zip
:heavy_check_mark: 6135d64b #4 2024-11-21 15:50:31 ~5 min ios :package:zip
:heavy_check_mark: 6135d64b #4 2024-11-21 15:50:31 ~5 min macos :package:zip
:heavy_multiplication_x: 6135d64b #4 2024-11-21 15:50:34 ~5 min tests-rpc :page_facing_up:log
:heavy_check_mark: 6135d64b #4 2024-11-21 15:50:40 ~5 min windows :package:zip
:heavy_check_mark: 6135d64b #4 2024-11-21 15:50:48 ~5 min macos :package:zip
:heavy_check_mark: 6135d64b #4 2024-11-21 15:51:09 ~5 min android :package:aar
:heavy_check_mark: e5e053bd #5 2024-11-21 17:20:30 ~3 min windows :package:zip
:heavy_check_mark: e5e053bd #5 2024-11-21 17:20:37 ~3 min macos :package:zip
:heavy_check_mark: e5e053bd #5 2024-11-21 17:20:53 ~4 min tests-rpc :page_facing_up:log
:heavy_check_mark: e5e053bd #5 2024-11-21 17:21:09 ~4 min ios :package:zip
:heavy_check_mark: e5e053bd #5 2024-11-21 17:21:54 ~5 min macos :package:zip
:heavy_check_mark: e5e053bd #5 2024-11-21 17:22:24 ~5 min linux :package:zip
:heavy_check_mark: e5e053bd #5 2024-11-21 17:22:57 ~6 min android :package:aar
:heavy_check_mark: e5e053bd #5 2024-11-21 17:49:29 ~32 min tests :page_facing_up:log
codecov[bot] commented 3 weeks ago

Codecov Report

Attention: Patch coverage is 82.00000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 60.92%. Comparing base (11cf42b) to head (e5e053b). Report is 5 commits behind head on develop.

Files with missing lines Patch % Lines
logutils/core.go 82.00% 6 Missing and 3 partials :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #6024 +/- ## =========================================== + Coverage 60.91% 60.92% +0.01% =========================================== Files 819 820 +1 Lines 109466 109516 +50 =========================================== + Hits 66676 66719 +43 - Misses 34946 34961 +15 + Partials 7844 7836 -8 ``` | [Flag](https://app.codecov.io/gh/status-im/status-go/pull/6024/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im) | Coverage Δ | | |---|---|---| | [functional](https://app.codecov.io/gh/status-im/status-go/pull/6024/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im) | `13.52% <0.00%> (-0.03%)` | :arrow_down: | | [unit](https://app.codecov.io/gh/status-im/status-go/pull/6024/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im) | `60.14% <82.00%> (+0.01%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files with missing lines](https://app.codecov.io/gh/status-im/status-go/pull/6024?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im) | Coverage Δ | | |---|---|---| | [logutils/core.go](https://app.codecov.io/gh/status-im/status-go/pull/6024?src=pr&el=tree&filepath=logutils%2Fcore.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im#diff-bG9ndXRpbHMvY29yZS5nbw==) | `82.00% <82.00%> (ø)` | | ... and [25 files with indirect coverage changes](https://app.codecov.io/gh/status-im/status-go/pull/6024/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im)
osmaczko commented 3 weeks ago

Noice 👍 Is this not too harmful for performance?

Thanks! Overriding the log level, format, and writer isn’t a common operation—usually it's done only once per user account lifetime—so I wouldn’t worry about performance here. As for the writes, since I used atomics, performance should be solid (no locks on write from multiple goroutines). I’ll look into creating a benchmark.

osmaczko commented 3 weeks ago

no usage for the custom zap.Core yet?

There is a followup PR I am finalizing: https://github.com/status-im/status-go/pull/6025/

osmaczko commented 5 days ago

@igor-sirotin created a benchmark for zap.Core and custom core. Result looks fine, seems there is no performance penalty due to use of atomics.

$ go test -bench .
goos: linux
goarch: amd64
pkg: github.com/status-im/status-go/logutils
cpu: AMD Ryzen 7 4800HS with Radeon Graphics         
BenchmarkCustomCore-16           1061532              1118 ns/op
BenchmarkZapCore-16              1000000              1057 ns/op