line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Syslog::Fast::PP; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
13504
|
use 5.006002; |
|
8
|
|
|
|
|
23
|
|
|
8
|
|
|
|
|
230
|
|
4
|
8
|
|
|
8
|
|
28
|
use strict; |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
167
|
|
5
|
8
|
|
|
8
|
|
25
|
use warnings; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
166
|
|
6
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
2312
|
use Log::Syslog::Fast::Constants ':all'; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
2782
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
our @EXPORT = qw(); |
11
|
|
|
|
|
|
|
our %EXPORT_TAGS = %Log::Syslog::Fast::Constants::EXPORT_TAGS; |
12
|
|
|
|
|
|
|
our @EXPORT_OK = @Log::Syslog::Fast::Constants::EXPORT_OK; |
13
|
|
|
|
|
|
|
|
14
|
8
|
|
|
8
|
|
38
|
use Carp; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
441
|
|
15
|
8
|
|
|
8
|
|
3983
|
use POSIX 'strftime'; |
|
8
|
|
|
|
|
37669
|
|
|
8
|
|
|
|
|
46
|
|
16
|
8
|
|
|
8
|
|
12296
|
use IO::Socket::IP; |
|
8
|
|
|
|
|
225971
|
|
|
8
|
|
|
|
|
59
|
|
17
|
8
|
|
|
8
|
|
4689
|
use IO::Socket::UNIX; |
|
8
|
|
|
|
|
23
|
|
|
8
|
|
|
|
|
68
|
|
18
|
8
|
|
|
8
|
|
7140
|
use Socket; |
|
8
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
5170
|
|
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
0
|
|
0
|
sub DESTROY { } |
21
|
|
|
|
|
|
|
|
22
|
8
|
|
|
8
|
|
48
|
use constant PRIORITY => 0; |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
532
|
|
23
|
8
|
|
|
8
|
|
40
|
use constant SENDER => 1; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
338
|
|
24
|
8
|
|
|
8
|
|
37
|
use constant NAME => 2; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
325
|
|
25
|
8
|
|
|
8
|
|
36
|
use constant PID => 3; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
346
|
|
26
|
8
|
|
|
8
|
|
31
|
use constant SOCK => 4; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
306
|
|
27
|
8
|
|
|
8
|
|
35
|
use constant LAST_TIME => 5; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
318
|
|
28
|
8
|
|
|
8
|
|
36
|
use constant PREFIX => 6; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
429
|
|
29
|
8
|
|
|
8
|
|
37
|
use constant PREFIX_LEN => 7; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
321
|
|
30
|
8
|
|
|
8
|
|
30
|
use constant FORMAT => 8; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
10549
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub new { |
33
|
34
|
|
|
34
|
0
|
649142
|
my $ref = shift; |
34
|
34
|
100
|
|
|
|
118
|
$ref = __PACKAGE__ unless defined $ref; |
35
|
34
|
|
33
|
|
|
163
|
my $class = ref $ref || $ref; |
36
|
|
|
|
|
|
|
|
37
|
34
|
|
|
|
|
64
|
my ($proto, $hostname, $port, $facility, $severity, $sender, $name) = @_; |
38
|
|
|
|
|
|
|
|
39
|
34
|
100
|
|
|
|
275
|
croak "hostname required" unless defined $hostname; |
40
|
33
|
100
|
|
|
|
184
|
croak "sender required" unless defined $sender; |
41
|
32
|
100
|
|
|
|
168
|
croak "name required" unless defined $name; |
42
|
|
|
|
|
|
|
|
43
|
31
|
|
|
|
|
157
|
my $self = bless [ |
44
|
|
|
|
|
|
|
($facility << 3) | $severity, # prio |
45
|
|
|
|
|
|
|
$sender, # sender |
46
|
|
|
|
|
|
|
$name, # name |
47
|
|
|
|
|
|
|
$$, # pid |
48
|
|
|
|
|
|
|
undef, # sock |
49
|
|
|
|
|
|
|
undef, # last_time |
50
|
|
|
|
|
|
|
undef, # prefix |
51
|
|
|
|
|
|
|
undef, # prefix_len |
52
|
|
|
|
|
|
|
LOG_RFC3164, # format |
53
|
|
|
|
|
|
|
], $class; |
54
|
|
|
|
|
|
|
|
55
|
31
|
|
|
|
|
121
|
$self->update_prefix(time()); |
56
|
|
|
|
|
|
|
|
57
|
31
|
|
|
|
|
57
|
eval { $self->set_receiver($proto, $hostname, $port) }; |
|
31
|
|
|
|
|
99
|
|
58
|
31
|
100
|
|
|
|
166
|
die "Error in ->new: $@" if $@; |
59
|
22
|
|
|
|
|
77
|
return $self; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub update_prefix { |
63
|
73
|
|
|
73
|
0
|
87
|
my $self = shift; |
64
|
73
|
|
|
|
|
86
|
my $t = shift; |
65
|
|
|
|
|
|
|
|
66
|
73
|
|
|
|
|
125
|
$self->[LAST_TIME] = $t; |
67
|
|
|
|
|
|
|
|
68
|
73
|
|
|
|
|
3015
|
my $timestr = strftime("%h %e %T", localtime $t); |
69
|
73
|
100
|
|
|
|
257
|
if ($self->[FORMAT] == LOG_RFC5424) { |
70
|
4
|
|
|
|
|
100
|
$timestr = strftime("%Y-%m-%dT%H:%M:%S%z", localtime $t); |
71
|
4
|
|
|
|
|
40
|
$timestr =~ s/(\d{2})$/:$1/; # see http://tools.ietf.org/html/rfc3339#section-5.6 time-numoffset |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
73
|
|
|
|
|
363
|
$self->[PREFIX] = sprintf "<%d>%s %s %s[%d]: ", |
75
|
|
|
|
|
|
|
$self->[PRIORITY], $timestr, $self->[SENDER], $self->[NAME], $self->[PID]; |
76
|
73
|
100
|
|
|
|
253
|
if ($self->[FORMAT] == LOG_RFC5424) { |
77
|
4
|
|
|
|
|
25
|
$self->[PREFIX] = sprintf "<%d>1 %s %s %s %d - - ", |
78
|
|
|
|
|
|
|
$self->[PRIORITY], $timestr, $self->[SENDER], $self->[NAME], $self->[PID]; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub set_receiver { |
83
|
140
|
|
|
140
|
0
|
10908
|
my $self = shift; |
84
|
140
|
100
|
|
|
|
337
|
croak("hostname required") unless defined $_[1]; |
85
|
|
|
|
|
|
|
|
86
|
139
|
|
|
|
|
158
|
my ($proto, $hostname, $port) = @_; |
87
|
|
|
|
|
|
|
|
88
|
139
|
100
|
|
|
|
270
|
if ($proto == LOG_TCP) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
89
|
109
|
|
|
|
|
384
|
$self->[SOCK] = IO::Socket::IP->new( |
90
|
|
|
|
|
|
|
Proto => 'tcp', |
91
|
|
|
|
|
|
|
PeerHost => $hostname, |
92
|
|
|
|
|
|
|
PeerPort => $port, |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
elsif ($proto == LOG_UDP) { |
96
|
12
|
|
|
|
|
86
|
$self->[SOCK] = IO::Socket::IP->new( |
97
|
|
|
|
|
|
|
Proto => 'udp', |
98
|
|
|
|
|
|
|
PeerHost => $hostname, |
99
|
|
|
|
|
|
|
PeerPort => $port, |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
elsif ($proto == LOG_UNIX) { |
103
|
18
|
|
|
|
|
22
|
eval { |
104
|
18
|
|
|
|
|
112
|
$self->[SOCK] = IO::Socket::UNIX->new( |
105
|
|
|
|
|
|
|
Type => SOCK_STREAM, |
106
|
|
|
|
|
|
|
Peer => $hostname, |
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
}; |
109
|
18
|
100
|
66
|
|
|
3390
|
if ($@ || !$self->[SOCK]) { |
110
|
12
|
|
|
|
|
68
|
$self->[SOCK] = IO::Socket::UNIX->new( |
111
|
|
|
|
|
|
|
Type => SOCK_DGRAM, |
112
|
|
|
|
|
|
|
Peer => $hostname, |
113
|
|
|
|
|
|
|
); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
139
|
100
|
|
|
|
47123
|
die "Error in ->set_receiver: $!" unless $self->[SOCK]; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub set_priority { |
121
|
11
|
|
|
11
|
0
|
2881
|
my $self = shift; |
122
|
11
|
|
|
|
|
25
|
my ($facility, $severity) = @_; |
123
|
11
|
|
|
|
|
31
|
$self->[PRIORITY] = ($facility << 3) | $severity; |
124
|
11
|
|
|
|
|
31
|
$self->update_prefix(time); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub set_facility { |
128
|
1
|
|
|
1
|
0
|
8
|
my $self = shift; |
129
|
1
|
|
|
|
|
3
|
$self->set_priority(shift, $self->get_severity); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub set_severity { |
133
|
1
|
|
|
1
|
0
|
257
|
my $self = shift; |
134
|
1
|
|
|
|
|
3
|
$self->set_priority($self->get_facility, shift); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub set_sender { |
138
|
10
|
|
|
10
|
0
|
3006
|
my $self = shift; |
139
|
10
|
100
|
|
|
|
147
|
croak("sender required") unless defined $_[0]; |
140
|
9
|
|
|
|
|
17
|
$self->[SENDER] = shift; |
141
|
9
|
|
|
|
|
26
|
$self->update_prefix(time); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub set_name { |
145
|
10
|
|
|
10
|
0
|
3104
|
my $self = shift; |
146
|
10
|
100
|
|
|
|
128
|
croak("name required") unless defined $_[0]; |
147
|
9
|
|
|
|
|
23
|
$self->[NAME] = shift; |
148
|
9
|
|
|
|
|
23
|
$self->update_prefix(time); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub set_pid { |
152
|
9
|
|
|
9
|
0
|
2866
|
my $self = shift; |
153
|
9
|
|
|
|
|
20
|
$self->[PID] = shift; |
154
|
9
|
|
|
|
|
25
|
$self->update_prefix(time); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub set_format { |
158
|
4
|
|
|
4
|
0
|
1325
|
my $self = shift; |
159
|
4
|
|
|
|
|
10
|
$self->[FORMAT] = shift; |
160
|
4
|
|
|
|
|
11
|
$self->update_prefix(time); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub send { |
164
|
25
|
|
66
|
25
|
0
|
20449
|
my $now = $_[2] || time; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# update the prefix if seconds have rolled over |
167
|
25
|
50
|
|
|
|
78
|
if ($now != $_[0][LAST_TIME]) { |
168
|
0
|
|
|
|
|
0
|
$_[0]->update_prefix($now); |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
25
|
100
|
|
|
|
836
|
send($_[0][SOCK], $_[0][PREFIX] . $_[1], 0) || die "Error while sending: $!"; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
#no warnings 'redefine'; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub get_priority { |
177
|
3
|
|
|
3
|
0
|
256
|
my $self = shift; |
178
|
3
|
|
|
|
|
15
|
return $self->[PRIORITY]; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub get_facility { |
182
|
3
|
|
|
3
|
0
|
256
|
my $self = shift; |
183
|
3
|
|
|
|
|
11
|
return $self->[PRIORITY] >> 3; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub get_severity { |
187
|
3
|
|
|
3
|
0
|
4
|
my $self = shift; |
188
|
3
|
|
|
|
|
11
|
return $self->[PRIORITY] & 7; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub get_sender { |
192
|
2
|
|
|
2
|
0
|
3
|
my $self = shift; |
193
|
2
|
|
|
|
|
7
|
return $self->[SENDER]; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub get_name { |
197
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
198
|
2
|
|
|
|
|
7
|
return $self->[NAME]; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub get_pid { |
202
|
2
|
|
|
2
|
0
|
3
|
my $self = shift; |
203
|
2
|
|
|
|
|
7
|
return $self->[PID]; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub get_format { |
207
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
208
|
0
|
|
|
|
|
0
|
return $self->[FORMAT]; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub _get_sock { |
212
|
2
|
|
|
2
|
|
124
|
my $self = shift; |
213
|
2
|
|
|
|
|
6
|
return $self->[SOCK]->fileno; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
1; |
217
|
|
|
|
|
|
|
__END__ |