Log have no color in docker logs
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.
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)
For people using docker compose that don't want to modify the code, it's also possible to add an env var:
environment:
LOGURU_COLORIZE: YES
For people using docker compose that don't want to modify the code, it's also possible to add an env var:
environment: LOGURU_COLORIZE: YES
Using environment variable is a good solution. The downside of LOGURU_COLORIZE is that it'll also change the default behavior for handlers that generally do not support colors, such as a file sink for example. The next version of Loguru will support the FORCE_COLOR environment variable, which affects only terminal output, and should be preferred.