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

How to have different logging levels for different modules? #1301

Open
johann-petrak opened this issue Feb 17, 2025 · 1 comment
Open

How to have different logging levels for different modules? #1301

johann-petrak opened this issue Feb 17, 2025 · 1 comment

Comments

@johann-petrak
Copy link

A program may use different API functions from various of its own modules plus other library modules which also use loguru for logging.

What is the standard way to have different logging levels or sinks in place depending on which module or library is doing the logging?
For example I might want all modules from package pack1 to use INFO, might want all my own modules use WARNING except module1 which should use DEBUG.
Is there a mechanism or method available to configure this?

@Delgan
Copy link
Owner

Delgan commented Feb 17, 2025

You could use a dict as the filter argument of your sink. This is discussed in this paragraph of the documentation: The logged message.

For example:

level_filtering = {
    "": "WARNING",
    "pack1": "INFO",
    "module1": "DEBUG",
}

logger.add(sys.stderr, filter=level_filtering, level="DEBUG")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants