> On 24 Mar 2017, at 8:57 PM, Алексей Бойко <[email protected]> wrote:
> 
> I use mod_wsgi-express with django and run server like this manage.py 
> runmodwsgi ...
> I have a question about logging.
> When python traceback appears in error_log, mod_wsgi add timestamp and other 
> information to every line and it's a problem because i sent logs to logstash 
> server and it's splited to many events. Can i somehow use python logger 
> instead of wsgi or use both just devide logs to different files?

As I mentioned in blog post comments where you originally asked this, I am not 
sure Python logging module will necessarily help if all you are doing is 
sending it to a file anyway, as it will still break the traceback over separate 
lines. Same if sending logging module output to stdout and capturing it from 
there.

The only thing you may be able to do is override the error log format used by 
Apache to add in the request ID to each log message line.

For example, if you used the options:

    --error-log-format "(%L) [%t] [%l] [pid %P] [client %a] %M" 
--log-to-terminal

Then the log output would look like:

  [Mon Mar 27 12:15:06 2017] [notice] [pid 38640] [client AH00163: 
Apache/2.4.18 (Unix) mod_wsgi/4.5.15 Python/3.6 configured -- resuming normal 
operations
 [Mon Mar 27 12:15:06 2017] [notice] [pid 38640] [client AH00094: Command line: 
'httpd (mod_wsgi-express)  -f /tmp/mod_wsgi-localhost:8000:502/httpd.conf -D 
MOD_WSGI_ERROR_LOG_FORMAT -D FOREGROUND'
(jyX4Egx+lxE) [Mon Mar 27 12:15:08 2017] [error] [pid 38642] [client ::1:53240] 
request message #1
(jyX4Egx+lxE) [Mon Mar 27 12:15:08 2017] [error] [pid 38642] [client ::1:53240] 
global message #1
(jyX4Egx+lxE) [Mon Mar 27 12:15:08 2017] [error] [pid 38642] [client ::1:53240] 
queued message #1request message #2
(jyX4Egx+lxE) [Mon Mar 27 12:15:08 2017] [error] [pid 38642] [client ::1:53240] 
global message #2
(jyX4Egx+lxE) [Mon Mar 27 12:15:08 2017] [error] [pid 38642] [client ::1:53240] 
queued message #2request message #3
(jyX4Egx+lxE) [Mon Mar 27 12:15:08 2017] [error] [pid 38642] [client ::1:53240] 
queued message #3+queued message #4
(KlYFEwx+lxE) [Mon Mar 27 12:15:09 2017] [error] [pid 38642] [client ::1:53241] 
request message #1
(KlYFEwx+lxE) [Mon Mar 27 12:15:09 2017] [error] [pid 38642] [client ::1:53241] 
global message #1
(KlYFEwx+lxE) [Mon Mar 27 12:15:09 2017] [error] [pid 38642] [client ::1:53241] 
queued message #1request message #2
(KlYFEwx+lxE) [Mon Mar 27 12:15:09 2017] [error] [pid 38642] [client ::1:53241] 
global message #2
(KlYFEwx+lxE) [Mon Mar 27 12:15:09 2017] [error] [pid 38642] [client ::1:53241] 
queued message #2request message #3
(KlYFEwx+lxE) [Mon Mar 27 12:15:09 2017] [error] [pid 38642] [client ::1:53241] 
queued message #3+queued message #4

So where an error messages occurs in context of a request, you get the leading 
() where what is in it is a identifier for the request. You can perhaps 
configure the logging system to ensure it keeps those messages together.

You can find more information about what you can use when overriding the error 
log format in:

    http://httpd.apache.org/docs/2.4/mod/core.html#errorlogformat 
<http://httpd.apache.org/docs/2.4/mod/core.html#errorlogformat>

You will need to have a recent version of mod_wsgi, newer than what most Linux 
distributions ship, although since you are using pip installed version of 
mod_wsgi that shouldn't be an issue.

Graham

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Reply via email to