Last active
April 14, 2016 17:58
-
-
Save pypt/fb142fa51b7edc2401652be15659e52e to your computer and use it in GitHub Desktop.
Log4perl playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package CommonImports; | |
use strict; | |
use warnings; | |
use feature qw/ :5.18 /; | |
use Modern::Perl "2014"; | |
# Initializing at root level | |
use Log::Log4perl qw(:easy); | |
Log::Log4perl::init( 'log4perl.conf' ); | |
require Exporter; | |
our @ISA = qw(Exporter); | |
use Data::Dumper; | |
use Readonly; | |
our @LOGGER = qw(FATAL ERROR WARN INFO DEBUG TRACE LOGDIE LOGWARN LOGCARP LOGCLUCK LOGCONFESS LOGCROAK); | |
our @EXPORT = ( @Readonly::EXPORT, @Data::Dumper::EXPORT, @LOGGER ); | |
# Importing stuff to the caller just like MediaWords::CommonLibs | |
sub import | |
{ | |
my ( $class, @isa ) = @_; | |
my $caller = caller; | |
strict->import(); | |
warnings->import(); | |
feature->import( qw( :5.18 ) ); | |
if ( scalar @isa ) | |
{ | |
foreach my $isa ( @isa ) | |
{ | |
if ( eval "require $isa" ) | |
{ | |
no strict 'refs'; | |
push @{ "${caller}::ISA" }, $isa; | |
} | |
} | |
} | |
$class->export_to_level( 1, $caller ); | |
return; | |
} | |
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
log4perl.rootLogger = DEBUG, STDERR | |
log4perl.appender.STDERR = Log::Log4perl::Appender::Screen | |
log4perl.appender.STDERR.name = stderr | |
log4perl.appender.STDERR.stderr = 1 | |
log4perl.appender.STDERR.layout = Log::Log4perl::Layout::PatternLayout | |
log4perl.appender.STDERR.layout.ConversionPattern = %l: %m{chomp}%n | |
log4perl.oneMessagePerAppender = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Package; | |
use strict; | |
use warnings; | |
use CommonImports; | |
sub test_subroutine() | |
{ | |
DEBUG "And I'm a test subroutine in a Package"; | |
} | |
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Simple print to STDOUT | |
main::main ./script.pl (12): Debugging statement | |
main::main ./script.pl (13): Addition: 3 | |
Package::test_subroutine Package.pm (10): And I'm a test subroutine in a Package | |
main::main ./script.pl (18): merging 3 archive.is stories | |
main::main ./script.pl (19): merging 3 archive.is stories | |
main::main ./script.pl (20): merging 3 archive.is stories |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use CommonImports; | |
use Package; | |
sub main() | |
{ | |
say "Simple print to STDOUT"; | |
DEBUG 'Debugging statement'; | |
DEBUG 'Addition: ' . (1 + 2); | |
Package::test_subroutine(); | |
my $archive_is_stories = [ qw/a b c/ ]; | |
INFO( sub { "merging " . scalar( @{ $archive_is_stories } ) . " archive.is stories" } ); | |
INFO( "merging " . scalar( @{ $archive_is_stories } ) . " archive.is stories" ); | |
INFO "merging " . scalar( @{ $archive_is_stories } ) . " archive.is stories"; | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment