[Edu-sig] print to apache log from cgi script

Seth David Schoen schoen@loyalty.org
Thu, 15 Nov 2001 17:05:48 -0800


Titu Kim writes:

> Hi,
>    How can i output some message apache log files so i
> can see the progress in cgi script? If i use regular
> print, cgi prints the content to client browser. 
> 
> Thanks for any suggestion.

With many Unix web servers like Apache, writing data to standard error
instead of standard output results in its being logged instead of
transmitted to the client.

You can write things to standard error by doing something like

import sys
#
# ...
#
sys.stderr.write("hello there from my CGI script.\n")

These errors are written _directly_ into the Apache error log for the
appropriate virtual host, which means they will be intermingled with
things like HTTP errors.  That might not be what you want; it could be
better to open your own log file from within your CGI script, using
the "open" file, and write the data directly into your private log
file instead.

Questions about things like this might be more appropriate on some
other list, although I'm not sure which one.

-- 
Seth David Schoen <schoen@loyalty.org> | Its really terrible when FBI arrested
Temp.  http://www.loyalty.org/~schoen/ | hacker, who visited USA with peacefull
down:  http://www.loyalty.org/   (CAF) | mission -- to share his knowledge with
     http://www.freesklyarov.org/      | american nation.  (Ilya V. Vasilyev)