Delgan / loguru

Python logging made (stupidly) simple
MIT License
20.1k stars 704 forks source link

logger.add colorize is not working #1249

Open yechielb2000 opened 2 hours ago

yechielb2000 commented 2 hours ago
import sys
from loguru import logger

logger.remove(0)
logger.add(sys.stdout, colorize=True, format='{message}')
logger.info('this is a message')

Doesn't actually print with colors (specificly when also using foarmt flag)

Delgan commented 2 hours ago

Hi.

This is because the format must also include color markups like "<green></green>" or "<red></red>" for example. See documentation here: The color markups. Also, you may take a look at this: Why are my logs not colored?.

The following code should work:

import sys
from loguru import logger

logger.remove(0)
logger.add(sys.stdout, colorize=True, format='<green>{time}</> <level>{message}</>')
logger.info('this is a message')