Hello monks,

I am using Log::Log4perl as logger in my fastcgi based web application (in apache on WinXP). There is multiple processes with same code, so all pieces is writing to same log file. I wondered if it is a problem, so made simple test:

use Log::Log4perl qw(:easy); Log::Log4perl->init(\ qq{ log4perl.logger=DEBUG, A1 log4perl.appender.A1 = Log::Log4perl::Appender::File log4perl.appender.A1.filename = test2.log log4perl.appender.A1.syswrite = 1 log4perl.appender.A1.layout = SimpleLayout }); my $id = shift; for (1..20) { DEBUG "tick $_ from $id"; sleep(1); }

The script above (in file log_test.pl) is runned ten times with xargs like this

perl -E "say for 1..10" | xargs -n 1 -P 10 perl log_test.pl

Log file should contain 20 ticks from 10 processes

... DEBUG - tick 1 from 4 DEBUG - tick 1 from 5 DEBUG - tick 2 from 9 DEBUG - tick 2 from 10 ...

Unfortunately, there few entries missing. Typically it is like 5-10 entries out of 200 expected. I tried to enable/disable syswrite option, but it end up with similar results. I also tried to use Log::Log4perl::Appender::Synchronized, but it seems that IPC::SysV it is using does not work on Windows.

Any idea for better approach/solution?

-- thanks, Roman


In reply to Multiple processes using Log::Log4perl to write into single log by bobr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.