1 package Log::Contextual::TeeLogger;
7 for my $name (qw( trace debug info warn error fatal )) {
14 foreach my $logger (@{$self->{loggers}}) {
19 my $is_name = "is_${name}";
23 foreach my $logger (@{$self->{loggers}}) {
24 return 1 if $logger->$is_name(@_);
32 my ($class, $args) = @_;
33 my $self = bless {}, $class;
35 ref($self->{loggers} = $args->{loggers}) eq 'ARRAY'
36 or die "No loggers passed to tee logger";
47 Log::Contextual::TeeLogger - Output to more than one logger
51 use Log::Contextual::SimpleLogger;
52 use Log::Contextual::TeeLogger;
53 use Log::Contextual qw( :log ),
54 -logger => Log::Contextual::TeeLogger->new({ loggers => [
55 Log::Contextual::SimpleLogger->new({ levels => [ 'debug' ] }),
56 Log::Contextual::SimpleLogger->new({
58 coderef => sub { print @_ },
62 ## docs below here not yet edited
64 log_info { 'program started' }; # no-op because info is not in levels
66 log_debug { 'entered foo' };
72 This module is a simple logger made mostly for demonstration and initial
73 experimentation with L<Log::Contextual>. We recommend you use a real logger
74 instead. For something more serious but not overly complicated, take a look at
81 Arguments: C<< Dict[ levels => ArrayRef[Str], coderef => Optional[CodeRef] ] $conf >>
83 my $l = Log::Contextual::SimpleLogger->new({
84 levels => [qw( info warn )],
85 coderef => sub { print @_ }, # the default prints to STDERR
88 Creates a new SimpleLogger object with the passed levels enabled and optionally
89 a C<CodeRef> may be passed to modify how the logs are output/stored.
102 Arguments: C<@anything>
104 All of the following six methods work the same. The basic pattern is:
109 print STDERR "[$level] " . join qq{\n}, @_;
115 $l->trace( 'entered method foo with args ' join q{,}, @args );
119 $l->debug( 'entered method foo' );
123 $l->info( 'started process foo' );
127 $l->warn( 'possible misconfiguration at line 10' );
131 $l->error( 'non-numeric user input!' );
135 $l->fatal( '1 is never equal to 0!' );
139 All of the following six functions just return true if their respective
144 say 'tracing' if $l->is_trace;
148 say 'debuging' if $l->is_debug;
152 say q{info'ing} if $l->is_info;
156 say 'warning' if $l->is_warn;
160 say 'erroring' if $l->is_error;
164 say q{fatal'ing} if $l->is_fatal;
168 See L<Log::Contextual/"AUTHOR">
172 See L<Log::Contextual/"COPYRIGHT">
176 See L<Log::Contextual/"LICENSE">