Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Will Log4perl work threaded?

by broquaint (Abbot)
on Sep 30, 2003 at 15:30 UTC ( [id://295317]=note: print w/replies, xml ) Need Help??


in reply to Will Log4perl work threaded?

Having a quick peek at the source for Log::Log4perl::Appender::File it would appear that it will not be thread-safe due to its lack of file locking. But if you're using the Log::Log4perl::Appender::DBI layer you should be fine as DBI is thread-safe (in theory, at least).

As for a solution, I'd say just override the specific logging methods e.g

sub Log::Log4perl::Appender::File::log { my($self, %params) = @_; my $fh = $self->{fh}; flock( $fh => LOCK_EX ); print $fh $params{message}; flock( $fh => LOCK_UN ); if ($self->{autoflush}) { my $oldfh = select $self->{fh}; $| = 1; select $oldfh; } }
Or perhaps create just a wrapper function/method that does the flocking before and after the call to the logging function.

HTH

_________
broquaint

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://295317]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-23 15:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found