CGI-Application-Plugin-LogDispatch
view release on metacpan or search on metacpan
lib/CGI/Application/Plugin/LogDispatch.pm view on Meta::CPAN
525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
warn
"No 'module' name provided -- skipping this logger"
;
}
elsif
(!
$logger
->{module}->
require
) {
# Couldn't load the logger module
# not fatal... just skip this logger
warn
$UNIVERSAL::require::ERROR
;
}
else
{
my
$module
=
delete
$logger
->{module};
# setup a callback to append a newline if requested
if
(
$logger
->{append_newline} ||
$options
->{APPEND_NEWLINE}) {
delete
$logger
->{append_newline}
if
exists
$logger
->{append_newline};
$logger
->{callbacks} = [
$logger
->{callbacks} ]
if
$logger
->{callbacks} &&
ref
$logger
->{callbacks} ne
'ARRAY'
;
push
@{
$logger
->{callbacks} }, \
&_append_newline
;
}
# add the logger to the dispatcher
$log
->add(
$module
->new(
%$logger
) );
}
}
}
else
{
# create a simple STDERR logger
my
%options
= (
name
=>
'screen'
,
stderr
=> 1,
min_level
=>
'debug'
,
);
$options
{callbacks} = \
&_append_newline
if
$options
->{APPEND_NEWLINE};
$log
->add( Log::Dispatch::Screen->new(
%options
) );
}
_set_object(
$frompkg
||
$self
,
$log
);
# CAP::DevPopup support
if
(UNIVERSAL::can(
$self
,
'devpopup'
)) {
# Register our report with DevPopup
$self
->add_callback(
'devpopup_report'
, \
&_devpopup_report
);
# Create logger to capture all log entries
my
%options
= (
'name'
=>
'DevPopup'
,
'min_level'
=>
'debug'
,
'filename'
=> File::Spec->devnull(),
'callbacks'
=>
sub
{
my
%args
=
@_
;
push
( @{
$self
->{LOG_DISPATCH_DEVPOPUP_HISTORY}}, [
$args
{level},
$args
{message}] );
},
);
$log
->add( Log::Dispatch::File->new(
%options
) );
}
}
return
$log
;
}
lib/CGI/Application/Plugin/LogDispatch.pm view on Meta::CPAN
365366367368369370371372373374375376377378379380381382383384385=over 4
=item LOG_DISPATCH_OPTIONS
This allows you to customize how the L<Log::Dispatch> object is created by providing a hash of
options that will be passed to the L<Log::Dispatch> constructor. Please see the documentation
for L<Log::Dispatch> for the exact syntax of the parameters. Surprisingly enough you will usually
not need to use this option, instead look at the LOG_DISPATCH_MODULES option.
LOG_DISPATCH_OPTIONS => {
callbacks => sub { my %h = @_; return time().': '.$h{message}; },
}
=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
t/TestAppNewline.pm view on Meta::CPAN
789101112131415161718192021222324252627use
DummyIOHandle;
@TestAppNewline::ISA
=
qw(CGI::Application)
;
sub
cgiapp_init {
my
$self
=
shift
;
$self
->{__LOG_MESSAGES}->{HANDLE} = new DummyIOHandle;
$self
->{__LOG_MESSAGES}->{HANDLE_APPEND} = new DummyIOHandle;
$self
->log_config(
# LOG_DISPATCH_OPTIONS => {
# callbacks => sub { my %h = @_; chomp $h{message}; return $h{message}.$/; },
# },
LOG_DISPATCH_MODULES
=> [
{
module
=>
'Log::Dispatch::Handle'
,
name
=>
'handle'
,
min_level
=>
'debug'
,
handle
=>
$self
->{__LOG_MESSAGES}->{HANDLE},
},
{
module
=>
'Log::Dispatch::Handle'
,
t/TestAppOptions.pm view on Meta::CPAN
67891011121314151617181920212223242526use
DummyIOHandle;
@TestAppOptions::ISA
=
qw(CGI::Application)
;
sub
cgiapp_init {
my
$self
=
shift
;
$self
->{__LOG_MESSAGES}->{HANDLE} = new DummyIOHandle;
$self
->log_config(
LOG_DISPATCH_OPTIONS
=> {
callbacks
=>
sub
{
my
%h
=
@_
;
chomp
$h
{message};
return
$h
{message}.
'EXTRA'
; },
},
LOG_DISPATCH_MODULES
=> [
{
module
=>
'Log::Dispatch::Handle'
,
name
=>
'handle'
,
min_level
=>
'debug'
,
handle
=>
$self
->{__LOG_MESSAGES}->{HANDLE},
},
],
);
t/TestAppSingleton.pm view on Meta::CPAN
353637383940414243444546474849505152535455package
TestAppSingleton::Sub;
use
strict;
use
DummyIOHandle;
BEGIN {
$HANDLE
= new DummyIOHandle; };
use
CGI::Application;
LOG_DISPATCH_OPTIONS
=> {
callbacks
=>
sub
{
my
%h
=
@_
;
chomp
$h
{message};
return
$h
{message}.
'EXTRA'
; },
},
LOG_DISPATCH_MODULES
=> [
{
module
=>
'Log::Dispatch::Handle'
,
name
=>
'handle'
,
min_level
=>
'info'
,
handle
=>
$HANDLE
,
},
],
);
( run in 0.268 second using v1.01-cache-2.11-cpan-05444aca049 )