Skip to content

Conversation

shadowsocks69420
Copy link
Contributor

Summary

Enable file logging with tracing via tracing-appender and introduce new log.file.* configuration options.

As log4rs is scheduled for removal, this PR serves as an intermediate step toward that transition. I’ve also removed user-facing documentation pertaining to log4rs to reduce the impact of potential future breaking changes.

Known Limitations

Console output will be suppressed if file logging is configured.

Significant additional work is required to support both.

Does not support rotation based on file size.

This is an inherent limitation of the tracing-appender library.

Plugin output will not be written to file

This is an existing issue that applies to log4rs as well.

Copy link
Contributor 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 may worth discussing.

if let Some(ref file_config) = config.file {
let file_writer = make_file_writer(bin_name, file_config)
// don't have the room for a more graceful error handling here
.expect("Failed to create file writer for logging");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please advice if you think there is a better way to handle this.

Comment on lines -300 to +302
logging::init_with_config("sslocal", &service_config.log);
logging::init_with_config("ssmanager", &service_config.log);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this was a copy-paste error, same for the other one.

src/config.rs Outdated
Comment on lines 164 to 166
if let Some(max_files) = file_config.max_files {
nfile.max_files = Some(max_files);
}
Copy link
Contributor Author

@shadowsocks69420 shadowsocks69420 Jul 25, 2025

Choose a reason for hiding this comment

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

There is a small caveat FWIW: if the user sets max_files to 0, it will cause panicking in debug builds due to integer underflow in the tracing-appender crate1.
However, in release build, this doesn't cause any noticeable issue as the check will be omitted and it behaves just like u64::MAX. Furthermore, I strongly believe the tracing-appender crate shouldn't accept 0 in there public API in the first place. Therefore, zero is not rejected as an invalid value here.

Footnotes

  1. https://github.com/tokio-rs/tracing/blob/e63ef57f3d686abe3727ddd586eb9af73d6715b7/tracing-appender/src/rolling.rs#L695

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes indeed. max_files should always be >= 1.

src/config.rs Outdated
Comment on lines 145 to 148
if let Some(file_config) = log.file
// directory must be configured for file logging
&& let Some(directory) = file_config.directory
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This requires rustc 1.88.0. Let me know if I should bump the MSRV or nest this block one level deeper.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You should keep the MSRV. Bumping MSRV should be a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback, I've updated the changes accordingly.

@shadowsocks69420
Copy link
Contributor Author

The test failure seems dubious, could you try run it again?
The MSRV compilation error is caused by #1992 (comment)

@shadowsocks69420
Copy link
Contributor Author

Closing this as the alternative approach #1993 has been merged.

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