This is a discussion on Re: Logging to a file - modperl ; On 9/22/06, Jonathan wrote: > > composing the info i need to log under mp is trivial > > i'm a bit uneasy about actually logging to a file though-- it looks > like under a prefork model ( i ...
On 9/22/06, Jonathan
> composing the info i need to log under mp is trivial
> i'm a bit uneasy about actually logging to a file though-- it looks
> like under a prefork model ( i need 2+ servers to handle this ), i'd
> need to lock / open / write / close / unlock the log file per request
that isn't heavy. You may not need the lock -- your OS may
serialize writes when a file is opened in append mode for you --
so gather the info to log, then open the file, write, close the file.
That is what whatever logging utility you choose is going to have
to do anyway. If you do need the lock, the sequence would be
open, lock, seek, write, close. I believe Perl takes care of flushing and
unlocking when you close.
> does anyone know of a facility that will let me just log
> straightforward ?
use Fcntl ':flock';
my ($filename, $data) = @_;
open SIMPLELOG, ">>$filename" or die "open >>$filename: $!";
flock (SIMPLELOG, LOCK_EX);
seek(SIMPLELOG, 0, 2);
print SIMPLELOG, localtime().": $data\n";
it might get a hair faster using sysopen, sysseek and syswrite, or
written in XS, but that's
too small to put into a module IMHO
I spend so much time explaining my simple time-saving proposals that
there may actually be a net loss of time. New time saving proposal:
keep thoughts to self.