Skip to content

feat: file and advanced logging configuration for tracing #1993

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shadowsocks69420
Copy link

@shadowsocks69420 shadowsocks69420 commented Jul 29, 2025

This is the second attempt of #1992, as requested in #1990 (comment)

Compare to the first attempt, this iteration enables more flexibility for logging configuration, supporting logging to stdout and multiple files simultaneously, which was a limitation in the previous version.

This new PR is intended as an alternative to the first iteration, feel free to close the other once decision is made.


I removed SS*Config structs as the amount of code duplication involved to deserialize the new LogWriterConfig enum is too much. And I don't really get the benefit of having them in the first place. I can see it makes sense for server configurations for backward compatibility reasons, but service configurations don't carry the same baggage and, in most cases, can be easily worked around by utilizing existing serde_derive features.

I've provided extra tests to ensure the change to the deserialization logic won't break existing configurations.

Copy link
Author

@shadowsocks69420 shadowsocks69420 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pointing out some changes that are worth discussing

Comment on lines -209 to 167
/// Default logger log level, [0, 3]
/// Default log level for all writers, [0, 3]
pub level: u32,
/// Default logger format configuration
/// Default format configuration for all writers
pub format: LogFormatConfig,
Copy link
Author

@shadowsocks69420 shadowsocks69420 Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My original plan was to remove these fields from the struct while keeping the configuration format backward-compatible. E.g.: create a stdout writer using these values if no writers are configured, but ignore them otherwise (because it should be configured on a per-writer basis).

However, having to support the command line option prevented me from doing so because I figured that the command line option has to be handled in a somewhat sensible way and not ignored. But it is hard to reason about when there can be multiple writers. E.g.: which writer should the command line option apply to?

I'd still like to remove them if possible, let me know if you have opinion on this,

pub format: LogFormatConfig,
/// Logging configuration file path
/// Log writers configuration
pub writers: Vec<LogWriterConfig>,
Copy link
Author

@shadowsocks69420 shadowsocks69420 Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the term writers as requested in your comment #1990 (comment)

However, please note that in tracing the term writer refers to the MakeWriter trait which only handles dispatching a formatted buffer to an io::Write. What each LogWriterConfig here corresponds to is a "subscriber" or "layer" in tracing-speak, or an "appender" in log4rs-speak.

@shadowsocks69420
Copy link
Author

@zonyitoo This is ready for review. Waiting for your feedback on this.

@zonyitoo
Copy link
Collaborator

zonyitoo commented Aug 7, 2025

I know. But I was quite busy these days.

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.

2 participants