Delgan / loguru

Python logging made (stupidly) simple
MIT License
19.96k stars 699 forks source link

logger.level does not work! #1190

Open EchoShoot opened 3 months ago

EchoShoot commented 3 months ago

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 commented 3 months ago

You need to replace the default sink.

logger.remove()
logger.add(sink=sys.stdout, level="DEBUG")
Delgan commented 1 month ago

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.