I’m using logging vai Log::Log4perl in my perl script; I’m wondering if making multiple calls to write to the same log object will cause incorrect / erroneous behavior.
I’m using a Appender::File to write out the log in the following manner:
$log->info("Launching commands...");
foreach my $param (@params) {
push @thread_handles, async {
system("$param");
$log->info("$param COMPLETE");
logstatus($?);
};
}
$_->join() foreach @thread_handles;
$log->info("Commands completed...");
The Log::Log4perl with the default file based appender will work, but some overlapping may occur in a multi-threaded or multi-processed environment using the same log file.
One solution is to use Log::Log4perl::Appender::Synchronized as an appender. See How can I run Log::Log4perl under mod_perl? in the FAQ for more info.