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

chore(logs): Improve and standardize structured logging (1st Pass) #4949

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

ldiego08
Copy link

@ldiego08 ldiego08 commented Jul 5, 2024

Description

This PR leverages slog's features as much as possible to create log messages with plenty of context to help developers debug issues but also end users when running their node without development experience. It also seeks to help settle on a standard for structured logging across the codebase. As an initial effort, only messages on some files have been updated:

  • Stacks node main entrypoint (main.rs)
  • Nakamoto bootstrapper (boot_nakamoto.rs)
  • Sortition database (sortdb.rs)

Once a standard is defined, it can be propagated in subsequent passes.

⚠️ Log messages were rephrased best-effort. Feel free to make any suggestions to make them more helpful or accurate!

Changes

  • Rephrase log messages to use less developer-specific lingo.
  • Rephrase panic error messages to add as much context as possible as tags or data cannot be attached (different from calling error!).
  • Add tags to log messages to let users know what functionality is logging the message (not the source file).
  • Add context data to logs to help developers determine what caused issues.
  • Update logging interfaces to improve console output readability.
  • Add macros to serialize values to slog values easily.

image

💡 Adding tags to logs can be a bit boilerplatey. There's a more automated alternative in which new log macros are generated in the file context. However, this would require using temporarily something like log_info! instead of info! as the names would collide. Example usage:

use_logging!("sortition-db");

// .. rest of code
log_info!("An info message.");

Implementation example here.

Based on a discussion with @wileyj

References

Applicable issues

Checklist

  • Test coverage for new or modified code paths
  • Changelog is updated
  • Required documentation changes (e.g., docs/rpc/openapi.yaml and rpc-endpoints.md for v2 endpoints, event-dispatcher.md for new events)
  • New clarity functions have corresponding PR in clarity-benchmarking repo
  • New integration test(s) added to bitcoin-tests.yml

@saralab saralab requested a review from wileyj July 8, 2024 15:16
@ldiego08 ldiego08 changed the title Improve and standardize structured logging (1st Pass) chore(logs): Improve and standardize structured logging (1st Pass) Jul 12, 2024
@ldiego08 ldiego08 marked this pull request as ready for review July 12, 2024 17:08
@ldiego08 ldiego08 requested review from a team as code owners July 12, 2024 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant