-
Notifications
You must be signed in to change notification settings - Fork 1
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
Implement loggers #47
Comments
For logging, I highly recommend I have this function, usually in a import os
import sys
import loguru
def get_logger(verbose: bool = False) -> Logger:
"""Get a logger."""
logger = loguru.logger
logger.configure(
handlers=[
{
"sink": sys.stdout,
"colorize": True,
"format": " | ".join(
[
"<cyan>{time:YYYY/MM/DD HH:mm:ss}</>",
"{message}",
]
),
}
]
)
if os.getenv("PACKAGE_NAME_VERBOSE", str(verbose)).lower() == "true":
logger.enable("package_name")
else:
logger.disable("package_name")
return logger This way, I can easily control the verbosity of the package with an env variable ( logger = get_logger()
logger.info("This is a log") By default, the logger is disabled and needs to be enabled explicitly using the env variable like so: os.environ["PACKAGE_NAME_VERBOSE"] = "true" It's a simple and clean solution and doesn't interfere with the logging level of other packages. |
I would personally use just the standard logger that comes with Python. I've never had the need of another, third party tool, very often just syntactic sugar for the standard logger. It has its drawbacks, of course, but still it is really powerful and, to be honest, it is WIDELY use, so learning to use it properly will help you understand other tools. Here you have an interesting video on pros, cons and how to use it right: https://www.youtube.com/watch?v=9L77QExPmI0 |
Maybe open an issue about it, if not already there.
Originally posted by @dalonsoa in #31 (comment)
The text was updated successfully, but these errors were encountered: