I have a simple logging definition in the settings.py file:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'simple': {
'format': '[%(asctime)s] %(levelname)s %(message)s',
},
'verbose': {
'format': '[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s',
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatters': 'simple',
'propagate': False
}
},
'loggers': {
'myapp': {
'handlers': ['console'],
'level': 'DEBUG'
},
}
}
When I run my program, I get the error:
ValueError: Unable to configure handler 'console'
What is going wrong?
propagate is not an option for handlers but for loggers. So your configuration should be.
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple',
}
},
'loggers': {
'myapp': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': False
},
}
I changed and tested your LOGGING dictionary bit by bit, the following version works
{
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'simple': {
'format': '[%(asctime)s] %(levelname)s %(message)s',
},
'verbose': {
'format': '[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s',
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple',
}
},
'loggers': {
'': {
'handlers': ['console'],
'level': 'DEBUG',
"propagate": True
},
}
}
There are three differences between LOGGING and the above dictionary:
LOGGING, there is a key value pair 'propagate': False in LOGGING.handlers.console. It was removed in the above dictionaryLOGGING.loggers, the unique key is 'myapp'. In the above dictionary, the 'myapp' is replaced by an empty string ''LOGGING.loggers, there is a key value pair "propagate": False in the unique sub dictionary. It was replaced by "propagate": True.Hope it helps.
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