Delgan / loguru

Python logging made (stupidly) simple
MIT License
18.69k stars 682 forks source link

RecordLevel lack of property “color” #1120

Closed main1015 closed 2 months ago

main1015 commented 3 months ago

There are color properties when defining what Level is, but RecordLevel lacks the color property when you format the output logs. In the documentation There is no color in the “level: The severity used to log the message name (default)”, no, icon. But with the default log output

Delgan commented 3 months ago

This is because color has been deemed quite pointless within RecordLevel, since it cannot be formatted. Colors should be specified using markup tags like <blue>...</blue> and <level>...</level>. This allows for defining a scheme using various colors, not just the one of current level, which encompasses the common format of your logs. The record fields can be formatted with {level.name} and {level.icon}, but this would not map very naturally if applied to colors.

What exactly is your use case for accessing level color from a record?

main1015 commented 2 months ago

This is my code: 1712472647152 Below is the output: 1712472667508 However, I deleted the own output of loguru and defined the output format by myself, so there is no way to set the output color: 1712472893143

Delgan commented 2 months ago

Can you use the special "<level>...</level>" color markup in your custom format?

main1015 commented 2 months ago

@Delgan
Thank you very much, I want this effect, I haven't read the document carefully before, sorry

Delgan commented 2 months ago

No problem, I'm closing this ticket then, since it's resolved. :+1: