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

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

Open
zhangchunsheng opened this issue Oct 21, 2024 · 2 comments
Open

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

zhangchunsheng opened this issue Oct 21, 2024 · 2 comments
Labels
question Further information is requested

Comments

@zhangchunsheng
Copy link

zhangchunsheng commented Oct 21, 2024

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

@Delgan
Copy link
Owner

Delgan commented Oct 23, 2024

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.

@Delgan Delgan added the question Further information is requested label Oct 23, 2024
@sanmai-NL
Copy link

@zhangchunsheng Can this be closed?

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