/usr/share/perl5/Log/Dispatch/Perl.pm is in liblog-dispatch-perl-perl 0.04-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | package Log::Dispatch::Perl;
use base 'Log::Dispatch::Output';
$VERSION= '0.04';
# be as strict and verbose as possible
use strict;
use warnings;
# initialize level name / number conversion hashes
my %LEVEL2NUM;
my %NUM2LEVEL;
do {
my @level2num= (
debug => 0,
info => 1,
notice => 2,
warning => 3,
error => 4,
err => 4, # MUST be after "error"
critical => 5,
crit => 5, # MUST be after "critical"
alert => 6,
emergency => 7,
emerg => 7, # MUST be after "emergency"
);
%LEVEL2NUM= @level2num;
%NUM2LEVEL= reverse @level2num; # order fixes double assignments
};
# hide ourselves from Carp
my $havecarp= defined $Carp::VERSION;
unless ( $] < 5.008 ) {
$Carp::Internal{$_}= 1 foreach ( 'Log::Dispatch', 'Log::Dispatch::Output' );
}
# action to actual code hash
my %ACTION2CODE;
%ACTION2CODE= (
'' => sub { undef },
carp => $havecarp
? \&Carp::carp
: sub {
$havecarp ||= require Carp;
$ACTION2CODE{carp}= \&Carp::carp;
goto &Carp::carp;
},
cluck => $] < 5.008
? sub {
$havecarp ||= require Carp;
( my $m= Carp::longmess() )
=~ s#\s+Log::Dispatch::[^\n]+\n##sg;
return CORE::warn $_[0] . $m;
}
: sub {
$havecarp ||= require Carp;
return CORE::warn $_[0] . Carp::longmess();
},
confess => $] < 5.008
? sub {
$havecarp ||= require Carp;
( my $m = Carp::longmess() )
=~ s#\s+Log::Dispatch::[^\n]+\n##sg;
return CORE::die $_[0] . $m;
}
: sub {
$havecarp ||= require Carp;
return CORE::die $_[0] . Carp::longmess();
},
croak => $havecarp
? \&Carp::croak
: sub {
$havecarp ||= require Carp;
$ACTION2CODE{croak}= \&Carp::croak;
goto &Carp::croak;
},
die => sub { CORE::die @_ },
warn => sub { CORE::warn @_ },
);
# satisfy require
1;
#-------------------------------------------------------------------------------
#
# Class methods
#
#-------------------------------------------------------------------------------
# new
#
# Required by Log::Dispatch::Output. Creates a new Log::Dispatch::Perl
# object
#
# IN: 1 class
# 2..N parameters as a hash
# OUT: 1 instantiated object
sub new {
my ( $class, %param )= @_;
# do the basic initializations
my $self= bless {}, ref $class || $class;
$self->_basic_init( %param );
# we have specific actions specified
my @action;
if ( my $actions= $param{action} ) {
# check all actions specified
foreach my $level ( keys %{$actions} ) {
my $action= $actions->{$level};
$level= $NUM2LEVEL{$level} if exists $NUM2LEVEL{$level};
# sanity check, store if ok
my $warn;
warn qq{"$level" is an unknown logging level, ignored\n"}, $warn++
if !exists $LEVEL2NUM{ $level || '' };
warn qq{"$action" is an unknown Perl action, ignored\n"}, $warn++
if !exists $ACTION2CODE{$action};
$action[$LEVEL2NUM{$level}]= $ACTION2CODE{$action}
if !$warn;
}
}
# set the actions that have not yet been specified
$action[0] ||= $ACTION2CODE{''};
$action[1] ||= $ACTION2CODE{''};
$action[2] ||= $ACTION2CODE{warn};
$action[3] ||= $ACTION2CODE{warn};
$action[4] ||= $ACTION2CODE{die};
$action[5] ||= $ACTION2CODE{die};
$action[6] ||= $ACTION2CODE{confess};
$action[7] ||= $ACTION2CODE{confess};
# save this setting
$self->{action}= \@action;
return $self;
} #new
#-------------------------------------------------------------------------------
#
# Instance methods
#
#-------------------------------------------------------------------------------
# log_message
#
# Required by Log::Dispatch. Log a single message.
#
# IN: 1 instantiated Log::Dispatch::Perl object
# 2..N hash with parameters as required by Log::Dispatch
sub log_message {
my ( $self, %param )= @_;
# huh?
my $level= $param{level};
return if !exists $LEVEL2NUM{$level} and !exists $NUM2LEVEL{$level};
# obtain level number
my $num= $LEVEL2NUM{$level};
$num= $level if !defined $num; # //=
# set message
my $message= $param{message};
$message .= "\n" if substr( $message, -1, 1 ) ne "\n";
@_= ($message);
# log it the right way
goto &{$self->{action}->[$num]};
} #log_message
#-------------------------------------------------------------------------------
__END__
=head1 NAME
Log::Dispatch::Perl - Use core Perl functions for logging
=head1 SYNOPSIS
use Log::Dispatch::Perl ();
my $dispatcher = Log::Dispatch->new;
$dispatcher->add( Log::Dispatch::Perl->new(
name => 'foo',
min_level => 'info',
action => { debug => '',
info => '',
notice => 'warn',
warning => 'warn',
error => 'die',
critical => 'die',
alert => 'croak',
emergency => 'croak',
},
) );
$dispatcher->warning( "This is a warning" );
=head1 VERSION
This documentation describes version 0.04.
=head1 DESCRIPTION
The "Log::Dispatch::Perl" module offers a logging alternative using standard
Perl core functions. It allows you to fall back to the common Perl
alternatives for logging, such as "warn" and "cluck". It also adds the
possibility for a logging action to halt the current environment, such as
with "die" and "croak".
=head1 POSSIBLE ACTIONS
The following actions are currently supported (in alphabetical order):
=head2 (absent or empty string or undef)
Indicates no action should be executed. Default for log levels "debug" and
"info".
=head2 carp
Indicates a "carp" action should be executed. See L<Carp/"carp">. Halts
execution.
=head2 cluck
Indicates a "cluck" action should be executed. See L<Carp/"cluck">. Does
B<not> halt execution.
=head2 confess
Indicates a "confess" action should be executed. See L<Carp/"confess">. Halts
execution.
=head2 croak
Indicates a "croak" action should be executed. See L<Carp/"croak">. Halts
execution.
=head2 die
Indicates a "die" action should be executed. See L<perlfunc/"die">. Halts
execution.
=head2 warn
Indicates a "warn" action should be executed. See L<perlfunc/"warn">. Does
B<not> halt execution.
=head1 REQUIRED MODULES
Log::Dispatch (1.16)
=head1 AUTHOR
Elizabeth Mattijsen, <liz@dijkmat.nl>.
Please report bugs to <perlbugs@dijkmat.nl>.
=head1 COPYRIGHT
Copyright (c) 2004, 2012 Elizabeth Mattijsen <liz@dijkmat.nl>. All rights
reserved. This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
|