This blog explains how to create a auditlog with a custom log level 'AUDIT'.
We have created a custom filter AUDITFILTER which matches the level AUDIT in the appender.
Now we need to create a custom level which need to be done in code as below.
We have created a custom level 'AUDIT' which is below the level DEBUG. With custom level we need to call another method log() with 2 parameters as below.
log4perl.rootLogger=TRACE, auditlog
log4perl.filter.AUDITFILTER = Log::Log4perl::Filter::LevelMatch
log4perl.filter.AUDITFILTER .LevelToMatch = AUDIT
log4perl.filter.AUDITFILTER
.AcceptOnMatch = true
log4perl.appender.auditlog=Log::Log4perl::Appender::File
log4perl.appender.auditlog.filename=c:/perl/log-dir/audit.log
log4perl.appender.auditlog.mode=append
log4perl.appender.auditlog.Filter = AUDITFILTER
log4perl.appender.auditlog.layout=Log::Log4perl::Layout::PatternLayout
log4perl.appender.auditlog.layout.ConversionPattern=%d{ISO8601}|%C|%m%n
We have created a custom filter AUDITFILTER which matches the level AUDIT in the appender.
Now we need to create a custom level which need to be done in code as below.
use Log::Log4perl;
Log::Log4perl::Logger::create_custom_level("AUDIT", "DEBUG");
Log::Log4perl::init("log4perl.conf");
method();
sub method {
my $logger = Log::Log4perl->get_logger("");
$logger->log($AUDIT, "Received an audit message");
}
We have created a custom level 'AUDIT' which is below the level DEBUG. With custom level we need to call another method log() with 2 parameters as below.
$logger->log($AUDIT, "Received an audit message");
Wow, cool post. I'd like to write like this too - taking time and real hard work to make a great article... but I put things off too much and never seem to get started. Thanks though. 澳洲代写
ReplyDelete