Codebase list liblog-agent-perl / b18c45b
Merge pull request #20 from rmanfredi/info-debug Adding loginfo() and logdebug(). Mark Rogaski authored 3 years ago GitHub committed 3 years ago
9 changed file(s) with 125 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
119119 sub logwarn { intercept(\@_, '>>', 'logwarn', 'error', 'WARNING') }
120120 sub logxcarp { intercept(\@_, '>>', 'logxcarp', 'error', 'WARNING') }
121121 sub logsay { intercept(\@_, '>>', 'logsay', 'output') }
122 sub loginfo { intercept(\@_, '>>', 'loginfo', 'output') }
123 sub logdebug { intercept(\@_, '>>', 'logdebug', 'output') }
122124
123125 #
124126 # logwrite -- redefined
284284 $self->emit('output', 'notice', $str);
285285 }
286286
287 #
288 # loginfo
289 #
290 # Log message to "output" channel at "info" priority
291 #
292 sub loginfo {
293 my($self, $str) = @_;
294
295 #
296 # send message to drivers
297 #
298 $self->emit('output', 'info', $str);
299 }
300
301 #
302 # logdebug
303 #
304 # Log message to "output" channel at "debug" priority
305 #
306 sub logdebug {
307 my($self, $str) = @_;
308
309 #
310 # send message to drivers
311 #
312 $self->emit('output', 'debug', $str);
313 }
314
287315 1; # for require
288316 __END__
289317
4343 # routines would not do anything. Let's redefine them though...
4444 #
4545
46 sub logerr {}
47 sub logwarn {}
46 sub logerr {}
47 sub logwarn {}
4848 sub logcluck {}
49 sub logsay {}
49 sub logsay {}
50 sub loginfo {}
51 sub logdebug {}
5052 sub logwrite {}
5153 sub logxcarp {}
5254
361361 }
362362
363363 #
364 # loginfo
365 #
366 # Log message at the "info" level.
367 #
368 sub loginfo {
369 my $self = shift;
370 my ($str) = @_;
371 $self->emit('output', 'info', $str);
372 }
373
374 #
375 # logdebug
376 #
377 # Log message at the "debug" level.
378 #
379 sub logdebug {
380 my $self = shift;
381 my ($str) = @_;
382 $self->emit('output', 'debug', $str);
383 }
384
385 #
364386 # logwrite
365387 #
366388 # Emit the message to the specified channel
2626 @EXPORT = qw(
2727 logconfig
2828 logconfess logcluck logcroak logcarp logxcroak logxcarp
29 logsay logerr logwarn logdie logtrc logdbg
29 logdebug loginfo logsay logerr logwarn logdie logtrc logdbg
3030 );
3131 @EXPORT_OK = qw(
3232 logwrite logtags
347347 $Driver->logsay($str);
348348 }
349349
350 # loginfo
351 #
352 # Log message at the "info" level.
353 #
354 sub loginfo {
355 return if $Trace < INFO;
356 my $ptag = prio_tag(priority_level(INFO)) if defined $Priorities;
357 my $str = tag_format_args($Caller, $ptag, $Tags, \@_);
358 &log_default unless defined $Driver;
359 $Driver->loginfo($str);
360 }
361
362 # logdebug
363 #
364 # Log message at the "debug" level.
365 #
366 sub logdebug {
367 return if $Trace < DEBUG;
368 my $ptag = prio_tag(priority_level(INFO)) if defined $Priorities;
369 my $str = tag_format_args($Caller, $ptag, $Tags, \@_);
370 &log_default unless defined $Driver;
371 $Driver->logdebug($str);
372 }
373
350374 #
351375 # logtrc -- frozen
352376 #
565589 routine checks the logging level (either explicit as in C<"info:14">
566590 or implicit as in C<"notice">) against the trace level.
567591
592 =item logdebug I<message>
593
594 Log the message at the C<debug> priority to the C<output> channel.
595
596 The difference with logdbg() is twofold: logging is done on the
597 C<output> channel, not the C<debug> one, and the priority is implicit.
598
599 =item loginfo I<message>
600
601 Log the message at the C<info> priority to the C<output> channel.
602
568603 =item logsay I<message>
569604
570605 Log the message at the C<notice> priority to the C<output> channel.
1111 #
1212 ##########################################################################
1313
14 print "1..4\n";
14 print "1..6\n";
1515
1616 require './t/code.pl';
1717 sub ok;
2626
2727 logerr "error";
2828 logsay "message";
29 loginfo "info";
30 logdebug "debugging";
2931 logtrc 'debug', "debug";
3032
3133 close STDOUT;
3436 ok 1, contains("t/default.err", '^Error$');
3537 ok 2, contains("t/default.err", '^Message$');
3638 ok 3, !contains("t/default.err", '^Debug$');
37 ok 4, 0 == -s "t/default.out";
39 ok 4, !contains("t/default.err", '^Debugging$');
40 ok 5, !contains("t/default.err", '^Info$');
41 ok 6, 0 == -s "t/default.out";
3842
3943 unlink 't/default.out', 't/default.err';
1313
1414 use Test::More;
1515 use Log::Agent;
16 use Log::Agent::Priorities qw(:LEVELS);
1617 require Log::Agent::Driver::File;
1718 require './t/common.pl';
1819
19 BEGIN { plan tests => 38 }
20 BEGIN { plan tests => 42 }
2021
2122 my $driver = Log::Agent::Driver::File->make(); # take all defaults
2223 logconfig(-driver => $driver);
5455 },
5556 -duperr => 1,
5657 );
57 logconfig(-driver => $driver);
58 logconfig(-driver => $driver, -level => DEBUG);
5859
5960 open(ORIGOUT, ">&STDOUT") or die "can't dup STDOUT: $!\n";
6061 open(STDOUT, ">t/file.out") or die "can't redirect STDOUT: $!\n";
6465 select(ORIGOUT); $| = 1;
6566
6667 logerr "error";
68 logdebug "debug";
69 loginfo "info";
6770 logsay "message";
6871 logwarn "warning";
6972 eval { logdie "die" };
7982 ok(contains("t/file.err", '^DATE me\[\d+\]: error$'));
8083 ok(contains("t/file.out", 'ERROR: error'));
8184 ok(contains("t/file.out", '^DATE me\[\d+\]: message$'));
85 ok(contains("t/file.out", '^DATE me\[\d+\]: info$'));
86 ok(contains("t/file.out", '^DATE me\[\d+\]: debug$'));
8287 ok(! contains("t/file.err", 'message'));
88 ok(! contains("t/file.err", 'info'));
89 ok(! contains("t/file.err", 'debug'));
8390 ok(contains("t/file.err", '^DATE me\[\d+\]: warning$'));
8491 ok(contains("t/file.out", 'WARNING: warning'));
8592 ok(contains("t/file.err", '^DATE me\[\d+\]: die$'));
1515 use Test;
1616 require './t/common.pl';
1717
18 BEGIN { plan tests => 19 }
18 BEGIN { plan tests => 27 }
1919
2020 use Log::Agent;
21 use Log::Agent::Priorities qw(:LEVELS);
2122 require Log::Agent::Driver::Fork;
2223 require Log::Agent::Driver::Default;
2324 require Log::Agent::Driver::File;
3435 -duperr => 1,
3536 )
3637 );
37 logconfig( -driver => $driver );
38 logconfig( -driver => $driver, -level => DEBUG );
3839
3940 open(ORIGOUT, ">&STDOUT") or die "can't dup STDOUT: $!\n";
4041 open(STDOUT, ">t/fork_std.out") or die "can't redirect STDOUT: $!\n";
4546
4647 logerr "out of pez";
4748 logsay "una is a growing pup";
49 loginfo "COOLING";
50 logdebug "COOKING";
4851 logtrc 'debug', "HLAGHLAGHLAGH";
4952 logwarn "do not try this at home";
5053 eval { logdie "et tu, Chuckles?" };
6164 ok(contains("t/fork_std.err", '^moose: out of pez$'));
6265 ok(! contains("t/fork_std.err", '^Out of pez$'));
6366 ok(contains("t/fork_std.err", '^moose: una is a growing pup$'));
67 ok(contains("t/fork_std.err", '^moose: COOLING'));
68 ok(contains("t/fork_std.err", '^moose: COOKING'));
6469 ok(! contains("t/fork_std.err", '^Una is a growing pup$'));
70 ok(! contains("t/fork_std.err", '^COOKING$'));
71 ok(! contains("t/fork_std.err", '^COOLING$'));
6572 ok(contains("t/fork_std.err", '^moose: et tu, Chuckles\?$'));
6673 ok(! contains("t/fork_std.err", '^Et tu, Chuckles\?$'));
6774 ok(contains("t/fork_std.err", '^moose: do not try this at home$'));
7481 ok(contains("t/fork_file.out", 'ERROR: out of pez'));
7582 ok(contains("t/fork_file.out", '^DATE squirrel\[\d+\]: una is a growing pup$'));
7683 ok(! contains("t/fork_file.err", 'una is a growing pup'));
84 ok(! contains("t/fork_file.err", 'COOKING'));
85 ok(! contains("t/fork_file.err", 'COOLING'));
7786 ok(contains("t/fork_file.err", '^DATE squirrel\[\d+\]: do not try this at home$'));
7887 ok(contains("t/fork_file.out", 'WARNING: do not try this at home'));
7988 ok(contains("t/fork_file.err", '^DATE squirrel\[\d+\]: et tu, Chuckles\?$'));
8089 ok(contains("t/fork_file.out", 'FATAL: et tu, Chuckles\?'));
90 ok(contains("t/fork_file.out", 'COOKING'));
91 ok(contains("t/fork_file.out", 'COOLING'));
8192
8293 unlink 't/fork_std.out', 't/fork_std.err',
8394 't/fork_file.out', 't/fork_file.err';
1111 #
1212 ##########################################################################
1313
14 print "1..5\n";
14 print "1..7\n";
1515
1616 require './t/code.pl';
1717 sub ok;
3838 logsay "notice string";
3939 logcarp "carp string";
4040 logdbg 'info:12', "info string";
41 logdebug "debug string in out";
4142
4243 ok 1, contains("t/file.err", "<error/3> error string");
4344 ok 2, !contains("t/file.err", "notice string");
4445 ok 3, contains("t/file.err", "<warning/4> carp string");
4546 ok 4, contains("t/file.out", "<notice/6> notice string");
4647 ok 5, contains("t/file.err", "<info/12> info string");
48 ok 6, !contains("t/file.err", "debug string in out");
49 ok 7, contains("t/file.out", "debug string in out");
4750
4851 unlink 't/file.out', 't/file.err';