.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "CGI::Application::Plugin::LogDispatch 3pm" .TH CGI::Application::Plugin::LogDispatch 3pm "2022-06-09" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" CGI::Application::Plugin::LogDispatch \- Add Log::Dispatch support to CGI::Application .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& package My::App; \& \& use CGI::Application::Plugin::LogDispatch; \& \& sub cgiapp_init { \& my $self = shift; \& \& # calling log_config is optional as \& # some simple defaults will be used \& $self\->log_config( \& LOG_DISPATCH_MODULES => [ \& { module => \*(AqLog::Dispatch::File\*(Aq, \& name => \*(Aqdebug\*(Aq, \& filename => \*(Aq/tmp/debug.log\*(Aq, \& min_level => \*(Aqdebug\*(Aq, \& }, \& ] \& ); \& } \& \& sub myrunmode { \& my $self = shift; \& \& $self\->log\->info(\*(AqInformation message\*(Aq); \& $self\->log\->debug(\*(AqDebug message\*(Aq); \& } \& \& \- or as a class based singleton \- \& \& package My::App; \& \& use CGI::Application::Plugin::LogDispatch ( \& LOG_DISPATCH_MODULES => [ \& { module => \*(AqLog::Dispatch::File\*(Aq, \& name => \*(Aqdebug\*(Aq, \& filename => \*(Aq/tmp/debug.log\*(Aq, \& min_level => \*(Aqdebug\*(Aq, \& }, \& ] \& ); \& \& My::App\->log\->info(\*(AqInformation message\*(Aq); \& \& sub myrunmode { \& my $self = shift; \& \& $self\->log\->info(\*(AqThis also works\*(Aq); \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" CGI::Application::Plugin::LogDispatch adds logging support to your CGI::Application modules by providing a Log::Dispatch dispatcher object that is accessible from anywhere in the application. .PP If you have CGI::Application::Plugin::DevPopup installed, a \*(L"Log Entries\*(R" report is added to the popup window, containing all of the entries that were logged during the execution of the runmode. .SH "METHODS" .IX Header "METHODS" .SS "log" .IX Subsection "log" This method will return the current Log::Dispatch dispatcher object. The Log::Dispatch object is created on the first call to this method, and any subsequent calls will return the same object. This effectively creates a singleton log dispatcher for the duration of the request. If \f(CW\*(C`log_config\*(C'\fR has not been called before the first call to \f(CW\*(C`log\*(C'\fR, then it will choose some sane defaults to create the dispatcher object (the exact default values are defined below). .PP .Vb 4 \& # retrieve the log object \& my $log = $self\->log; \& $log\->warning("something\*(Aqs not right!"); \& $log\->emergency("It\*(Aqs all gone pear shaped!"); \& \& \- or \- \& \& # use the log object directly \& $self\->log\->debug(Data::Dumper::Dumper(\e%hash)); \& \& \- or \- \& \& # if you configured it as a singleton \& My::App\->log\->debug(\*(AqThis works too\*(Aq); .Ve .SS "log_config" .IX Subsection "log_config" This method can be used to customize the functionality of the CGI::Application::Plugin::LogDispatch module. Calling this method does not mean that a new Log::Dispatch object will be immediately created. The log object will not be created until the first call to \f(CW$self\fR\->log. .PP The recommended place to call \f(CW\*(C`log_config\*(C'\fR is in the \f(CW\*(C`cgiapp_init\*(C'\fR stage of CGI::Application. If this method is called after the log object has already been accessed, then it will die with an error message. .PP If this method is not called at all then a reasonable set of defaults will be used (the exact default values are defined below). .PP The following parameters are accepted: .IP "\s-1LOG_DISPATCH_OPTIONS\s0" 4 .IX Item "LOG_DISPATCH_OPTIONS" This allows you to customize how the Log::Dispatch object is created by providing a hash of options that will be passed to the Log::Dispatch constructor. Please see the documentation for Log::Dispatch for the exact syntax of the parameters. Surprisingly enough you will usually not need to use this option, instead look at the \s-1LOG_DISPATCH_MODULES\s0 option. .Sp .Vb 3 \& LOG_DISPATCH_OPTIONS => { \& callbacks => sub { my %h = @_; return time().\*(Aq: \*(Aq.$h{message}; }, \& } .Ve .IP "\s-1LOG_DISPATCH_MODULES\s0" 4 .IX Item "LOG_DISPATCH_MODULES" This option allows you to specify the Log::Dispatch::* modules that you wish to use to log messages. You can list multiple dispatch modules, each with their own set of options. Format the options in an array of hashes, where each hash contains the options for the Log::Dispatch:: module you are configuring and also include a 'module' parameter containing the name of the dispatch module. See below for an example. You can also add an 'append_newline' option to automatically append a newline to each log entry for this dispatch module (this option is not needed if you already specified the \s-1APPEND_NEWLINE\s0 option listed below which will add a newline for all dispatch modules). .Sp .Vb 10 \& LOG_DISPATCH_MODULES => [ \& { module => \*(AqLog::Dispatch::File\*(Aq, \& name => \*(Aqmessages\*(Aq, \& filename => \*(Aq/tmp/messages.log\*(Aq, \& min_level => \*(Aqinfo\*(Aq, \& append_newline => 1 \& }, \& { module => \*(AqLog::Dispatch::Email::MailSend\*(Aq, \& name => \*(Aqemail\*(Aq, \& to => [ qw(foo@bar.com bar@baz.org ) ], \& subject => \*(AqOh No!!!!!!!!!!\*(Aq, \& min_level => \*(Aqemerg\*(Aq \& } \& ] .Ve .IP "\s-1APPEND_NEWLINE\s0" 4 .IX Item "APPEND_NEWLINE" By default Log::Dispatch does not append a newline to the end of the log messages. By setting this option to a true value, a newline character will automatically be added to the end of the log message. .Sp .Vb 1 \& APPEND_NEWLINE => 1 .Ve .IP "\s-1LOG_METHOD_EXECUTION\s0 (\s-1EXPERIMENTAL\s0)" 4 .IX Item "LOG_METHOD_EXECUTION (EXPERIMENTAL)" This option will allow you to log the execution path of your program. Set \s-1LOG_METHOD_EXECUTION\s0 to a list of all the modules you want to be logged. This will automatically send a debug message at the start and end of each method/function that is called in the modules you listed. The parameters passed, and the return value will also be logged. This can be useful by tracing the program flow in the logfile without having to resort to the debugger. .Sp .Vb 1 \& LOG_METHOD_EXECUTION => [qw(_\|_PACKAGE_\|_ CGI::Application CGI)], .Ve .Sp \&\s-1WARNING:\s0 This hasn't been heavily tested, although it seems to work fine for me. Also, a closure is created around the log object, so some care may need to be taken when using this in a persistent environment like mod_perl. This feature depends on the Sub::WrapPackages module. .SS "\s-1DEFAULT OPTIONS\s0" .IX Subsection "DEFAULT OPTIONS" The following example shows what options are set by default (ie this is what you would get if you do not call log_config). A single Log::Dispatch::Screen module that writes error messages to \s-1STDERR\s0 with a minimum log level of debug. .PP .Vb 10 \& $self\->log_config( \& LOG_DISPATCH_MODULES => [ \& { module => \*(AqLog::Dispatch::Screen\*(Aq, \& name => \*(Aqscreen\*(Aq, \& stderr => 1, \& min_level => \*(Aqdebug\*(Aq, \& append_newline => 1 \& } \& ], \& ); .Ve .PP Here is a more customized example that uses two file appenders, and an email gateway. Here all debug messages are sent to /tmp/debug.log, and all messages above are sent to /tmp/messages.log. Also, any emergency messages are emailed to foo@bar.com and bar@baz.org. .PP .Vb 10 \& $self\->log_config( \& LOG_DISPATCH_MODULES => [ \& { module => \*(AqLog::Dispatch::File\*(Aq, \& name => \*(Aqdebug\*(Aq, \& filename => \*(Aq/tmp/debug.log\*(Aq, \& min_level => \*(Aqdebug\*(Aq, \& max_level => \*(Aqdebug\*(Aq \& }, \& { module => \*(AqLog::Dispatch::File\*(Aq, \& name => \*(Aqmessages\*(Aq, \& filename => \*(Aq/tmp/messages.log\*(Aq, \& min_level => \*(Aqinfo\*(Aq \& }, \& { module => \*(AqLog::Dispatch::Email::MailSend\*(Aq, \& name => \*(Aqemail\*(Aq, \& to => [ qw(foo@bar.com bar@baz.org ) ], \& subject => \*(AqOh No!!!!!!!!!!\*(Aq, \& min_level => \*(Aqemerg\*(Aq \& } \& ], \& APPEND_NEWLINE => 1, \& ); .Ve .SH "EXAMPLE" .IX Header "EXAMPLE" In a CGI::Application module: .PP .Vb 3 \& # configure the log modules once during the init stage \& sub cgiapp_init { \& my $self = shift; \& \& # Configure the session \& $self\->log_config( \& LOG_DISPATCH_MODULES => [ \& { module => \*(AqLog::Dispatch::File\*(Aq, \& name => \*(Aqmessages\*(Aq, \& filename => \*(Aq/tmp/messages.log\*(Aq, \& min_level => \*(Aqerror\*(Aq \& }, \& { module => \*(AqLog::Dispatch::Email::MailSend\*(Aq, \& name => \*(Aqemail\*(Aq, \& to => [ qw(foo@bar.com bar@baz.org ) ], \& subject => \*(AqOh No!!!!!!!!!!\*(Aq, \& min_level => \*(Aqemerg\*(Aq \& } \& ], \& APPEND_NEWLINE => 1, \& ); \& \& } \& \& sub cgiapp_prerun { \& my $self = shift; \& \& $self\->log\->debug("Current runmode: ".$self\->get_current_runmode); \& } \& \& sub my_runmode { \& my $self = shift; \& my $log = $self\->log; \& \& if ($ENV{\*(AqREMOTE_USER\*(Aq}) { \& $log\->info("user ".$ENV{\*(AqREMOTE_USER\*(Aq}); \& } \& \& # etc... \& } .Ve .SH "SINGLETON SUPPORT" .IX Header "SINGLETON SUPPORT" This module can be used as a singleton object. This means that when the object is created, it will remain accessible for the duration of the process. This can be useful in persistent environments like mod_perl and PersistentPerl, since the object only has to be created one time, and will remain in memory across multiple requests. It can also be useful if you want to setup a \s-1DIE\s0 handler, or \s-1WARN\s0 handler, since you will not have access to the \f(CW$self\fR object. .PP To use this module as a singleton you need to provide all configuration parameters as options to the use statement. The use statement will accept all the same parameters that the log_config method accepts, so see the documentation above for more details. .PP When creating the singleton, the log object will be saved in the namespace of the module that created it. The singleton will also be inherited by any subclasses of this module. .PP \&\s-1NOTE:\s0 Singleton support requires the Class::ISA module which is not installed automatically by this module. .SH "SINGLETON EXAMPLE" .IX Header "SINGLETON EXAMPLE" .Vb 1 \& package My::App; \& \& use base qw(CGI::Application); \& use CGI::Application::Plugin::LogDispatch( \& LOG_DISPATCH_MODULES => [ \& { module => \*(AqLog::Dispatch::File\*(Aq, \& name => \*(Aqmessages\*(Aq, \& filename => \*(Aq/tmp/messages.log\*(Aq, \& min_level => \*(Aqerror\*(Aq \& }, \& ], \& APPEND_NEWLINE => 1, \& ); \& \& } \& \& sub cgiapp_prerun { \& my $self = shift; \& \& $self\->log\->debug("Current runmode: ".$self\->get_current_runmode); \& } \& \& sub my_runmode { \& my $self = shift; \& my $log = $self\->log; \& \& if ($ENV{\*(AqREMOTE_USER\*(Aq}) { \& $log\->info("user ".$ENV{\*(AqREMOTE_USER\*(Aq}); \& } \& \& # etc... \& } \& \& package My::App::Subclass; \& \& use base qw(My::App); \& \& # Setup a die handler that uses the logger \& $SIG{_\|_DIE_\|_} = sub { My::App::Subclass\->log\->emerg(@_); CORE::die(@_); }; \& \& sub my_other_runmode { \& my $self = shift; \& \& $self\->log\->info("This will log to the logger configured in My::App"); \& } .Ve .SH "BUGS" .IX Header "BUGS" Please report any bugs or feature requests to \&\f(CW\*(C`bug\-cgi\-application\-plugin\-logdispatch@rt.cpan.org\*(C'\fR, or through the web interface at . I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. .SH "SEE ALSO" .IX Header "SEE ALSO" CGI::Application, Log::Dispatch, Log::Dispatch::Screen, Sub::WrapPackages, \fBperl\fR\|(1) .SH "AUTHOR" .IX Header "AUTHOR" Cees Hek .SH "LICENSE" .IX Header "LICENSE" Copyright (C) 2004 Cees Hek .PP This library is free software. You can modify and or distribute it under the same terms as Perl itself.