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

using a custom logger results in cli_colors having no effect #1712

Closed
tkenda opened this issue Jun 18, 2021 · 3 comments
Closed

using a custom logger results in cli_colors having no effect #1712

tkenda opened this issue Jun 18, 2021 · 3 comments
Labels
feedback wanted User feedback is needed

Comments

@tkenda
Copy link

tkenda commented Jun 18, 2021

Hi,

I use Rocket configuration programatically:

let figment = rocket::figment::Figment::from(rocket::Config::release_default())
    .merge(("port", file_config.web.port as u16))
    .merge(("address", address))
    .merge(("cli_colors", false));

// Rocket
match rocket::custom(figment)
    .mount("/", api::primitives::routes())
    .mount("/api/v1", api::v1::routes())
    .register("/", api::primitives::catchers())
    .manage(shared_config)
    .launch()
    .await
{
    Ok(_) => {
        info!("Finalizing Rocket!");
        Ok(())
    }
    Err(err) => {
        error!("Rocket error: {}", err);
        Err(format!("Rocket error: {}", err))
    }
}

Cargo.toml:
rocket = { version = "0.5.0-rc.1", features = ["tls", "json"] }

OS:
Linux 5.8.0-55-generic #62~20.04.1-Ubuntu

Rustup:
stable-x86_64-unknown-linux-gnu (default)
rustc 1.51.0 (2fd73fabe 2021-03-23)

The log show me that the CLI_COLORS is set correctly.

image

@jebrosen jebrosen added the bug Deviation from the specification or expected behavior label Jun 18, 2021
@jebrosen jebrosen changed the title CLI COLORS not working rocket::custom() does not respect cli_colors configuration Jun 18, 2021
@SergioBenitez SergioBenitez added triage A bug report being investigated feedback wanted User feedback is needed and removed bug Deviation from the specification or expected behavior triage A bug report being investigated labels Jun 19, 2021
@SergioBenitez
Copy link
Member

You are using a custom logger which means that Rocket doesn't touch logging. If you remove your logger, you'll see colors go away. The default is with coloring enabled. So, this is working as expected:

https://github.com/SergioBenitez/Rocket/blob/abf996b026b601abb193d2f2081887b1de5e6ced/core/lib/src/log.rs#L144-L154

It's tricky. On the one hand, if we're not using Rocket's logger, it seems we should disable coloring. Or if the cli_colors property is unset. But this may have a negative impact on other applications which use yansi for coloring.

I'm inclined to suggest that, barring the massive revamp of logging in #21, we probably should disable coloring even if Rocket's logger is being used if cli_colors is false.

@SergioBenitez SergioBenitez changed the title rocket::custom() does not respect cli_colors configuration using a custom logger results in cli_colors having no effect Jun 19, 2021
@SergioBenitez
Copy link
Member

I have implemented an approach that resolves this issue. I need to polish a few more changes before merging this one but will do so soon.

@tkenda
Copy link
Author

tkenda commented Jun 19, 2021

Correctly, I am using log4rs.

log4rs = { version = "1.0.0", features = ["gzip"] }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feedback wanted User feedback is needed
Projects
None yet
Development

No branches or pull requests

3 participants