Log::Contextual::TeeLogger - Output to more than one logger
use Log::Contextual::SimpleLogger; use Log::Contextual::TeeLogger; use Log::Contextual qw( :log ), -logger => Log::Contextual::TeeLogger->new({ loggers => [ Log::Contextual::SimpleLogger->new({ levels => [ 'debug' ] }), Log::Contextual::SimpleLogger->new({ levels => [ 'info' ], coderef => sub { print @_ }, }), ]}); ## docs below here not yet edited log_info { 'program started' }; # no-op because info is not in levels sub foo { log_debug { 'entered foo' }; ... }
This module is a simple logger made mostly for demonstration and initial experimentation with Log::Contextual. We recommend you use a real logger instead. For something more serious but not overly complicated, take a look at Log::Dispatchouli.
Arguments: Dict[ levels => ArrayRef[Str], coderef => Optional[CodeRef] ] $conf
Dict[ levels => ArrayRef[Str], coderef => Optional[CodeRef] ] $conf
my $l = Log::Contextual::SimpleLogger->new({ levels => [qw( info warn )], coderef => sub { print @_ }, # the default prints to STDERR });
Creates a new SimpleLogger object with the passed levels enabled and optionally a CodeRef may be passed to modify how the logs are output/stored.
CodeRef
Levels may contain:
trace debug info warn error fatal
Arguments: @anything
@anything
All of the following six methods work the same. The basic pattern is:
sub $level { my $self = shift; print STDERR "[$level] " . join qq{\n}, @_; if $self->is_$level; }
$l->trace( 'entered method foo with args ' join q{,}, @args );
$l->debug( 'entered method foo' );
$l->info( 'started process foo' );
$l->warn( 'possible misconfiguration at line 10' );
$l->error( 'non-numeric user input!' );
$l->fatal( '1 is never equal to 0!' );
All of the following six functions just return true if their respective level is enabled.
say 'tracing' if $l->is_trace;
say 'debuging' if $l->is_debug;
say q{info'ing} if $l->is_info;
say 'warning' if $l->is_warn;
say 'erroring' if $l->is_error;
say q{fatal'ing} if $l->is_fatal;
See "AUTHOR" in Log::Contextual
See "COPYRIGHT" in Log::Contextual
See "LICENSE" in Log::Contextual
To install Log::Contextual, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Log::Contextual
CPAN shell
perl -MCPAN -e shell install Log::Contextual
For more information on module installation, please visit the detailed CPAN module installation guide.