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.level does not work! #1190

Open
EchoShoot opened this issue Aug 13, 2024 · 2 comments
Open

logger.level does not work! #1190

EchoShoot opened this issue Aug 13, 2024 · 2 comments
Labels
question Further information is requested

Comments

@EchoShoot
Copy link

Python 3.11.8, my code is

from loguru import logger

logger.level('INFO')

if __name__ == '__main__':
    logger.debug('debug')
    logger.info('info')
    logger.success('success')
    logger.warning('warning')
    logger.error('error')
    logger.critical('critical')
    logger.exception('exception')

the print is

2024-08-13 10:23:43.683 | DEBUG    | __main__:<module>:6 - debug
2024-08-13 10:23:43.683 | INFO     | __main__:<module>:7 - info
2024-08-13 10:23:43.683 | SUCCESS  | __main__:<module>:8 - success
2024-08-13 10:23:43.683 | WARNING  | __main__:<module>:9 - warning
2024-08-13 10:23:43.683 | ERROR    | __main__:<module>:10 - error
2024-08-13 10:23:43.683 | CRITICAL | __main__:<module>:11 - critical
2024-08-13 10:23:43.683 | ERROR    | __main__:<module>:12 - exception
NoneType: None

Why does DEBUG and INFO display?

@destin-v
Copy link

You need to replace the default sink.

logger.remove()
logger.add(sink=sys.stdout, level="DEBUG")

@Delgan Delgan added the question Further information is requested label Oct 5, 2024
@Delgan
Copy link
Owner

Delgan commented Oct 5, 2024

The level() method is only used to retrieve, modify or add a log level usable by the logger.log().

As indicated by @destin-v, if you want to change the default handler, simply replace it by a new one with the threshold level you desire.

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

3 participants