Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logger.add colorize is not working #1249

Open
yechielb2000 opened this issue Dec 2, 2024 · 1 comment
Open

logger.add colorize is not working #1249

yechielb2000 opened this issue Dec 2, 2024 · 1 comment
Labels
question Further information is requested

Comments

@yechielb2000
Copy link
Contributor

yechielb2000 commented Dec 2, 2024

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
Copy link
Owner

Delgan commented Dec 2, 2024

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')

@Delgan Delgan added the question Further information is requested label Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants