-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: replace logger #108
Draft
dmke
wants to merge
7
commits into
master
Choose a base branch
from
refactor/slog
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #108 +/- ##
=========================================
Coverage ? 69.80%
=========================================
Files ? 38
Lines ? 1984
Branches ? 0
=========================================
Hits ? 1385
Misses ? 534
Partials ? 65 ☔ View full report in Codecov by Sentry. |
dmke
force-pushed
the
refactor/slog
branch
3 times, most recently
from
January 28, 2024 22:43
6d2020a
to
150f5a4
Compare
dmke
force-pushed
the
refactor/slog
branch
5 times, most recently
from
October 30, 2024 20:45
9d525cc
to
9d10789
Compare
This replaces the zap logging engine with Go 1.21's structured logger, log/slog, or more precisely a thin wrapper around that ("xlog"). The log/slog package has a few things missing, which are present in xlog: 1. xlog provides a no-op logger, which simply discards any log output. This is extensively used in our tests. 2. xlog has a Fatal() output method, which simply calls Error() and then os.Exit(1). 3. xlog treats error values as first-class citizen. Since (log/slog).Error() is a convenience function for their default logger instance, there is no built-in way to treat errors as values. In comparison, (xlog).Error() constructs an slog.Attr, since xlog does not provide a default logger. Point (2) is debatable, since xlog.Fatal is only used in cmd/texd/main.go, so I'd be willing to forfeit it. Some TODOs remain: - xlog, i.e. its extension over log/slog, is not really tested - documentation is missing - the current xlog constructor (New) is a bit clunky to use, maybe switch to functional options? - some tests create a local buffer as log output target - this could be made easier with a `log, buf := xlog.NewBuffered()` constructor (albeit, the overhead is minimal) - for local development, I still like to have some colorization Issue: #1
Y'know, for performance. Logging is intense
I'm waiting on upstream to merge two merge requests. Merge-Request: https://gitlab.com/greyxor/slogor/-/merge_requests/7 Merge-Request: https://gitlab.com/greyxor/slogor/-/merge_requests/8
dmke
force-pushed
the
refactor/slog
branch
2 times, most recently
from
October 31, 2024 17:04
e233bba
to
7ef0add
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This replaces the zap logging engine with Go 1.21's new structured logger,
log/slog
, or more precisely a thin wrapper around that (xlog
).The log/slog package has a few things missing, which are present in
xlog
:xlog
provides a no-op logger, which simply discards any log output. This is extensively used in our tests.xlog
has aFatal()
output method, which simply callsError()
and thenos.Exit(1)
.xlog
does not provide global convenience functions to access a default logger instance; all calls must go through aLogger
instance created withNew()
.xlog
treats error values as first-class citizen. Since(log/slog).Error()
is a convenience function for their default logger instance, there is no built-in way to treat errors as values. In comparison,(xlog).Error(err)
constructs anslog.Attr
.Point (2) is debatable, since
xlog.Fatal
is only used incmd/texd/main.go
, so I'd be willing to forfeit it.Some TODOs remain:
xlog
, i.e. its extension over log/slog, is not really testedxlog.New()
Issue: #1