Delgan / loguru

Python logging made (stupidly) simple
MIT License
19.43k stars 690 forks source link

Log have no color in docker logs #1173

Open dogky123 opened 2 months ago

dogky123 commented 2 months ago

image

from loguru import logger
logger.info(...)
logger.warning(...)

the script work in container but there is no color. All config is default.

thank you for your works.

Delgan commented 1 month ago

By default, Loguru will try to automatically detect if the sink supports colors (e.g. console terminal as opposed to file sink) by calling the isatty() method.

The sys.stderr in your Docker container is likely redirected and not a tty, causing the colors to be disabled.

You can force them anyway by replacing the default sink with logger.add() and specifying colorize=True:

logger.remove()
logger.add(sys.stderr, colorize=True)