-
Notifications
You must be signed in to change notification settings - Fork 3
hook: introduce mechanism for hooking into raw logger output #55
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
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #55 +/- ##
==========================================
+ Coverage 59.83% 60.16% +0.32%
==========================================
Files 15 16 +1
Lines 600 615 +15
==========================================
+ Hits 359 370 +11
- Misses 220 222 +2
- Partials 21 23 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
sashaostrikov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! ![]()
hook/writer.go
Outdated
|
|
||
| // Writer hooks receiver to rendered log output at level in the requested format, | ||
| // typically one of 'json' or 'console'. | ||
| func Writer(logger log.Logger, receiver io.Writer, level log.Level, format string) log.Logger { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can create a type and consts for format and use it instead of string.
However, I can see that you had a type and changed it to string :) But I think having our own type (aliasing string) shouldn't cause any problems?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type was internal - let me try and move it around :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a bit of shuffling but here we go: 4373c5e
Co-authored-by: Alex Ostrikov <alexander.ostrikov.jr@gmail.com>
Includes: - sourcegraph/log#56 - sourcegraph/log#55 - https://github.com/sourcegraph/run/releases/tag/v0.10.0 - https://github.com/sourcegraph/run/releases/tag/v0.11.0 - https://github.com/sourcegraph/run/releases/tag/v0.12.0 Also updates deprecated usages (seems we have a linter requiring this now)
A use case for this came up before (https://github.com/sourcegraph/sourcegraph/pull/45229), and @thenamankumar inquired about similar capabilities today for tracking log entries into a database. I think this may be a valid use case to support and simple enough to provide:
This makes it easy for consumers to record log output in a format consistent with what gets rendered by the library.
For convenience, log output format is now exported via
log/output.Format.I also think it makes sense for this to exist separately from
logtest.CaptureLog-logtestexports log entries in a structured manner for assertions, but we don't really want production code to be treating log entries as structured data (we could, but that might be a larger debate) - this serves simply to tee output elsewhere for recordkeeping.