Delgan / loguru

Python logging made (stupidly) simple
MIT License
20.01k stars 702 forks source link

Can't change sys.stdout level in different file. #505 #1223

Open zhangchunsheng opened 1 month ago

zhangchunsheng commented 1 month ago

Can't change sys.stdout level in different file. #505, How to create new object logger.

Delgan commented 1 month ago

Could you please explain your problem further?

Keep in mind that each of your file share the same logger. They all write messages to the same set of handlers you configured.

Therefore, if you want to use different levels for different file, you can use a filter like so:

levels = {
    "": "DEBUG",  # Default
    "module_a": "INFO",
    "module_b": "WARNING",
}

logger.remove()  # Remove default handler.
logger.add(sys.stderr, filter=levels)

If you need to create truly independent loggers, take a look a this page of the documentation: Creating independent loggers with separate set of handlers.

sanmai-NL commented 2 weeks ago

@zhangchunsheng Can this be closed?