Delgan / loguru

Python logging made (stupidly) simple
MIT License
19.62k stars 695 forks source link

Programmatic interface to color changes #1159

Closed kfsone closed 3 months ago

kfsone commented 3 months ago

In theory:

import os
os.environ["LOGURU_DEBUG_COLOR"] = os.environ.get("LOGURU_DEBUG_COLOR", "<dim>")
from loguru import logger

works, up until someone else imports loguru first.

Is there an extant mechanism to that lets me cause a logger to rebuild its color table? Or if I'm desperate to control it, do I just play whackamole with logger._core.levels[x].color?

Delgan commented 3 months ago

Could you update the color using logger.level()?

logger.level("DEBUG", color="<dim>")
kfsone commented 3 months ago

YES! Might be worth calling this out in the section on color customization, somehow my read thru of the documentation actually lead me away from that.