Making my Python3 CGI write error messages to Apache errorlog?

26 views Asked by At

I am in the midst of converting a portfolio of Perl web applications to Python 3.

According to docs at https://httpd.apache.org/docs/2.4/logs.html#errorlog , "Any information written to stderr by a CGI script will be copied directly to the error log" - but when my code tries to do so:

   def scream_and_die(msg,exitcode):
         sys.tracebacklimit = 0
         sys.stderr.write(msg)
         os._exit(exitcode)

, I get a 500 error in the browser, but only

[Mon Jul 24 12:15:14.460517 2023] [cgid:error] [pid 1842:tid 140415969720064] [client 10.17.74.82:54645] End of script output before headers: incident_new.py, referer:...

in the error log.

Is there a canonically correct way to inject error messages into the Apache error log?

Thanks, -g

If I force unbuffered output with "#!/usr/bin/python3 -u", I no longer get the 500 error (blank page instead, which I expected), but then I get no entry at all in the error log.

0

There are 0 answers