CGI-Application-Plugin-LogDispatch
view release on metacpan or search on metacpan
lib/CGI/Application/Plugin/LogDispatch.pm view on Meta::CPAN
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
=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
use 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
use CGI::Application::Plugin::LogDispatch;
use 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
package TestAppSingleton::Sub;
use strict;
use vars qw($HANDLE);
use DummyIOHandle;
BEGIN { $HANDLE = new DummyIOHandle; };
use CGI::Application;
use CGI::Application::Plugin::LogDispatch (
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.277 second using v1.01-cache-2.11-cpan-2b0bae70ee8 )