1Log::Handler(3)       User Contributed Perl Documentation      Log::Handler(3)
2
3
4

NAME

6       Log::Handler - Log messages to several outputs.
7

SYNOPSIS

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

DESCRIPTION

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

IMPORTANT NOTES

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

LOG LEVELS

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

LOG LEVEL METHODS

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

SPECIAL LOG METHODS

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

METHODS

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
346           "set_pattern()".
347
348       message_pattern
349           This option is just useful if you want to forward messages to
350           output modules that needs the parts of a message as a hash
351           reference - as example Log::Handler::Output::Forward,
352           Log::Handler::Output::DBI or Log::Handler::Output::Screen.
353
354           The option expects a list of placeholders:
355
356               # as a array reference
357               message_pattern => [ qw/%T %L %H %m/ ]
358
359               # or as a string
360               message_pattern => "%T %L %H %m"
361
362           The patterns will be replaced with real names as hash keys.
363
364               %L   level
365               %T   time
366               %D   date
367               %P   pid
368               %H   hostname
369               %U   user
370               %G   group
371               %N   newline
372               %r   runtime
373               %C   caller
374               %p   package
375               %f   filename
376               %l   line
377               %s   subroutine
378               %S   progname
379               %t   mtime
380               %m   message
381
382           Here a full code example:
383
384               use Log::Handler;
385
386               my $log = Log::Handler->new();
387
388               $log->add(forward => {
389                   forward_to      => \&my_func,
390                   message_pattern => [ qw/%T %L %H %m/ ],
391                   message_layout  => "%m",
392                   maxlevel        => "info",
393               });
394
395               $log->info("a forwarded message");
396
397               # now you can access it
398
399               sub my_func {
400                   my $msg = shift;
401                   print "Timestamp: $msg->{time}\n";
402                   print "Level:     $msg->{level}\n";
403                   print "Hostname:  $msg->{hostname}\n";
404                   print "Message:   $msg->{message}\n";
405               }
406
407       prepare_message
408           "prepare_message" is useful if you want to do something with the
409           message before it will be logged... maybe you want to create your
410           own layout because message_layout doesn't meet your claim.
411
412               $log->add(
413                   screen => {
414                       newline => 1,
415                       message_layout  => "%m (%t)",
416                       message_pattern => [ qw/%T %L %H %m/ ],
417                       prepare_message => \&format,
418                   }
419               );
420
421               $log->error("foo");
422               $log->error("bar");
423               $log->error("baz");
424
425               sub format {
426                   my $m = shift;
427
428                   $m->{message} = sprintf("%-20s %-20s %-20s %s",
429                       $m->{time}, $m->{level}, $m->{hostname}, $m->{message});
430               }
431
432           The output looks like
433
434               Mar 08 15:14:20      ERROR                h1434036             foo (0.039694)
435               Mar 08 15:14:20      ERROR                h1434036             bar (0.000510)
436               Mar 08 15:14:20      ERROR                h1434036             baz (0.000274)
437
438       priority
439           With this option you can set the priority of your output objects.
440           This means that messages will be logged at first to the outputs
441           with a higher priority.  If this option is not set then the default
442           priority begins with 10 and will be increased +1 with each output.
443           Example:
444
445           We add a output with no priority
446
447               $log->add(file => { filename => "file1.log" });
448
449           This output gets the priority of 10. Now we add another output
450
451               $log->add(file => { filename => "file2.log" });
452
453           This output gets the priority of 11... and so on.
454
455           Messages would be logged at first to the output with the priority
456           of 10 and then to the output with the priority of 11. Now you can
457           add another output and set the priority to 1.
458
459               $log->add(screen => { dump => 1, priority => 1 });
460
461           Messages would be logged now at first to the screen.
462
463       die_on_errors
464           Set "die_on_errors" to 0 if you don't want that the handler dies on
465           failed write operations.
466
467               0 - to disable it
468               1 - to enable it
469
470           If you set "die_on_errors" to 0 then you have to control it
471           yourself.
472
473               $log->info("info message") or die $log->errstr();
474
475               # or Log::Handler->errstr()
476               # or Log::Handler::errstr()
477               # or $Log::Handler::ERRSTR
478
479       remove_on_reload
480           This option is set to 1 by default.
481
482           Take a look to the description of the method "reload" for more
483           information about this option.
484
485       filter_message
486           With this option it's possible to set a filter. If the filter is
487           set then only messages will be logged that match the filter. You
488           can pass a regexp, a code reference or a simple string. Example:
489
490               $log->add(file => {
491                   filename => "file.log",
492                   maxlevel => 6,
493                   filter_message => qr/log this/,
494                   # or
495                   # filter_message => "log this",
496                   # filter_message => '^log only this$',
497               });
498
499               $log->info("log this");
500               $log->info("but not that");
501
502           If you pass your own code then you have to check the message
503           yourself.
504
505               $log->add(file => {
506                   filename => "file.log",
507                   maxlevel => 6,
508                   filter_message => \&my_filter
509               });
510
511               # return TRUE if you want to log the message, FALSE if not
512               sub my_filter {
513                   my $msg = shift;
514                   $msg->{message} =~ /your filter/;
515               }
516
517           It's also possible to define a simple condition with matches. Just
518           pass a hash reference with the options "matchN" and "condition".
519           Example:
520
521               $log->add(file => {
522                   filename => "file.log",
523                   maxlevel => 6,
524                   filter_message => {
525                       match1    => "log this",
526                       match2    => qr/with that/,
527                       match3    => "(?:or this|or that)",
528                       condition => "(match1 && match2) || match3",
529                   }
530               });
531
532           NOTE that re-eval in regexes is not valid! Something like
533
534               match1 => '(?{unlink("file.txt")})'
535
536           would cause an error!
537
538       skip_message
539           This is the opposite of option "filter_message", but it's only
540           possible to set a simple string or regular expression.
541
542               $log->add(file => {
543                   filename => "file.log",
544                   maxlevel => 6,
545                   skip => '^do not log this.+$'
546               });
547
548       category
549           The parameter "category" works like "filter_caller" but is much
550           easier to configure.  You can set a comma separated list of
551           modules. As example if you would set the category to
552
553               category => "MyApp::User"
554
555           then all messages of MyApp::User and the submodules would be
556           logged.
557
558           Example:
559
560               my $log = Log::Handler->new();
561
562               $log->add(
563                   screen => {
564                       maxlevel => "info",
565                       category => "MyApp::User, MyApp::Session"
566                   }
567               );
568
569               package MyApp;
570               $log->info(__PACKAGE__);
571
572               package MyApp::Products;
573               $log->info(__PACKAGE__);
574
575               package MyApp::User;
576               $log->info(__PACKAGE__);
577
578               package MyApp::Users;
579               $log->info(__PACKAGE__);
580
581               package MyApp::User::Settings;
582               $log->info(__PACKAGE__);
583
584               package MyApp::Session;
585               $log->info(__PACKAGE__);
586
587               package MyApp::Session::Settings;
588               $log->info(__PACKAGE__);
589
590           The messages of "MyApp" and "MyApp::Products" would not be logged.
591
592           The usage of categories is much faster than to filter by caller.
593
594       filter_caller
595           You can use this option to set a package name. Only messages from
596           this packages will be logged.
597
598           Example:
599
600               my $log = Log::Handler->new();
601
602               $log->add(screen => {
603                   maxlevel => "info",
604                   filter_caller  => qr/^Foo::Bar\z/,
605                   # or
606                   # filter_caller => "^Foo::Bar\z",
607               });
608
609               package Foo::Bar;
610               $log->info("log this");
611
612               package Foo::Baz;
613               $log->info("but not that");
614
615               1;
616
617           This would only log the message from the package "Foo::Bar".
618
619       except_caller
620           This option is just the opposite of "filter_caller".
621
622           If you want to log messages from all callers but "Foo::Bar":
623
624               except_caller => qr/^Foo::Bar\z/
625
626       alias
627           You can set an alias if you want to get the output object later.
628           Example:
629
630               my $log = Log::Handler->new();
631
632               $log->add(screen => {
633                   maxlevel => 7,
634                   alias    => "screen-out",
635               });
636
637               my $screen = $log->output("screen-out");
638
639               $screen->log(message => "foo");
640
641               # or in one step
642
643               $log->output("screen-out")->log(message => "foo");
644
645       debug_trace
646           You can activate a debugger that writes "caller()" information
647           about each active log level. The debugger is logging all defined
648           values except "hints" and "bitmask". Set "debug_trace" to 1 to
649           activate the debugger.  The debugger is set to 0 by default.
650
651       debug_mode
652           There are two debug modes: line(1) and block(2) mode. The default
653           mode is 1.
654
655           The line mode looks like this:
656
657               use strict;
658               use warnings;
659               use Log::Handler;
660
661               my $log = Log::Handler->new()
662
663               $log->add(file => {
664                   filename    => "*STDOUT",
665                   maxlevel    => "debug",
666                   debug_trace => 1,
667                   debug_mode  => 1
668               });
669
670               sub test1 { $log->warning() }
671               sub test2 { &test1; }
672
673               &test2;
674
675           Output:
676
677               Apr 26 12:54:11 [WARNING]
678                  CALL(4): package(main) filename(./trace.pl) line(15) subroutine(main::test2) hasargs(0)
679                  CALL(3): package(main) filename(./trace.pl) line(13) subroutine(main::test1) hasargs(0)
680                  CALL(2): package(main) filename(./trace.pl) line(12) subroutine(Log::Handler::__ANON__) hasargs(1)
681                  CALL(1): package(Log::Handler) filename(/usr/local/share/perl/5.8.8/Log/Handler.pm) line(713) subroutine(Log::Handler::_write) hasargs(1)
682                  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)
683
684           The same code example but the debugger in block mode would looks
685           like this:
686
687                  debug_mode => 2
688
689           Output:
690
691              Apr 26 12:52:17 [DEBUG]
692                 CALL(4):
693                    package     main
694                    filename    ./trace.pl
695                    line        15
696                    subroutine  main::test2
697                    hasargs     0
698                 CALL(3):
699                    package     main
700                    filename    ./trace.pl
701                    line        13
702                    subroutine  main::test1
703                    hasargs     0
704                 CALL(2):
705                    package     main
706                    filename    ./trace.pl
707                    line        12
708                    subroutine  Log::Handler::__ANON__
709                    hasargs     1
710                 CALL(1):
711                    package     Log::Handler
712                    filename    /usr/local/share/perl/5.8.8/Log/Handler.pm
713                    line        681
714                    subroutine  Log::Handler::_write
715                    hasargs     1
716                 CALL(0):
717                    package     Log::Handler
718                    filename    /usr/local/share/perl/5.8.8/Log/Handler.pm
719                    line        990
720                    subroutine  Devel::Backtrace::new
721                    hasargs     1
722                    wantarray   0
723
724       debug_skip
725           This option let skip the "caller()" information the count of
726           "debug_skip".
727
728   output()
729       Call "output($alias)" to get the output object that you added with the
730       option "alias".
731
732       It's possible to access a output directly:
733
734           $log->output($alias)->log(message => "booo");
735
736       For more information take a look to the option "alias".
737
738   flush()
739       Call "flush()" if you want to send flush to all outputs that can flush.
740
741       Flush means to flush buffers and/or close and re-open outputs.
742
743       If you want to send it only to some outputs you can pass the aliases.
744
745           $log->flush(); # flush all
746           $log->flush("foo", "bar"); # flush only foo and bar
747
748       If option "die_on_errors" is set to 0 then you can intercept errors
749       with:
750
751           $log->flush or die $log->errstr;
752
753   errstr()
754       Call "errstr()" if you want to get the last error message. This is
755       useful if you set "die_on_errors" to 0 and the handler wouldn't die on
756       failed write operations.
757
758           use Log::Handler;
759
760           my $log = Log::Handler->new();
761
762           $log->add(file => {
763               filename      => "file.log",
764               maxlevel      => "info",
765               die_on_errors => 0,
766           });
767
768           $log->info("Hello World!") or die $log->errstr;
769
770       Or
771
772           unless ( $log->info("Hello World!") ) {
773               $error_string = $log->errstr;
774               # do something with $error_string
775           }
776
777       The exception is that the handler dies in any case if the call of
778       "new()" or "add()" fails because on missing or wrong settings!
779
780   config()
781       With this method it's possible to load your output configuration from a
782       file.
783
784           $log->config(config => "file.conf");
785
786       Or
787
788           $log->config(config => {
789               file => [
790                   {
791                       alias    => "error_log",
792                       filename => "error.log",
793                       maxlevel => "warning",
794                       minlevel => "emerg",
795                       priority => 1
796                   },
797                   {
798                       alias    => "common_log",
799                       filename => "common.log",
800                       maxlevel => "info",
801                       minlevel => "emerg",
802                       priority => 2
803                   },
804               ],
805               screen => {
806                   alias    => "screen",
807                   maxlevel => "debug",
808                   minlevel => "emerg",
809                   log_to   => "STDERR",
810               },
811           });
812
813       The key "default" is used here to define default parameters for all
814       file outputs. All other keys ("error_log", "common_log") are used as
815       aliases.
816
817       Take a look into the documentation of Log::Handler::Config for more
818       information.
819
820   reload()
821       With the method "reload()" it's possible to reload the logging machine.
822       Just pass the complete new configuration for all outputs, it works
823       exaclty like "config()".
824
825       At first you should know that it's highly recommended to set a alias
826       for each output. If you don't set a alias then the logger doesn't know
827       which output-objects to reload. If a output-objects doesn't have a
828       alias then the objects will be removed and the new configuration will
829       be added.
830
831       Example:
832
833       logger.conf
834
835           <file>
836               alias    = debug
837               filename = debug.log
838               maxlevel = debug
839               minlevel = emerg
840           </file>
841
842           <file>
843               alias    = common
844               filename = common.log
845               maxlevel = info
846               minlevel = emerg
847           </file>
848
849       Load the configuration
850
851           $log->config(config => "logger.conf");
852
853       Now change the configuration in logger.conf
854
855           <file>
856               alias    = common
857               filename = common.log
858               maxlevel = notice
859               minlevel = emerg
860           </file>
861
862           <sendmail>
863               alias   = sendmail
864               from    = bar@foo.example
865               to      = foo@bar.example
866               subject = your subject
867           </sendmail>
868
869       What happends now...
870
871       The file-output with the alias "debug" will be removed, the file-output
872       with the alias "common" will be reloaded and the output with the alias
873       "sendmail" will be added.
874
875       If you don't want that output-objects will be removed because they were
876       added internal, then you can set the option "remove_on_reload" to 0.
877
878       Example:
879
880           $log->config(config => "logger.conf");
881
882           $log->add(
883               forward => {
884                   forward_to => \&my_func,
885                   remove_on_reload => 0,
886               }
887           );
888
889       The forward-output is not removed after a reload.
890
891   validate()
892       The method "validate()" expects the same arguments like "config()" and
893       "reload()".
894
895       Maybe you want to validate your options before you pass them to
896       "config()" or "reload()".
897
898       Example:
899
900           my $log = Log::Handler->new();
901
902           $log->config( config => \%config );
903
904           # and maybe later
905
906           if ( $log->validate( config => \%new_config ) ) {
907               $log->reload( config => \%new_config );
908           } else {
909               warn "unable to reload configuration";
910               warn $log->errstr;
911           }
912
913   set_pattern()
914       With this option you can set your own placeholders. Example:
915
916           $log->set_pattern("%X", "key_name", sub { "value" });
917
918           # or
919
920           $log->set_pattern("%X", "key_name", "value");
921
922       Then you can use this pattern in your message layout:
923
924           $log->add(file => {
925               filename        => "file.log",
926               message_layout  => "%X %m%N",
927           });
928
929       Or use it with "message_pattern":
930
931           sub func {
932               my $m = shift;
933               print "$m->{key_name} $m->{message}\n";
934           }
935
936           $log->add(forward => {
937               forward_to      => \&func,
938               message_pattern => "%X %m",
939           });
940
941       Note: valid character for the key name are: "[%\w\-\.]+"
942
943   set_level()
944       With this method it's possible to change the log level at runtime.
945
946       To change the log level it's necessary to use a alias - see option
947       "alias".
948
949           $log->set_level(
950               $alias => { # option alias
951                   minlevel => $new_minlevel,
952                   maxlevel => $new_maxlevel,
953               }
954           );
955
956   set_default_param()
957       With this methods it's possible to overwrite the default settings for
958       new outputs.
959
960       Normally you would do something like
961
962           $log->add(
963               file => {
964                   filename => "debug.log",
965                   maxlevel => "info",
966                   timeformat => "%b %d %Y %H:%M:%S",
967                   message_layout => "[%T] %L %P %t %m (%C)"
968               }
969           );
970
971           $log->add(
972               file => {
973                   filename => "error.log",
974                   maxlevel => "error",
975                   timeformat => "%b %d %Y %H:%M:%S",
976                   message_layout => "[%T] %L %P %t %m (%C)"
977               }
978           );
979
980       Now you can simplify it with
981
982           $log->set_default_param(
983               timeformat => "%b %d %Y %H:%M:%S",
984               message_layout => "[%T] %L %P %t %m (%C)"
985           );
986
987           $logg->add(
988               file => {
989                   filename => "debug.log",
990                   maxlevel => "info"
991               }
992           );
993
994           $log->add(
995               file => {
996                   filename => "error.log",
997                   maxlevel => "error"
998               }
999           );
1000
1001   create_logger()
1002       "create_logger()" is the same like "new()" but it creates a global
1003       logger.
1004
1005           my $log = Log::Handler->create_logger("myapp");
1006
1007   get_logger()
1008       With "get_logger()" it's possible to get a logger that was created with
1009       "create_logger()" or with
1010
1011           use Log::Handler "myapp";
1012
1013       Just call
1014
1015           my $log = Log::Handler->get_logger("myapp");
1016
1017       If the logger does not exists then a new logger will be created and
1018       returned.
1019
1020   exists_logger()
1021       With "exists_logger()" it's possible to check if a logger exists and it
1022       returns TRUE or FALSE.
1023

EXAMPLES

1025       Log::Handler::Examples
1026

BENCHMARK

1028       The benchmark (examples/benchmark/benchmark.pl) runs on a Intel Core
1029       i7-920 with the following result:
1030
1031           simple pattern output took     :  1 wallclock secs ( 1.26 usr +  0.01 sys =  1.27 CPU) @ 78740.16/s (n=100000)
1032           default pattern output took    :  2 wallclock secs ( 2.08 usr +  0.15 sys =  2.23 CPU) @ 44843.05/s (n=100000)
1033           complex pattern output took    :  4 wallclock secs ( 3.22 usr +  0.23 sys =  3.45 CPU) @ 28985.51/s (n=100000)
1034           message pattern output took    :  3 wallclock secs ( 2.72 usr +  0.16 sys =  2.88 CPU) @ 34722.22/s (n=100000)
1035           suppressed output took         :  0 wallclock secs ( 0.08 usr +  0.00 sys =  0.08 CPU) @ 1250000.00/s (n=100000)
1036           filtered caller output took    :  2 wallclock secs ( 2.10 usr +  0.68 sys =  2.78 CPU) @ 35971.22/s (n=100000)
1037           suppressed caller output took  :  1 wallclock secs ( 0.54 usr +  0.00 sys =  0.54 CPU) @ 185185.19/s (n=100000)
1038           filtered messages output took  :  3 wallclock secs ( 2.62 usr +  0.08 sys =  2.70 CPU) @ 37037.04/s (n=100000)
1039

EXTENSIONS

1041       Send me a mail if you have questions.
1042

PREREQUISITES

1044       Prerequisites for all modules:
1045
1046           Carp
1047           Data::Dumper
1048           Fcntl
1049           Params::Validate
1050           POSIX
1051           Time::HiRes
1052           Sys::Hostname
1053           UNIVERSAL
1054
1055       Recommended modules:
1056
1057           Config::General
1058           Config::Properties
1059           DBI
1060           IO::Socket
1061           Net::SMTP
1062           YAML
1063
1064       Just for the test suite:
1065
1066           File::Spec
1067           Test::More
1068

EXPORTS

1070       No exports.
1071

REPORT BUGS

1073       Please report all bugs to <jschulz.cpan(at)bloonix.de>.
1074

AUTHOR

1076       Jonny Schulz <jschulz.cpan(at)bloonix.de>.
1077

QUESTIONS

1079       Do you have any questions or ideas?
1080
1081       MAIL: <jschulz.cpan(at)bloonix.de>
1082
1083       IRC: irc.perl.org#perl
1084
1085       If you send me a mail then add Log::Handler into the subject.
1086
1088       Copyright (C) 2007-2009 by Jonny Schulz. All rights reserved.
1089
1090       This program is free software; you can redistribute it and/or modify it
1091       under the same terms as Perl itself.
1092
1093
1094
1095perl v5.32.1                      2021-01-27                   Log::Handler(3)
Impressum