line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Dispatch::Log::Syslog::Fast; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
3067
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
104
|
|
4
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
115
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
2080
|
use Log::Dispatch::Output; |
|
2
|
|
|
|
|
20737
|
|
|
2
|
|
|
|
|
59
|
|
9
|
2
|
|
|
2
|
|
2225
|
use parent qw( Log::Dispatch::Output ); |
|
2
|
|
|
|
|
614
|
|
|
2
|
|
|
|
|
11
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
128
|
use Carp qw( croak ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
117
|
|
12
|
2
|
|
|
2
|
|
1783
|
use Log::Syslog::Constants 1.02 qw( :functions :severities ); |
|
2
|
|
|
|
|
3592
|
|
|
2
|
|
|
|
|
505
|
|
13
|
2
|
|
|
2
|
|
1904
|
use Log::Syslog::Fast 0.58 qw( :protos ); |
|
2
|
|
|
|
|
2547
|
|
|
2
|
|
|
|
|
321
|
|
14
|
2
|
|
|
2
|
|
16
|
use Params::Validate qw( validate SCALAR ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
108
|
|
15
|
2
|
|
|
2
|
|
1902
|
use Sys::Hostname (); |
|
2
|
|
|
|
|
69236
|
|
|
2
|
|
|
|
|
1744
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Params::Validate::validation_options( allow_extra => 1 ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
1
|
|
|
1
|
1
|
18
|
my $proto = shift; |
21
|
1
|
|
33
|
|
|
9
|
my $class = ref $proto || $proto; |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
7
|
my %p = @_; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
3
|
my $self = bless {}, $class; |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
11
|
$self->_basic_init(%p); |
28
|
1
|
|
|
|
|
145
|
$self->_init(%p); |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
11
|
return $self; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my ($Ident) = $0 =~ /(.+)/; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _init { |
36
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
10
|
my %p = validate( |
39
|
|
|
|
|
|
|
@_, { |
40
|
|
|
|
|
|
|
transport => { |
41
|
|
|
|
|
|
|
type => SCALAR, |
42
|
|
|
|
|
|
|
default => 'udp', |
43
|
|
|
|
|
|
|
}, |
44
|
|
|
|
|
|
|
host => { |
45
|
|
|
|
|
|
|
type => SCALAR, |
46
|
|
|
|
|
|
|
default => 'localhost', |
47
|
|
|
|
|
|
|
}, |
48
|
|
|
|
|
|
|
port => { |
49
|
|
|
|
|
|
|
type => SCALAR, |
50
|
|
|
|
|
|
|
default => 514, |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
facility => { |
53
|
|
|
|
|
|
|
type => SCALAR, |
54
|
|
|
|
|
|
|
default => 'user' |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
severity => { |
57
|
|
|
|
|
|
|
type => SCALAR, |
58
|
|
|
|
|
|
|
default => 'info' |
59
|
|
|
|
|
|
|
}, |
60
|
|
|
|
|
|
|
sender => { |
61
|
|
|
|
|
|
|
type => SCALAR, |
62
|
|
|
|
|
|
|
default => Sys::Hostname::hostname(), |
63
|
|
|
|
|
|
|
}, |
64
|
|
|
|
|
|
|
name => { |
65
|
|
|
|
|
|
|
type => SCALAR, |
66
|
|
|
|
|
|
|
default => $Ident |
67
|
|
|
|
|
|
|
}, |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
1
|
0
|
|
|
|
88
|
my $transport |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
72
|
|
|
|
|
|
|
= lc $p{transport} eq 'udp' ? LOG_UDP |
73
|
|
|
|
|
|
|
: lc $p{transport} eq 'tcp' ? LOG_TCP |
74
|
|
|
|
|
|
|
: lc $p{transport} eq 'unix' ? LOG_UNIX |
75
|
|
|
|
|
|
|
: undef; |
76
|
1
|
50
|
|
|
|
4
|
croak "unknown facility $p{facility}" unless defined $transport; |
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
6
|
$self->{facility} = get_facility($p{facility}); |
79
|
1
|
50
|
|
|
|
12
|
croak "unknown facility $p{facility}" unless defined $self->{facility}; |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
5
|
$self->{severity} = get_severity($p{severity}); |
82
|
1
|
50
|
|
|
|
8
|
croak "unknown severity $p{severity}" unless defined $self->{severity}; |
83
|
|
|
|
|
|
|
|
84
|
1
|
|
|
|
|
569
|
my $logger = Log::Syslog::Fast->new( |
85
|
|
|
|
|
|
|
$transport, $p{host}, $p{port}, |
86
|
|
|
|
|
|
|
$self->{facility}, $self->{severity}, |
87
|
|
|
|
|
|
|
$p{sender}, $p{name}, |
88
|
|
|
|
|
|
|
); |
89
|
1
|
50
|
|
|
|
16
|
die "failed to create Log::Syslog::Fast" unless $logger; |
90
|
|
|
|
|
|
|
|
91
|
1
|
|
|
|
|
9
|
$self->{logger} = $logger; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# mapping of levels defined in Log::Dispatch to syslog severity |
95
|
|
|
|
|
|
|
my %level2severity = ( |
96
|
|
|
|
|
|
|
0 => LOG_DEBUG, |
97
|
|
|
|
|
|
|
debug => LOG_DEBUG, |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1 => LOG_INFO, |
100
|
|
|
|
|
|
|
info => LOG_INFO, |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
2 => LOG_NOTICE, |
103
|
|
|
|
|
|
|
notice => LOG_NOTICE, |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
3 => LOG_WARNING, |
106
|
|
|
|
|
|
|
warn => LOG_WARNING, |
107
|
|
|
|
|
|
|
warning => LOG_WARNING, |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
4 => LOG_ERR, |
110
|
|
|
|
|
|
|
error => LOG_ERR, |
111
|
|
|
|
|
|
|
err => LOG_ERR, |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
5 => LOG_CRIT, |
114
|
|
|
|
|
|
|
critical => LOG_CRIT, |
115
|
|
|
|
|
|
|
crit => LOG_CRIT, |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
6 => LOG_ALERT, |
118
|
|
|
|
|
|
|
alert => LOG_ALERT, |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
7 => LOG_EMERG, |
121
|
|
|
|
|
|
|
emergency => LOG_EMERG, |
122
|
|
|
|
|
|
|
emerg => LOG_EMERG, |
123
|
|
|
|
|
|
|
); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub log_message { |
126
|
2
|
|
|
2
|
0
|
2582
|
my ($self, %p) = @_; |
127
|
|
|
|
|
|
|
|
128
|
2
|
50
|
|
|
|
12
|
if (defined(my $level = $p{level})) { |
129
|
2
|
50
|
|
|
|
11
|
if (defined(my $severity = $level2severity{lc $level})) { |
130
|
2
|
50
|
|
|
|
6
|
if ($severity != $self->{severity}) { |
131
|
2
|
|
|
|
|
5
|
$self->{severity} = $severity; |
132
|
2
|
|
|
|
|
76
|
$self->{logger}->set_severity($self->{severity}); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
2
|
|
|
|
|
109
|
$self->{logger}->send($p{message}); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# ABSTRACT: Log::Dispatch wrapper around Log::Syslog::Fast |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
__END__ |