You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Sergey Rusakov <ra...@azot.kuzbass.net> on 2002/06/11 02:41:43 UTC

Logging under CGI

Hello!
I'm working on mod_perl project and I worry about logging. I don't like to
log to Apache's error log. I want to log to file.

open(ERRORLOG, '>>/var/log/my_log');
print ERRORLOG "some text\n";
close ERRORLOG;

This bit of code runs in every apache child.
I worry abount concurent access to this log file under heavy apache load. Is
there any problems on my way?

Sergey






Re: Logging under CGI

Posted by Sam Tregar <sa...@tregar.com>.
On Mon, 10 Jun 2002, Bill Moseley wrote:

> >You are correct to worry.  You should use flock() to prevent your log file
> >from becoming corrupted.  See "perldoc -f flock()" for more details.
>
> Maybe it's a matter of volume.  Or size of string written to the log.  But
> I don't flock, and I keep the log file open between requests and only
> reopen if stat() shows that the file was renamed.  So far been lucky.

Nope, just plain luck.  Keep it running long enough without locking and
you will eventually have a corrupted log file.

-sam



Re: Logging under CGI

Posted by Bill Moseley <mo...@hank.org>.
At 10:30 PM 06/10/02 -0400, Sam Tregar wrote:
>On Tue, 11 Jun 2002, Sergey Rusakov wrote:
>
>> open(ERRORLOG, '>>/var/log/my_log');
>> print ERRORLOG "some text\n";
>> close ERRORLOG;
>>
>> This bit of code runs in every apache child.
>> I worry abount concurent access to this log file under heavy apache
load. Is
>> there any problems on my way?
>
>You are correct to worry.  You should use flock() to prevent your log file
>from becoming corrupted.  See "perldoc -f flock()" for more details.

Maybe it's a matter of volume.  Or size of string written to the log.  But
I don't flock, and I keep the log file open between requests and only
reopen if stat() shows that the file was renamed.  So far been lucky.


-- 
Bill Moseley
mailto:moseley@hank.org

Re: Logging under CGI

Posted by Les Mikesell <le...@attbi.com>.
>From: "Sergey Rusakov" <ra...@azot.kuzbass.net>

> open(ERRORLOG, '>>/var/log/my_log');
> print ERRORLOG "some text\n";
> close ERRORLOG;
> 
> This bit of code runs in every apache child.
> I worry abount concurent access to this log file under heavy apache load. Is
> there any problems on my way?

This is OS dependent.  Most unix type systems perform an
atomic seek-to-end-of-file along with the write when you
have opened in append mode, so as long as the writes are
small enough to complete in one operation concurrency
is not an issue.  It doesn't work over NFS when writing
from multiple machines and it probably doesn't work
the same way on Windows.

  Les Mikesell
      lesmikesell@attbi.com


Re: Logging under CGI

Posted by Sam Tregar <sa...@tregar.com>.
On Mon, 10 Jun 2002, Sam Tregar wrote:

> You are correct to worry.  You should use flock() to prevent your log file
> from becoming corrupted.  See "perldoc -f flock()" for more details.

Gah, these fingers...  That should be "perldoc -f flock".

-sam



Re: Logging under CGI

Posted by Sam Tregar <sa...@tregar.com>.
On Tue, 11 Jun 2002, Sergey Rusakov wrote:

> open(ERRORLOG, '>>/var/log/my_log');
> print ERRORLOG "some text\n";
> close ERRORLOG;
>
> This bit of code runs in every apache child.
> I worry abount concurent access to this log file under heavy apache load. Is
> there any problems on my way?

You are correct to worry.  You should use flock() to prevent your log file
from becoming corrupted.  See "perldoc -f flock()" for more details.

-sam