-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
log: structured logging #9083
base: master
Are you sure you want to change the base?
log: structured logging #9083
Conversation
Important Review skippedAuto reviews are limited to specific labels. Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
61e241c
to
9ca6dac
Compare
3bdef45
to
4a09edb
Compare
f259e66
to
9587f54
Compare
Update the `btclog` dependency to take advantage of the new expanded Logger interface that supports structured logging. Then also update the PrefixedLogger so that it implements the new expanded btclog.Logger interface.
Ensure that the ShutdownLogger correctly calls shutdown for the new CriticalS method added to the btclog.Logger.
To make the upcoming commits easier to review and for general code organisation.
These are two separate concerns. So this commit splits them up and just passes a LogWriter from the one to the other. This will become cleaner in an upcoming commit where the Rotator will implement io.Writer and there will no longer be a need for LogWriter.
This commit adds a Handler interface which extends the btclog.Handler interface which is needed for initialising an slog logger. This commit then also adds an implementation of this interface called `handlerSets` which basically lets us have a Handler backed by many Handlers (we need one for the stdout and one for our log file).
This commit adds one that can be used for log files (in the format that our logs are currently written) along with a colourful one that is nice for terminal.
Start using the new slog handlers. With this commit we also remove the need for the LogWriter since we let our LogRotator implement io.Writer and pass that in to our log file handler.
This commit adds config options so that users can for both the console logger and the file logger set the following things: - disable the logger - omit timestamps from log lines. - set the color profile used by the logger.
Update LND logger(s) to make use of structured logging (the
Logger
interface now has structured logging messages (DebugS
,InfoS
etc))See btclog update here: btcsuite/btclog#17
Details
slog.Handlers
(which underneath could be a json formatter, a logfmt formatter or any anything else like a charm HandlerUsage
The idea is that the
msg
passed to anS
method should be a constant. Theattr...
params are then used for key-value pairs.Each new method also takes a
context.Context
. TheWithCtx
helper can be used to attach any key-value pairs to acontext and then when the logger is called, the pairs will be extracted from the context and added as attributes in the log.
For example:
Other additions:
Config options
This also introduces a new
--logging.console.disable
option to disable logs being writtento stdout and a new
--logging.file.disable
option to disable writing logs to the standard log file.It also has
--logging.console.no-timestamps
&--logging.file.no-timestamps
to omit timestamps from the logsfinally, there is a new
--logging.console.color
option which can be set to:off
to disable color formatting,auto
to use the OS supported color format orforce
to force it to try use color formatting. This option is set toauto
by default. (Question: should we maybe set it to off by default & then let devs explicitly enable it rather?)TODO:
Fixes #8713
Fixes #6828
Fixes #6163