Seems that Django loggers default to use stderr for all logging levels.
for example when logging setup is:
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'default': {
'format': "%(asctime)s:%(name)s:%(levelname)s:%(message)s"
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'default',
}
},
'loggers': {
'': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': True,
},
'django': {
'handlers': ['console'],
'level': 'WARNING',
'propagate': False,
},
'appname': {
'handlers': ['console'],
'level': 'WARNING',
'propagate': False,
},
When I change handlers to:
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'default',
'stream': sys.stdout #Notice the change
}
},
Then all output is in stdout.
But I need the correct behavior: logging info,debug, warning to stdout
(warning can go either way, don't really care) and exception, error, critical to stderr
What am I missing here? (some obvious setting? everybody knows about?) Thanks for the help!
As mentioned in #6099: all log messages should go to stderr instead of stdout. command API related output should use a dedicated interface that outputs to stdout.
Logger defaults to printing to stderr instead of stdout.
Python Logging Best Practices If you want to catch error messages from libraries you use, make sure to configure the root logger to write to a file, for example, to make the debugging easier. By default, the root logger only outputs to stderr , so the log can get lost easily.
There is a parameter for you CustomLog sets log filename and format. If you configure /proc/self/fd/1 as the log filename, Apache2 process will now write to its own stdout.
Try defining 2 handlers, e.g consoleout
and consoleerr
each using the correct stream.
Use the correct handler for each entry in the loggers
section.
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