Skip to content
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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

ellemouton
Copy link
Collaborator

@ellemouton ellemouton commented Sep 10, 2024

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

  • This new implementation is flexible enough to allow callers to pass in their own slog.Handlers (which underneath could be a json formatter, a logfmt formatter or any anything else like a charm Handler

Usage

The idea is that the msg passed to an S method should be a constant. The attr... params are then used for key-value pairs.

log.InfoS(ctx, "User performed a request",
			"user_id", id,
			"request_uri: ", uri)

Each new method also takes a context.Context. The WithCtx helper can be used to attach any key-value pairs to a
context and then when the logger is called, the pairs will be extracted from the context and added as attributes in the log.

For example:

ctx := WithCtx(context.Background(), "user_id", id)

// This log will include both the `user_id` and `request_uri` attributes.
log.InfoS(ctx, "User performed a request", "request_uri", uri)

Other additions:

Config options

  • This also introduces a new --logging.console.disable option to disable logs being written
    to 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 logs

  • finally, 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 or force to force it to try use color formatting. This option is set to auto by default. (Question: should we maybe set it to off by default & then let devs explicitly enable it rather?)

TODO:

  • update docs with guidelines for using structured logging methods

Fixes #8713
Fixes #6828
Fixes #6163

Copy link
Contributor

coderabbitai bot commented Sep 10, 2024

Important

Review skipped

Auto reviews are limited to specific labels.

Labels to auto review (1)
  • llm-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ellemouton ellemouton changed the title https://github.com/btcsuite/btclog/pull/17 log: structured logging Sep 10, 2024
@guggero guggero self-requested a review September 10, 2024 18:38
@ellemouton ellemouton added the logging Related to the logging / debug output functionality label Sep 10, 2024
@ellemouton ellemouton self-assigned this Sep 11, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logging Related to the logging / debug output functionality
Projects
Status: In Progress
2 participants