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

Apply level dependent color formatting to other fields #87

Open
bwuerkner opened this issue Mar 25, 2020 · 2 comments
Open

Apply level dependent color formatting to other fields #87

bwuerkner opened this issue Mar 25, 2020 · 2 comments

Comments

@bwuerkner
Copy link

Hello,

I just stumbled upon your package and really like it. Especially the extensive documentation.
While reading said documentation I also realized though that something I'd like to do isn't possible using coloredlogs.
I would like to format the color of the levelname according to my style definition for the level and not the message.
Example:
[ERROR] some error with ERROR in red and "some error" in the default color
[WARNING] some warning with WARNING in yellow and "some warning" in the default color

Do you think this would be a possibility to be added?
Cheers,
Ben

@barabanus
Copy link

barabanus commented Mar 31, 2020

That's exactly what I need. For example, let me show how I tried to use the library:

coloredlogs.install(
    logger=logger,
    level=logging.DEBUG,
    fmt="%(asctime)s.%(msecs)03d [%(levelname)s] %(message)s",
    level_styles=dict(
        debug={"color": "yellow"},
        info={"color": "white"},
        warning={"color": "red"},
        error={"color": "red"},
    ),
    field_styles=dict(
        asctime={"color": "blue"},
        message={"color": "white"},
    ),
)

Here I emphasized that I want message to be white. And also I omitted levelname color within field styles. That means I expect the message to be always white and levelname to be dependent on the current level.

Could you please support this functionality?

@curiousengineer
Copy link

I am also confused log level colour is applied that the message text only on the terminal and not the other fields. What I am looking for is that the whole line printed onto the terminal is of the same colour dependant on the log level of the message. This includes the message log level and the message text. How can this be done?

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

No branches or pull requests

3 participants