Skip to content

No color on Windows when using builder #225

@roman-khazanskii

Description

@roman-khazanskii

If I just do env_logger::init(); then I see colored log messages, as expected, with different color for every log leve.

However, if I use builder - everything is colorless, even though I call .write_style(WriteStyle::Always):

    env_logger::builder()
        .format(|buf, record| {
            writeln!(
                buf,
                "{} [{}] - {}",
                Local::now().format("%Y-%m-%d %H:%M:%S"),
                record.level(),
                record.args()
            )
        })
        .write_style(WriteStyle::Always)
        .filter(Some(botname), LevelFilter::Info)
        .init();

However, if I manually color all the text, like this:

    env_logger::builder()
        .format(|buf, record| {

            let mut style = buf.style();

            style.set_color(Color::Red);

            writeln!(
                buf,
                "{} [{}] - {}",
                Local::now().format("%Y-%m-%d %H:%M:%S"),
                record.level(),
                style.value(record.args())
            )
        })
        .filter(Some(botname), LevelFilter::Info)
        .write_style(WriteStyle::Always)
        .init();

red text is printed. Does it mean that if I want to use builder, I have to manually color all different levels?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions