0

I have file "a.py" with logging configuration written. Another file "b.py" where I just import logging and write log, it creates empty file but fails to write something onto it. Here are the code from two files. Please tell me where am I missing something. Thanks

"a.py"

import logging.config
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'default': {
            'format': '%(asctime)s %(pathname)s:%(lineno)d %(message)s',
        },
    },
    'handlers': {
        'default': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': 'rror.log',
            'backupCount': 2,
            'formatter': 'default',
        },
        'information': {
            'level': 'INFO',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': 'information.log',
            'backupCount': 2,
            'formatter': 'default',
        },
    },
    'loggers': {
        'logger1': {
            'handlers': ['default'],
            'level': 'DEBUG',
            'propagate': False,
        },
        'logger2': {
            'handlers': ['information'],
            'level': 'INFO',
            'propagate': False,
        },
    },
}

logging.config.dictConfig(LOGGING)

"b.py"

import logging

logging.getLogger('logger1').info("hey there!")
logging.getLogger('logger2').debug("hey logger2")

1 Answer 1

1

change "b.py" to this:

from a import logging

logging.getLogger('logger1').debug("hey there!")
logging.getLogger('logger2').info("hey logger2")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.