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

Root Logger isn't configured properly #10

Open
melrubino opened this issue Apr 15, 2022 · 0 comments
Open

Root Logger isn't configured properly #10

melrubino opened this issue Apr 15, 2022 · 0 comments

Comments

@melrubino
Copy link

"root": {

I assumed with this configuration that we were indeed configuring and using the true root logger. However, this is giving a logger named "root", but not the true root logger I believe. When I use this configuration logged statements from other imported libraries aren't propagated up to this logger. So the problem I encountered was not being able to handle correctly logging statements from other imported libraries.

Instead, I followed the instructions here, for Dictionary Schema Details.

The configuration below configures the root logger and assigns it to logger:

logging_config = {
    "version": 1,
    "disable_existing_loggers": False,
    "formatters": {
        "minimal": {"format": "%(message)s"},
        "detailed": {
            "format": "%(levelname)s %(asctime)s [%(name)s:%(filename)s:%(funcName)s:%(lineno)d]\n%(message)s\n"
        },
    },
    "handlers": {
        "console": {
            "class": "logging.StreamHandler",
            "stream": sys.stdout,
            "formatter": "minimal",
            "level": logging.DEBUG,
        },
        "info": {
            "class": "logging.handlers.RotatingFileHandler",
            "filename": Path(LOGS_DIR, "info.log"),
            "maxBytes": 10485760,  # 1 MB
            "backupCount": 10,
            "formatter": "detailed",
            "level": logging.INFO,
        },
        "error": {
            "class": "logging.handlers.RotatingFileHandler",
            "filename": Path(LOGS_DIR, "error.log"),
            "maxBytes": 10485760,  # 1 MB
            "backupCount": 10,
            "formatter": "detailed",
            "level": logging.ERROR,
        },
    },
    "root": {"handlers": ["console", "info", "error"], "level": logging.INFO, "propagate": True},
}
logging.config.dictConfig(logging_config)

# Obtains the root logger; all child logging will propagate up to root logger
logger = logging.getLogger()
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

1 participant