The Log::Log4perl framework provides a Synchronized
appender which does exactly that: In ensures that log messages originating from parallel processes get written one by one. So if they all end up in a single file, they get written properly without interleaving. Read this
FAQ on how to configure the Log::Log4perl module on CPAN for this.