我正在读这个,我感到困惑和困惑.
我应该同时使用ALWAYS或print_portfolio('themessage')同时打印和登录文件吗?
我想做的事:
if ($logfile) {
open (FILE, '>>', "logfile");
print "Hello" #some code from Log4perl#;
#prints on the display and into the logfile
}
Run Code Online (Sandbox Code Playgroud)
代替:
if ($logfile) { open (FILE, '>>', "logfile"); }
print "Hello";
if ($logfile) { print FILE "Hello"; }
Run Code Online (Sandbox Code Playgroud) I would like to use a Perl variable from my script in a Log::Log4perl config file. I read the documentation and found that I can use a subroutine, but I would like to do it a little bit simpler, if possible.
I want to set the filename for my appender:
log4perl.appender.av_std_LOGFILE.filename="whateverfilename.log"
Run Code Online (Sandbox Code Playgroud)
But doing this this way, it is a fixed value.
I have the filename in a variable within my script and would like to use this at runtime:
log4perl.appender.av_std_LOGFILE.filename=\ …Run Code Online (Sandbox Code Playgroud) 我正在研究现有Perl代码库中的一个新功能,它允许我们记录发送到数据库的命令.我基于Log4perl的解决方案,这使我不必重新发明几个轮子.
不幸的是,我遇到了麻烦:每条消息都被发送到日志文件两次.我希望它停止这样做.
我的研究(谷歌)表示,将相同的消息发送到两个不同的日志文件是一个常见的问题,但这不是我所看到的.每条消息在单个日志文件中出现两次.
有没有人知道我应该从哪里开始寻找纠正这种行为的方法?
my $log_packages = undef;
sub _get_logging_modifications {
# Hash that is keyed by a package name
# and the value is the level at which
# to log that package
return %{$log_packages} if defined $log_packages;
$log_packages = {};
my $log_info = $ENV{PROJECT_LOG_INFO} || '';
for my $log_specification (split(/,/, $log_info)) {
# Skip to the next log specification unless we have
# a well formed log spec. i.e., Package::Name/LOGLEVEL
next unless $log_specification =~ m!([^/]+)/([A-Z]+)!i;
my …Run Code Online (Sandbox Code Playgroud) 我非常想念 Log4perl 中每一行的日志级别的信息easy_init。我正在运行一个大型迁移脚本,它在某些特殊记录上失败,所以我需要 grep WARNings 和ERRORs,但需要INFOrmation 上下文来修复这些。
使用此代码:
#!/usr/bin/perl
use strict; use warnings;
use Log::Log4perl qw(:easy);
Log::Log4perl->easy_init($INFO);
TRACE "bar";
DEBUG "baz";
INFO "qux";
WARN "quux";
ERROR "corge";
FATAL "grault";
Run Code Online (Sandbox Code Playgroud)
现在,我得到这个输出:
2013/06/02 13:08:48 qux
2013/06/02 13:08:48 quux
2013/06/02 13:08:48 corge
2013/06/02 13:08:48 grault
Run Code Online (Sandbox Code Playgroud)
我不想在日志消息中添加此信息,因为它已包含在我调用的日志函数中。
如何添加日志级别easy_init?我不想用一个相当小的脚本中的配置文件(即使包含内联)来初始化“常规”Log4perl,我喜欢easy_init它的清晰和简短的用法。