1Log::Handler(3) User Contributed Perl Documentation Log::Handler(3)
2
3
4
6 Log::Handler - Log messages to several outputs.
7
9 use Log::Handler;
10
11 my $log = Log::Handler->new();
12
13 $log->add(
14 file => {
15 filename => "file.log",
16 maxlevel => "debug",
17 minlevel => "warning",
18 }
19 );
20
21 $log->warning("message");
22
23 Or
24
25 use Log::Handler;
26
27 my $log = Log::Handler->new(
28 screen => {
29 log_to => "STDOUT",
30 maxlevel => "debug",
31 minlevel => "debug",
32 message_layout => "%T [%L] %m (%C)",
33 },
34 screen => {
35 log_to => "STDOUT",
36 maxlevel => "info",
37 minlevel => "notice",
38 },
39 screen => {
40 log_to => "STDERR",
41 maxlevel => "warning",
42 minlevel => "emergency",
43 },
44 );
45
46 Or
47
48 use Log::Handler;
49
50 my $log = Log::Handler->new();
51
52 $log->config( config => "logger.conf" );
53
54 # and maybe later
55
56 $log->reload( config => "logger.conf" );
57
58 Or
59
60 # create a application wide logger
61 package MyApp;
62 use Log::Handler;
63 my $log = Log::Handler->create_logger("myapp");
64 $log->add(screen => { maxlevel => "info" });
65 $log->info("info message");
66
67 # get logger with get_logger()
68 package MyApp::Admin;
69 use Log::Handler;
70 my $log = Log::Handler->get_logger("myapp");
71 $log->info("info message from MyApp::Admin");
72
74 The "Log::Handler" is a object oriented handler for logging, tracing
75 and debugging. It is very easy to use and provides a simple interface
76 for multiple output objects with lots of configuration parameters. You
77 can easily filter the amount of logged information on a per-output
78 base, define priorities, create patterns to format the messages and
79 reload the complete logging machine.
80
81 See the documentation for details.
82
84 Note that the default for option "newline" is now set to TRUE and
85 newlines will be appended automatically to each message if no newline
86 exists.
87
88 A long time I thought about this serious change and have come to the
89 decision to change it.
90
91 The default for option "mode" from Log::Handler::Output::File is now
92 "append" and not "excl" anymore.
93
94 The methods reload() and validate() are new since version 0.62. I
95 tested it with Screen.pm, File.pm and DBI.pm and it runs fine. If you
96 find bugs then open a bug report please :-)
97
99 There are eigth levels available:
100
101 7 debug
102 6 info
103 5 notice
104 4 warning, warn
105 3 error, err
106 2 critical, crit
107 1 alert
108 0 emergency, emerg
109
110 "debug" is the highest and "emergency" is the lowest level.
111
112 Level "debug" is the highest level because it basically says to log
113 every peep.
114
116 Level methods
117 debug()
118 info()
119 notice()
120 warning(), warn()
121 error(), err()
122 critical(), crit()
123 alert()
124 emergency(), emerg()
125
126 The call of a log level method is very simple:
127
128 $log->info("Hello World! How are you?");
129
130 Or maybe:
131
132 $log->info("Hello World!", "How are you?");
133
134 Both calls would log - if level INFO is active:
135
136 Feb 01 12:56:31 [INFO] Hello World! How are you?
137
138 is_* methods
139 is_debug()
140 is_info()
141 is_notice()
142 is_warning(), is_warn()
143 is_error(), is_err()
144 is_critical(), is_crit()
145 is_alert()
146 is_emergency(), is_emerg()
147
148 These twelve methods could be very useful if you want to kwow if the
149 current level would log the message. All methods returns TRUE if the
150 current set of "minlevel" and "maxlevel" would log the message and
151 FALSE if not.
152
154 fatal, is_fatal
155 trace
156 dump
157 die
158 log
159
160 For a full list take a look into the documentation of
161 Log::Handler::Levels.
162
164 new()
165 Call new() to create a new log handler object.
166
167 my $log = Log::Handler->new();
168
169 add()
170 Call add() to add a new output object.
171
172 The method expects 2 parts of options; the options for the handler and
173 the options for the output module you want to use. The output modules
174 got it's own documentation for all options.
175
176 Example:
177
178 use Log::Handler;
179
180 my $log = Log::Handler->new();
181
182 $log->add(
183
184 # Add "file output"
185 file => {
186
187 # handler options (see Log::Handler)
188 timeformat => "%Y/%m/%d %H:%M:%S",
189 message_layout => "%T [%L] %S: %m",
190 maxlevel => "debug",
191 minlevel => "emergency",
192 die_on_errors => 1,
193 debug_trace => 0,
194 debug_mode => 2,
195 debug_skip => 0,
196
197 # file options (see Log::Handler::Output::File)
198 filename => "file.log",
199 filelock => 1,
200 fileopen => 1,
201 reopen => 1,
202 autoflush => 1,
203 permissions => "0660",
204 utf8 => 1,
205
206 }
207 );
208
209 Take a look to Log::Handler::Examples for more examples.
210
211 The following options are possible for the handler:
212
213 maxlevel and minlevel
214 With these options it's possible to set the log levels for your
215 program.
216
217 Example:
218
219 maxlevel => "error"
220 minlevel => "emergency"
221
222 # or
223
224 maxlevel => "err"
225 minlevel => "emerg"
226
227 # or
228
229 maxlevel => 3
230 minlevel => 0
231
232 It's possible to set the log level as string or as number. The
233 default setting for "maxlevel" is "warning" and the default setting
234 for "minlevel" is "emergency".
235
236 Example: If "maxlevel" is set to "warning" and "minlevel" to
237 "emergency" then the levels "warning", "error", "critical", "alert"
238 and "emergency" would be logged.
239
240 You can set both to 8 or "nothing" if you want to disable the
241 logging machine.
242
243 timeformat
244 The option "timeformat" is used to set the format for the
245 placeholder %T. The string is converted with "POSIX::strftime".
246 The default format is set to "%b %d %H:%M:%S" and looks like
247
248 Feb 01 12:56:31
249
250 If you would set the format to "%Y/%m/%d %H:%M:%S" it would looks
251 like
252
253 2007/02/01 12:56:31
254
255 dateformat
256 This options works like "timeformat". You can set a format that is
257 used for the placeholder %D. It's just useful if you want to split
258 the date and time:
259
260 $log->add(file => {
261 filename => "file.log",
262 dateformat => "%Y-%m-%d",
263 timeformat => "%H:%M:%S",
264 message_layout => "%D %T %L %m",
265 });
266
267 $log->error("an error here");
268
269 This looks like
270
271 2007-02-01 12:56:31 ERROR an error here
272
273 This option is not used by default.
274
275 newline
276 "newline" is a very helpful option. It let the logger appends a
277 newline to the message if a newline doesn't exist.
278
279 0 - do nothing
280 1 - append a newline if not exist (default)
281
282 Example:
283
284 $log->add(
285 screen => {
286 newline => 1,
287 maxlevel => "info",
288 }
289 );
290
291 $log->info("message\n");
292 $log->info("message");
293
294 In both cases the message would be logged with a newline at the
295 end.
296
297 message_layout
298 With this option it's possible to create your own message layout
299 with different placeholders in printf() style. The available
300 placeholders are:
301
302 %L Log level
303 %T Time or full timestamp (option timeformat)
304 %D Date (option dateformat)
305 %P PID
306 %H Hostname
307 %U User name
308 %G Group name
309 %N Newline
310 %S Program name
311 %C Caller - filename and line number
312 %p Caller - package name
313 %f Caller - file name
314 %l Caller - line number
315 %s Caller - subroutine name
316 %r Runtime in seconds since program start
317 %t Time measurement - replaced with the time since the last call of $log->$level
318 %m Message
319 %% Percent
320
321 The default message layout is set to "%T [%L] %m".
322
323 As example the following code
324
325 $log->alert("foo bar");
326
327 would log
328
329 Feb 01 12:56:31 [ALERT] foo bar
330
331 If you set "message_layout" to
332
333 message_layout => "%T foo %L bar %m (%C)"
334
335 and call
336
337 $log->info("baz");
338
339 then it would log
340
341 Feb 01 12:56:31 foo INFO bar baz (script.pl, line 40)
342
343 Traces will be appended after the complete message.
344
345 You can create your own placeholders with the method set_pattern().
346
347 message_pattern
348 This option is just useful if you want to forward messages to
349 output modules that needs the parts of a message as a hash
350 reference - as example Log::Handler::Output::Forward,
351 Log::Handler::Output::DBI or Log::Handler::Output::Screen.
352
353 The option expects a list of placeholders:
354
355 # as a array reference
356 message_pattern => [ qw/%T %L %H %m/ ]
357
358 # or as a string
359 message_pattern => "%T %L %H %m"
360
361 The patterns will be replaced with real names as hash keys.
362
363 %L level
364 %T time
365 %D date
366 %P pid
367 %H hostname
368 %U user
369 %G group
370 %N newline
371 %r runtime
372 %C caller
373 %p package
374 %f filename
375 %l line
376 %s subroutine
377 %S progname
378 %t mtime
379 %m message
380
381 Here a full code example:
382
383 use Log::Handler;
384
385 my $log = Log::Handler->new();
386
387 $log->add(forward => {
388 forward_to => \&my_func,
389 message_pattern => [ qw/%T %L %H %m/ ],
390 message_layout => "%m",
391 maxlevel => "info",
392 });
393
394 $log->info("a forwarded message");
395
396 # now you can access it
397
398 sub my_func {
399 my $msg = shift;
400 print "Timestamp: $msg->{time}\n";
401 print "Level: $msg->{level}\n";
402 print "Hostname: $msg->{hostname}\n";
403 print "Message: $msg->{message}\n";
404 }
405
406 prepare_message
407 "prepare_message" is useful if you want to do something with the
408 message before it will be logged... maybe you want to create your
409 own layout because message_layout doesn't meet your claim.
410
411 $log->add(
412 screen => {
413 newline => 1,
414 message_layout => "%m (%t)",
415 message_pattern => [ qw/%T %L %H %m/ ],
416 prepare_message => \&format,
417 }
418 );
419
420 $log->error("foo");
421 $log->error("bar");
422 $log->error("baz");
423
424 sub format {
425 my $m = shift;
426
427 $m->{message} = sprintf("%-20s %-20s %-20s %s",
428 $m->{time}, $m->{level}, $m->{hostname}, $m->{message});
429 }
430
431 The output looks like
432
433 Mar 08 15:14:20 ERROR h1434036 foo (0.039694)
434 Mar 08 15:14:20 ERROR h1434036 bar (0.000510)
435 Mar 08 15:14:20 ERROR h1434036 baz (0.000274)
436
437 priority
438 With this option you can set the priority of your output objects.
439 This means that messages will be logged at first to the outputs
440 with a higher priority. If this option is not set then the default
441 priority begins with 10 and will be increased +1 with each output.
442 Example:
443
444 We add a output with no priority
445
446 $log->add(file => { filename => "file1.log" });
447
448 This output gets the priority of 10. Now we add another output
449
450 $log->add(file => { filename => "file2.log" });
451
452 This output gets the priority of 11... and so on.
453
454 Messages would be logged at first to the output with the priority
455 of 10 and then to the output with the priority of 11. Now you can
456 add another output and set the priority to 1.
457
458 $log->add(screen => { dump => 1, priority => 1 });
459
460 Messages would be logged now at first to the screen.
461
462 die_on_errors
463 Set "die_on_errors" to 0 if you don't want that the handler dies on
464 failed write operations.
465
466 0 - to disable it
467 1 - to enable it
468
469 If you set "die_on_errors" to 0 then you have to control it
470 yourself.
471
472 $log->info("info message") or die $log->errstr();
473
474 # or Log::Handler->errstr()
475 # or Log::Handler::errstr()
476 # or $Log::Handler::ERRSTR
477
478 remove_on_reload
479 This option is set to 1 by default.
480
481 Take a look to the description of the method "reload" for more
482 information about this option.
483
484 filter_message
485 With this option it's possible to set a filter. If the filter is
486 set then only messages will be logged that match the filter. You
487 can pass a regexp, a code reference or a simple string. Example:
488
489 $log->add(file => {
490 filename => "file.log",
491 maxlevel => 6,
492 filter_message => qr/log this/,
493 # or
494 # filter_message => "log this",
495 # filter_message => '^log only this$',
496 });
497
498 $log->info("log this");
499 $log->info("but not that");
500
501 If you pass your own code then you have to check the message
502 yourself.
503
504 $log->add(file => {
505 filename => "file.log",
506 maxlevel => 6,
507 filter_message => \&my_filter
508 });
509
510 # return TRUE if you want to log the message, FALSE if not
511 sub my_filter {
512 my $msg = shift;
513 $msg->{message} =~ /your filter/;
514 }
515
516 It's also possible to define a simple condition with matches. Just
517 pass a hash reference with the options "matchN" and "condition".
518 Example:
519
520 $log->add(file => {
521 filename => "file.log",
522 maxlevel => 6,
523 filter_message => {
524 match1 => "log this",
525 match2 => qr/with that/,
526 match3 => "(?:or this|or that)",
527 condition => "(match1 && match2) || match3",
528 }
529 });
530
531 NOTE that re-eval in regexes is not valid! Something like
532
533 match1 => '(?{unlink("file.txt")})'
534
535 would cause an error!
536
537 skip_message
538 This is the opposite of option "filter_message", but it's only
539 possible to set a simple string or regular expression.
540
541 $log->add(file => {
542 filename => "file.log",
543 maxlevel => 6,
544 skip => '^do not log this.+$'
545 });
546
547 category
548 The parameter "category" works like "filter_caller" but is much
549 easier to configure. You can set a comma separated list of
550 modules. As example if you would set the category to
551
552 category => "MyApp::User"
553
554 then all messages of MyApp::User and the submodules would be
555 logged.
556
557 Example:
558
559 my $log = Log::Handler->new();
560
561 $log->add(
562 screen => {
563 maxlevel => "info",
564 category => "MyApp::User, MyApp::Session"
565 }
566 );
567
568 package MyApp;
569 $log->info(__PACKAGE__);
570
571 package MyApp::Products;
572 $log->info(__PACKAGE__);
573
574 package MyApp::User;
575 $log->info(__PACKAGE__);
576
577 package MyApp::Users;
578 $log->info(__PACKAGE__);
579
580 package MyApp::User::Settings;
581 $log->info(__PACKAGE__);
582
583 package MyApp::Session;
584 $log->info(__PACKAGE__);
585
586 package MyApp::Session::Settings;
587 $log->info(__PACKAGE__);
588
589 The messages of "MyApp" and "MyApp::Products" would not be logged.
590
591 The usage of categories is much faster than to filter by caller.
592
593 filter_caller
594 You can use this option to set a package name. Only messages from
595 this packages will be logged.
596
597 Example:
598
599 my $log = Log::Handler->new();
600
601 $log->add(screen => {
602 maxlevel => "info",
603 filter_caller => qr/^Foo::Bar\z/,
604 # or
605 # filter_caller => "^Foo::Bar\z",
606 });
607
608 package Foo::Bar;
609 $log->info("log this");
610
611 package Foo::Baz;
612 $log->info("but not that");
613
614 1;
615
616 This would only log the message from the package "Foo::Bar".
617
618 except_caller
619 This option is just the opposite of "filter_caller".
620
621 If you want to log messages from all callers but "Foo::Bar":
622
623 except_caller => qr/^Foo::Bar\z/
624
625 alias
626 You can set an alias if you want to get the output object later.
627 Example:
628
629 my $log = Log::Handler->new();
630
631 $log->add(screen => {
632 maxlevel => 7,
633 alias => "screen-out",
634 });
635
636 my $screen = $log->output("screen-out");
637
638 $screen->log(message => "foo");
639
640 # or in one step
641
642 $log->output("screen-out")->log(message => "foo");
643
644 debug_trace
645 You can activate a debugger that writes caller() information about
646 each active log level. The debugger is logging all defined values
647 except "hints" and "bitmask". Set "debug_trace" to 1 to activate
648 the debugger. The debugger is set to 0 by default.
649
650 debug_mode
651 There are two debug modes: line(1) and block(2) mode. The default
652 mode is 1.
653
654 The line mode looks like this:
655
656 use strict;
657 use warnings;
658 use Log::Handler;
659
660 my $log = Log::Handler->new()
661
662 $log->add(file => {
663 filename => "*STDOUT",
664 maxlevel => "debug",
665 debug_trace => 1,
666 debug_mode => 1
667 });
668
669 sub test1 { $log->warning() }
670 sub test2 { &test1; }
671
672 &test2;
673
674 Output:
675
676 Apr 26 12:54:11 [WARNING]
677 CALL(4): package(main) filename(./trace.pl) line(15) subroutine(main::test2) hasargs(0)
678 CALL(3): package(main) filename(./trace.pl) line(13) subroutine(main::test1) hasargs(0)
679 CALL(2): package(main) filename(./trace.pl) line(12) subroutine(Log::Handler::__ANON__) hasargs(1)
680 CALL(1): package(Log::Handler) filename(/usr/local/share/perl/5.8.8/Log/Handler.pm) line(713) subroutine(Log::Handler::_write) hasargs(1)
681 CALL(0): package(Log::Handler) filename(/usr/local/share/perl/5.8.8/Log/Handler.pm) line(1022) subroutine(Devel::Backtrace::new) hasargs(1) wantarray(0)
682
683 The same code example but the debugger in block mode would looks
684 like this:
685
686 debug_mode => 2
687
688 Output:
689
690 Apr 26 12:52:17 [DEBUG]
691 CALL(4):
692 package main
693 filename ./trace.pl
694 line 15
695 subroutine main::test2
696 hasargs 0
697 CALL(3):
698 package main
699 filename ./trace.pl
700 line 13
701 subroutine main::test1
702 hasargs 0
703 CALL(2):
704 package main
705 filename ./trace.pl
706 line 12
707 subroutine Log::Handler::__ANON__
708 hasargs 1
709 CALL(1):
710 package Log::Handler
711 filename /usr/local/share/perl/5.8.8/Log/Handler.pm
712 line 681
713 subroutine Log::Handler::_write
714 hasargs 1
715 CALL(0):
716 package Log::Handler
717 filename /usr/local/share/perl/5.8.8/Log/Handler.pm
718 line 990
719 subroutine Devel::Backtrace::new
720 hasargs 1
721 wantarray 0
722
723 debug_skip
724 This option let skip the caller() information the count of
725 "debug_skip".
726
727 output()
728 Call output($alias) to get the output object that you added with the
729 option "alias".
730
731 It's possible to access a output directly:
732
733 $log->output($alias)->log(message => "booo");
734
735 For more information take a look to the option "alias".
736
737 flush()
738 Call flush() if you want to send flush to all outputs that can flush.
739
740 Flush means to flush buffers and/or close and re-open outputs.
741
742 If you want to send it only to some outputs you can pass the aliases.
743
744 $log->flush(); # flush all
745 $log->flush("foo", "bar"); # flush only foo and bar
746
747 If option "die_on_errors" is set to 0 then you can intercept errors
748 with:
749
750 $log->flush or die $log->errstr;
751
752 errstr()
753 Call errstr() if you want to get the last error message. This is useful
754 if you set "die_on_errors" to 0 and the handler wouldn't die on failed
755 write operations.
756
757 use Log::Handler;
758
759 my $log = Log::Handler->new();
760
761 $log->add(file => {
762 filename => "file.log",
763 maxlevel => "info",
764 die_on_errors => 0,
765 });
766
767 $log->info("Hello World!") or die $log->errstr;
768
769 Or
770
771 unless ( $log->info("Hello World!") ) {
772 $error_string = $log->errstr;
773 # do something with $error_string
774 }
775
776 The exception is that the handler dies in any case if the call of new()
777 or add() fails because on missing or wrong settings!
778
779 config()
780 With this method it's possible to load your output configuration from a
781 file.
782
783 $log->config(config => "file.conf");
784
785 Or
786
787 $log->config(config => {
788 file => [
789 {
790 alias => "error_log",
791 filename => "error.log",
792 maxlevel => "warning",
793 minlevel => "emerg",
794 priority => 1
795 },
796 {
797 alias => "common_log",
798 filename => "common.log",
799 maxlevel => "info",
800 minlevel => "emerg",
801 priority => 2
802 },
803 ],
804 screen => {
805 alias => "screen",
806 maxlevel => "debug",
807 minlevel => "emerg",
808 log_to => "STDERR",
809 },
810 });
811
812 The key "default" is used here to define default parameters for all
813 file outputs. All other keys ("error_log", "common_log") are used as
814 aliases.
815
816 Take a look into the documentation of Log::Handler::Config for more
817 information.
818
819 reload()
820 With the method reload() it's possible to reload the logging machine.
821 Just pass the complete new configuration for all outputs, it works
822 exaclty like config().
823
824 At first you should know that it's highly recommended to set a alias
825 for each output. If you don't set a alias then the logger doesn't know
826 which output-objects to reload. If a output-objects doesn't have a
827 alias then the objects will be removed and the new configuration will
828 be added.
829
830 Example:
831
832 logger.conf
833
834 <file>
835 alias = debug
836 filename = debug.log
837 maxlevel = debug
838 minlevel = emerg
839 </file>
840
841 <file>
842 alias = common
843 filename = common.log
844 maxlevel = info
845 minlevel = emerg
846 </file>
847
848 Load the configuration
849
850 $log->config(config => "logger.conf");
851
852 Now change the configuration in logger.conf
853
854 <file>
855 alias = common
856 filename = common.log
857 maxlevel = notice
858 minlevel = emerg
859 </file>
860
861 <sendmail>
862 alias = sendmail
863 from = bar@foo.example
864 to = foo@bar.example
865 subject = your subject
866 </sendmail>
867
868 What happends now...
869
870 The file-output with the alias "debug" will be removed, the file-output
871 with the alias "common" will be reloaded and the output with the alias
872 "sendmail" will be added.
873
874 If you don't want that output-objects will be removed because they were
875 added internal, then you can set the option "remove_on_reload" to 0.
876
877 Example:
878
879 $log->config(config => "logger.conf");
880
881 $log->add(
882 forward => {
883 forward_to => \&my_func,
884 remove_on_reload => 0,
885 }
886 );
887
888 The forward-output is not removed after a reload.
889
890 validate()
891 The method validate() expects the same arguments like config() and
892 reload().
893
894 Maybe you want to validate your options before you pass them to
895 config() or reload().
896
897 Example:
898
899 my $log = Log::Handler->new();
900
901 $log->config( config => \%config );
902
903 # and maybe later
904
905 if ( $log->validate( config => \%new_config ) ) {
906 $log->reload( config => \%new_config );
907 } else {
908 warn "unable to reload configuration";
909 warn $log->errstr;
910 }
911
912 set_pattern()
913 With this option you can set your own placeholders. Example:
914
915 $log->set_pattern("%X", "key_name", sub { "value" });
916
917 # or
918
919 $log->set_pattern("%X", "key_name", "value");
920
921 Then you can use this pattern in your message layout:
922
923 $log->add(file => {
924 filename => "file.log",
925 message_layout => "%X %m%N",
926 });
927
928 Or use it with "message_pattern":
929
930 sub func {
931 my $m = shift;
932 print "$m->{key_name} $m->{message}\n";
933 }
934
935 $log->add(forward => {
936 forward_to => \&func,
937 message_pattern => "%X %m",
938 });
939
940 Note: valid character for the key name are: "[%\w\-\.]+"
941
942 set_level()
943 With this method it's possible to change the log level at runtime.
944
945 To change the log level it's necessary to use a alias - see option
946 "alias".
947
948 $log->set_level(
949 $alias => { # option alias
950 minlevel => $new_minlevel,
951 maxlevel => $new_maxlevel,
952 }
953 );
954
955 set_default_param()
956 With this methods it's possible to overwrite the default settings for
957 new outputs.
958
959 Normally you would do something like
960
961 $log->add(
962 file => {
963 filename => "debug.log",
964 maxlevel => "info",
965 timeformat => "%b %d %Y %H:%M:%S",
966 message_layout => "[%T] %L %P %t %m (%C)"
967 }
968 );
969
970 $log->add(
971 file => {
972 filename => "error.log",
973 maxlevel => "error",
974 timeformat => "%b %d %Y %H:%M:%S",
975 message_layout => "[%T] %L %P %t %m (%C)"
976 }
977 );
978
979 Now you can simplify it with
980
981 $log->set_default_param(
982 timeformat => "%b %d %Y %H:%M:%S",
983 message_layout => "[%T] %L %P %t %m (%C)"
984 );
985
986 $logg->add(
987 file => {
988 filename => "debug.log",
989 maxlevel => "info"
990 }
991 );
992
993 $log->add(
994 file => {
995 filename => "error.log",
996 maxlevel => "error"
997 }
998 );
999
1000 create_logger()
1001 create_logger() is the same like new() but it creates a global logger.
1002
1003 my $log = Log::Handler->create_logger("myapp");
1004
1005 get_logger()
1006 With get_logger() it's possible to get a logger that was created with
1007 create_logger() or with
1008
1009 use Log::Handler "myapp";
1010
1011 Just call
1012
1013 my $log = Log::Handler->get_logger("myapp");
1014
1015 If the logger does not exists then a new logger will be created and
1016 returned.
1017
1018 exists_logger()
1019 With exists_logger() it's possible to check if a logger exists and it
1020 returns TRUE or FALSE.
1021
1023 Log::Handler::Examples
1024
1026 The benchmark (examples/benchmark/benchmark.pl) runs on a Intel Core
1027 i7-920 with the following result:
1028
1029 simple pattern output took : 1 wallclock secs ( 1.26 usr + 0.01 sys = 1.27 CPU) @ 78740.16/s (n=100000)
1030 default pattern output took : 2 wallclock secs ( 2.08 usr + 0.15 sys = 2.23 CPU) @ 44843.05/s (n=100000)
1031 complex pattern output took : 4 wallclock secs ( 3.22 usr + 0.23 sys = 3.45 CPU) @ 28985.51/s (n=100000)
1032 message pattern output took : 3 wallclock secs ( 2.72 usr + 0.16 sys = 2.88 CPU) @ 34722.22/s (n=100000)
1033 suppressed output took : 0 wallclock secs ( 0.08 usr + 0.00 sys = 0.08 CPU) @ 1250000.00/s (n=100000)
1034 filtered caller output took : 2 wallclock secs ( 2.10 usr + 0.68 sys = 2.78 CPU) @ 35971.22/s (n=100000)
1035 suppressed caller output took : 1 wallclock secs ( 0.54 usr + 0.00 sys = 0.54 CPU) @ 185185.19/s (n=100000)
1036 filtered messages output took : 3 wallclock secs ( 2.62 usr + 0.08 sys = 2.70 CPU) @ 37037.04/s (n=100000)
1037
1039 Send me a mail if you have questions.
1040
1042 Prerequisites for all modules:
1043
1044 Carp
1045 Data::Dumper
1046 Fcntl
1047 Params::Validate
1048 POSIX
1049 Time::HiRes
1050 Sys::Hostname
1051 UNIVERSAL
1052
1053 Recommended modules:
1054
1055 Config::General
1056 Config::Properties
1057 DBI
1058 IO::Socket
1059 Net::SMTP
1060 YAML
1061
1062 Just for the test suite:
1063
1064 File::Spec
1065 Test::More
1066
1068 No exports.
1069
1071 Please report all bugs to <jschulz.cpan(at)bloonix.de>.
1072
1074 Jonny Schulz <jschulz.cpan(at)bloonix.de>.
1075
1077 Do you have any questions or ideas?
1078
1079 MAIL: <jschulz.cpan(at)bloonix.de>
1080
1081 IRC: irc.perl.org#perl
1082
1083 If you send me a mail then add Log::Handler into the subject.
1084
1086 Copyright (C) 2007-2009 by Jonny Schulz. All rights reserved.
1087
1088 This program is free software; you can redistribute it and/or modify it
1089 under the same terms as Perl itself.
1090
1091
1092
1093perl v5.38.0 2023-07-20 Log::Handler(3)