Skip to content

Instantly share code, notes, and snippets.

@spicyjack
Last active December 22, 2015 20:39
Show Gist options
  • Save spicyjack/6528342 to your computer and use it in GitHub Desktop.
Save spicyjack/6528342 to your computer and use it in GitHub Desktop.
Some setup for Log::Log4perl
# color log output
if ( $cfg->get(q(colorize)) ) {
$log4perl_conf .= q(log4perl.appender.Screen )
. qq(= Log::Log4perl::Appender::ScreenColoredLevels\n);
} else {
$log4perl_conf .= q(log4perl.appender.Screen )
. qq(= Log::Log4perl::Appender::Screen\n);
}
# the rest of the log4perl setup
$log4perl_conf .= qq(log4perl.appender.Screen.stderr = 1\n)
. qq(log4perl.appender.Screen.layout = PatternLayout\n)
. q(log4perl.appender.Screen.layout.ConversionPattern )
. qq|= [%8r] %p{1} %4L (%M{1}) %m%n\n|;
# sprintf-like strings are documented at:
# https://metacpan.org/module/Log::Log4perl::Layout::PatternLayout
# sample outputs:
# [ 0] D 2216 (main::) script start; Wed Sep 11 11:54:19 PDT 2013
# [ 42] D 1027 (stat_local) stat'ing file/dir: /home/idgames/html/.message
# [ 60] D 1013 (BUILD) Absolute path is: /home/idgames/html/README.INCOMING
Log::Log4perl->init(\$log4perl_conf);
my $log = Log::Log4perl->get_logger();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment