Question

I have a Flask application running on Apache using mod WSGI. I am trying to log a simple messages from the application using its logger:

app.logger.name="users server"
app.logger.setLevel(logging.DEBUG)
app.logger.debug("my log message")

The result in the Apache log is:

[Thu Feb 20 12:54:42.853231 2014] [:error] [pid 19461:tid 140399641954048] DEBUG:users server:my log message

Somewhere along the path from Flask via WSGI to Apache, the log metadata is lost. Apache shows [:error] instead of DEBUG and the name is [pid 19461:tid 140399641954048] instead of users server. The log data appears as unparsed text at the end of the log line.

How do I set WSGI, Apache and Flask to parse the logs coming out of the Flask application?

Was it helpful?

Solution

There is no mapping of logging module log levels to Apache levels as it would cause various subtle problems which would leave you scratching your head as to why you are not getting log messages from Python because of the Apache log level overriding things and suppressing output.

What you are currently getting is because the logging module is simply logging to stderr, which under mod_wsgi gets logged in the Apache error log under 'ERROR' with Apache sticking its own log message prefixes on each line.

You can still use an output formatter to control what you see in your part of the message, but you cannot replace the prefix Apache places on each line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top