I successfully set up Django logging, but I find myself in need to log some information inside settings.py. Is that possible?
Currently, the settings only come into effect after the entire file is parsed, which I believe is expected. Is there a way to force the set up of loggers right after specifying them? Otherwise, are there any alternatives that people recommend?
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'console': {
'format': '%(levelname)s: %(message)s'
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'console'
}
},
'loggers': {
'main': {
'handlers': ['console'],
'level': 'INFO',
'propagate': False,
},
},
}
# The below does not work because the setup declared above is not yet in effect
logger = logging.getLogger('main')
logger.info("Works?")
Answering my own question, but will accept other answers that might be more complete
Adding the following, will load the LOGGING as required. Not sure what are the side effects.
import logging.config
logging.config.dictConfig(LOGGING)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With