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

[feat] Add set_enable_paris_formatting() ConfigBuilder method to control whether… #126

Merged
merged 4 commits into from May 31, 2023

Conversation

shimaowo
Copy link
Contributor

… a given logger uses or strips paris formatting. Only available with the paris feature, defaults to enabled for backwards compatibility. Fixes #98 and #112

This basically just defers the paris formatting until actual log time, rather than having it applied as part of the initial macro. This allows specifying different values per-logger (via their Config), which can then be passed to the new paris method.

paris_macros was removed as it is no longer used.

I chose to add a new flag, rather than use write_log_enable_colors, as the setter for that is already gated by the ansi_term feature, and presumably already has a use.

The extra 'return' is due to rust not understanding that a terminating statement is an implicit return if there is a later #[cfg] block.

I did not include a test as there are no paris tests currently.

Simple example:

use log::*;
use simplelog::*;
use std::fs::File;

fn main() {
    CombinedLogger::init(vec![
        TermLogger::new(
            LevelFilter::Info,
            Config::default(),
            TerminalMode::Mixed,
            ColorChoice::Auto),

        WriteLogger::new(
            LevelFilter::Debug,
            ConfigBuilder::new()
                .set_enable_paris_formatting(false)
                .build(),
            File::create("log.txt").unwrap()
        )
    ]).unwrap();

    info!("Here is some <blue>colored</> text.");
}

The TermLogger output will be colored as usual; the WriteLogger output will simply be the message "Here is some colored text." with no markup or formatting.

…ther a given logger uses or strips paris formatting. Only available with the paris feature, defaults to enabled for backwards compatibility. Fixes Drakulix#98 and Drakulix#112
where
W: Write + Sized,
{
writeln!(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

blame rustfmt for this one

@shimaowo
Copy link
Contributor Author

@Drakulix So the tests fail this way even in master, due to the discrepancy between how the log import is handled. I could try to address that here, but it's kind of orthogonal.

@shimaowo
Copy link
Contributor Author

Actually this is easier to fix with this changeset than it is in master, because paris no longer requires special handling.

This PR will go through one of these days!

Copy link
Owner

@Drakulix Drakulix left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for putting in the work.

@Drakulix Drakulix merged commit ee6aefa into Drakulix:master May 31, 2023
20 of 21 checks passed
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.

paris should respect "set_write_log_enable_colors"
2 participants