Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Logging in a multi-process environment

by tex (Acolyte)
on Oct 18, 2011 at 06:17 UTC ( #932071=perlquestion: print w/replies, xml ) Need Help??

tex has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I'm working on an application that creates many (e.g. 100) forks to do some OS related work (e.g. make some kind of backups).

I'd like to provide a verbose debug log. Each of my forks' output should end up in one logfile after my script has finished.

How should I implement this?

If I just fork w/ the open filehandle I'll end up having garbage and/or duplicate lines in my logfile.

I could close the logfile after each write and use Flock.

Or I could create a dedicated logging child that communicates with the other by the means of a pipe().

Anything else?

And if the solution would integrated nicely with Log::Dispatch I'd be super happy.

Please note that using the syslog is not an option here. I alreay have syslog logging in place for the more severe issues, but I don't want to put the debugging information into the syslog.

Thanks, tex

Replies are listed 'Best First'.
Re: Logging in a multi-process environment
by wwe (Friar) on Oct 18, 2011 at 07:28 UTC
    Take a look at Log::Log4perl. There is no explicit statement if it is thread safe but some FAQs make me think it is. Maybe this will help you too http://www.webmasterkb.com/Uwe/Forum.aspx/perl-newbie/18057/Log-Log4perl

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2021-11-30 08:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?