Tuesday, October 03, 2006

 

Easy Error Logging in Perl via Log4Perl

Need a quick and dirty tutorial on enabling loggers in your scripts? Here you go.
Download and Install Log-Log4perl-1.06 from CPAN (May prompt you to install IO-Tty-1.07).

The following perl script will let you give you the ability to define 3 filters for your logging: Error, Warn and Info. Warings and Errors are logged to one file and Info messages to the other.

use Log::Log4perl qw(get_logger);

# Define configuration
my $conf = q(
log4perl.logger = INFO, AppInfo, AppWarn, AppError

#filter to match INFO
log4perl.filter.MatchInfo = Log::Log4perl::Filter::LevelMatch
log4perl.filter.MatchInfo.LevelToMatch = INFO
log4perl.filter.MatchInfo.AcceptOnMatch = true

#filter to match Warn
log4perl.filter.MatchWarn = Log::Log4perl::Filter::LevelMatch
log4perl.filter.MatchWarn.LevelToMatch = WARN
log4perl.filter.MatchWarn.AcceptOnMatch = true

# filter to match Error
log4perl.filter.MatchError = Log::Log4perl::Filter::LevelMatch
log4perl.filter.MatchError.LevelToMatch = ERROR
log4perl.filter.MatchError.AcceptOnMatch = true

# Info Appender
log4perl.appender.AppInfo = Log::Log4perl::Appender::File
log4perl.appender.AppInfo.filename = detail.log
log4perl.appender.AppInfo.layout = PatternLayout
log4perl.appender.AppInfo.layout.ConversionPattern = %d %p> %F{1}:%L %M - %m%n
log4perl.appender.AppInfo.Filter = MatchInfo

# Warn Appender
log4perl.appender.AppWarn = Log::Log4perl::Appender::File
log4perl.appender.AppWarn.filename = result.log
log4perl.appender.AppWarn.layout = PatternLayout
log4perl.appender.AppWarn.Filter = MatchWarn

# Error Appender
log4perl.appender.AppError = Log::Log4perl::Appender::File
log4perl.appender.AppError.filename = detail.log
log4perl.appender.AppError.layout = PatternLayout
log4perl.appender.AppError.layout.ConversionPattern = %d %p> %F{1}:%L %M - %m%n
log4perl.appender.AppError.Filter = MatchError
);

# Initialize logging behaviour
Log::Log4perl->init( \$conf );

my $logger = get_logger("issa::test");
$logger->info("License file installed successfully");

Comments:
Many customers have stated that whenever they have ordered these counterfeit,
fake, imitation UGG's, they will arrive in the plain, brown box that looked battered. ì (IE: sand, chestnut, chocolate, black) UGG boots. As an outcome of peculiarity on the physical appearance of a pair of boots, a whole lot of people won't
want to utilize them ahead of time of.

Feel free to surf to my site: プラダ バッグ
 
I’m not sure where you are getting your information, but
great topic. I needs to spend some time learning much more or understanding more.
Thanks for wonderful info I was looking for this information for my mission.


Also visit my site - gardening
 
Hi, I log on to your blog daily. Your humoristic style is awesome,
keep up the good work!

Also visit my web page: best core exercises for men
 
I like it wheneveг people get tоgether and share opinions.


Chеcκ out my blog post core ball
 
Нowdy! I ѕіmply ωant to offer you а huge thumbs up fοr your
excellent informatіon you’ve got here on thiѕ
рost. I wіll bе сoming bаck
to youг web site for moгe soon.

My sіtе: gardening tips
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?