1 package Log::Contextual::TeeLogger;
3 # ABSTRACT: Output to more than one logger
9 for my $name (qw( trace debug info warn error fatal )) {
16 foreach my $logger (@{$self->{loggers}}) {
21 my $is_name = "is_${name}";
25 foreach my $logger (@{$self->{loggers}}) {
26 return 1 if $logger->$is_name(@_);
34 my ($class, $args) = @_;
35 my $self = bless {}, $class;
37 ref($self->{loggers} = $args->{loggers}) eq 'ARRAY'
38 or die "No loggers passed to tee logger";
49 use Log::Contextual::SimpleLogger;
50 use Log::Contextual::TeeLogger;
51 use Log::Contextual qw( :log ),
52 -logger => Log::Contextual::TeeLogger->new({ loggers => [
53 Log::Contextual::SimpleLogger->new({ levels => [ 'debug' ] }),
54 Log::Contextual::SimpleLogger->new({
56 coderef => sub { print @_ },
60 ## docs below here not yet edited
62 log_info { 'program started' }; # no-op because info is not in levels
64 log_debug { 'entered foo' };
70 This module is a simple logger made mostly for demonstration and initial
71 experimentation with L<Log::Contextual>. We recommend you use a real logger
72 instead. For something more serious but not overly complicated, take a look at
79 Arguments: C<< Dict[ levels => ArrayRef[Str], coderef => Optional[CodeRef] ] $conf >>
81 my $l = Log::Contextual::SimpleLogger->new({
82 levels => [qw( info warn )],
83 coderef => sub { print @_ }, # the default prints to STDERR
86 Creates a new SimpleLogger object with the passed levels enabled and optionally
87 a C<CodeRef> may be passed to modify how the logs are output/stored.
100 Arguments: C<@anything>
102 All of the following six methods work the same. The basic pattern is:
107 print STDERR "[$level] " . join qq{\n}, @_;
113 $l->trace( 'entered method foo with args ' join q{,}, @args );
117 $l->debug( 'entered method foo' );
121 $l->info( 'started process foo' );
125 $l->warn( 'possible misconfiguration at line 10' );
129 $l->error( 'non-numeric user input!' );
133 $l->fatal( '1 is never equal to 0!' );
137 All of the following six functions just return true if their respective
142 say 'tracing' if $l->is_trace;
146 say 'debuging' if $l->is_debug;
150 say q{info'ing} if $l->is_info;
154 say 'warning' if $l->is_warn;
158 say 'erroring' if $l->is_error;
162 say q{fatal'ing} if $l->is_fatal;