perl的:将记录::在多线程环境中工作Log4perl? [英] perl: Will Log::Log4perl work in a multi-threaded environment?

查看:134
本文介绍了perl的:将记录::在多线程环境中工作Log4perl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用我的perl脚本登录奥钢联登录:: Log4perl;我想知道如果做多次调用写入同一日志对象会导致不正确/错误的行为。

我使用的Appender ::文件写出来的日志以下方式:

  $&对数GT;信息(启动命令......);
我的foreach $参数(@params){
    推@thread_handles,异步{
        系统($参数);
        $对数>信息($参数COMPLETE);
        logstatus($?);
    };
}$ _-> join()方法的foreach @thread_handles;
$对数>信息(命令完成......);


解决方案

日志:: Log4perl用的基于追加程序会的工作,但使用相同的日志文件,在多线程和多处理环境中,可能会出现一些重叠。默认的文件

一种解决方案是使用登录:: Log4perl :: Appender的::同步作为一个appender。见<一href=\"http://search.cpan.org/dist/Log-Log4perl/lib/Log/Log4perl/FAQ.pm#How_can_I_run_Log%3a%3aLog4perl_under_mod_perl?\"相对=nofollow>如何mod_perl下运行日志:: Log4perl?在FAQ中获得更多信息。

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.

这篇关于perl的:将记录::在多线程环境中工作Log4perl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆