python-coloredlogs
python-coloredlogs copied to clipboard
Apply level dependent color formatting to other fields
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
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?
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?