line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Syslog::Fast::PP; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
15443
|
use 5.006002; |
|
8
|
|
|
|
|
74
|
|
4
|
8
|
|
|
8
|
|
45
|
use strict; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
201
|
|
5
|
8
|
|
|
8
|
|
48
|
use warnings; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
286
|
|
6
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
3334
|
use Log::Syslog::Fast::Constants ':all'; |
|
8
|
|
|
|
|
22
|
|
|
8
|
|
|
|
|
2884
|
|
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
|
|
58
|
use Carp; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
545
|
|
15
|
8
|
|
|
8
|
|
4165
|
use POSIX 'strftime'; |
|
8
|
|
|
|
|
63454
|
|
|
8
|
|
|
|
|
41
|
|
16
|
8
|
|
|
8
|
|
16256
|
use IO::Socket::IP; |
|
8
|
|
|
|
|
223160
|
|
|
8
|
|
|
|
|
61
|
|
17
|
8
|
|
|
8
|
|
3905
|
use IO::Socket::UNIX; |
|
8
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
67
|
|
18
|
8
|
|
|
8
|
|
6803
|
use Socket; |
|
8
|
|
|
|
|
22
|
|
|
8
|
|
|
|
|
4710
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
0
|
|
|
sub DESTROY { } |
21
|
|
|
|
|
|
|
|
22
|
8
|
|
|
8
|
|
65
|
use constant PRIORITY => 0; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
467
|
|
23
|
8
|
|
|
8
|
|
45
|
use constant SENDER => 1; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
447
|
|
24
|
8
|
|
|
8
|
|
48
|
use constant NAME => 2; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
398
|
|
25
|
8
|
|
|
8
|
|
43
|
use constant PID => 3; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
400
|
|
26
|
8
|
|
|
8
|
|
47
|
use constant SOCK => 4; |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
318
|
|
27
|
8
|
|
|
8
|
|
39
|
use constant LAST_TIME => 5; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
392
|
|
28
|
8
|
|
|
8
|
|
48
|
use constant PREFIX => 6; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
314
|
|
29
|
8
|
|
|
8
|
|
41
|
use constant PREFIX_LEN => 7; |
|
8
|
|
|
|
|
22
|
|
|
8
|
|
|
|
|
417
|
|
30
|
8
|
|
|
8
|
|
48
|
use constant FORMAT => 8; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
10043
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub new { |
33
|
38
|
|
|
38
|
0
|
329425
|
my $ref = shift; |
34
|
38
|
100
|
|
|
|
120
|
$ref = __PACKAGE__ unless defined $ref; |
35
|
38
|
|
33
|
|
|
168
|
my $class = ref $ref || $ref; |
36
|
|
|
|
|
|
|
|
37
|
38
|
|
|
|
|
109
|
my ($proto, $hostname, $port, $facility, $severity, $sender, $name) = @_; |
38
|
|
|
|
|
|
|
|
39
|
38
|
100
|
|
|
|
325
|
croak "hostname required" unless defined $hostname; |
40
|
37
|
100
|
|
|
|
184
|
croak "sender required" unless defined $sender; |
41
|
36
|
100
|
|
|
|
183
|
croak "name required" unless defined $name; |
42
|
|
|
|
|
|
|
|
43
|
35
|
|
|
|
|
172
|
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
|
35
|
|
|
|
|
128
|
$self->update_prefix(time()); |
56
|
|
|
|
|
|
|
|
57
|
35
|
|
|
|
|
67
|
eval { $self->set_receiver($proto, $hostname, $port) }; |
|
35
|
|
|
|
|
100
|
|
58
|
35
|
100
|
|
|
|
153
|
die "Error in ->new: $@" if $@; |
59
|
26
|
|
|
|
|
94
|
return $self; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub update_prefix { |
63
|
85
|
|
|
85
|
0
|
141
|
my $self = shift; |
64
|
85
|
|
|
|
|
119
|
my $t = shift; |
65
|
|
|
|
|
|
|
|
66
|
85
|
|
|
|
|
169
|
$self->[LAST_TIME] = $t; |
67
|
|
|
|
|
|
|
|
68
|
85
|
|
|
|
|
4161
|
my $timestr = strftime("%h %e %T", localtime $t); |
69
|
85
|
100
|
|
|
|
402
|
if ($self->[FORMAT] == LOG_RFC5424) { |
70
|
4
|
|
|
|
|
174
|
$timestr = strftime("%Y-%m-%dT%H:%M:%S%z", localtime $t); |
71
|
4
|
|
|
|
|
54
|
$timestr =~ s/(\d{2})$/:$1/; # see http://tools.ietf.org/html/rfc3339#section-5.6 time-numoffset |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
85
|
|
|
|
|
504
|
$self->[PREFIX] = sprintf "<%d>%s %s %s[%d]: ", |
75
|
|
|
|
|
|
|
$self->[PRIORITY], $timestr, $self->[SENDER], $self->[NAME], $self->[PID]; |
76
|
85
|
100
|
|
|
|
212
|
if ($self->[FORMAT] == LOG_RFC5424) { |
77
|
4
|
|
|
|
|
19
|
$self->[PREFIX] = sprintf "<%d>1 %s %s %s %d - - ", |
78
|
|
|
|
|
|
|
$self->[PRIORITY], $timestr, $self->[SENDER], $self->[NAME], $self->[PID]; |
79
|
|
|
|
|
|
|
} |
80
|
85
|
100
|
|
|
|
258
|
if ($self->[FORMAT] == LOG_RFC3164_LOCAL) { |
81
|
8
|
|
|
|
|
42
|
$self->[PREFIX] = sprintf "<%d>%s %s[%d]: ", |
82
|
|
|
|
|
|
|
$self->[PRIORITY], $timestr, $self->[NAME], $self->[PID]; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub set_receiver { |
87
|
144
|
|
|
144
|
0
|
21373
|
my $self = shift; |
88
|
144
|
100
|
|
|
|
446
|
croak("hostname required") unless defined $_[1]; |
89
|
|
|
|
|
|
|
|
90
|
143
|
|
|
|
|
302
|
my ($proto, $hostname, $port) = @_; |
91
|
|
|
|
|
|
|
|
92
|
143
|
100
|
|
|
|
375
|
if ($proto == LOG_TCP) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
93
|
110
|
|
|
|
|
597
|
$self->[SOCK] = IO::Socket::IP->new( |
94
|
|
|
|
|
|
|
Proto => 'tcp', |
95
|
|
|
|
|
|
|
PeerHost => $hostname, |
96
|
|
|
|
|
|
|
PeerPort => $port, |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
elsif ($proto == LOG_UDP) { |
100
|
13
|
|
|
|
|
113
|
$self->[SOCK] = IO::Socket::IP->new( |
101
|
|
|
|
|
|
|
Proto => 'udp', |
102
|
|
|
|
|
|
|
PeerHost => $hostname, |
103
|
|
|
|
|
|
|
PeerPort => $port, |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
elsif ($proto == LOG_UNIX) { |
107
|
20
|
|
|
|
|
32
|
eval { |
108
|
20
|
|
|
|
|
133
|
$self->[SOCK] = IO::Socket::UNIX->new( |
109
|
|
|
|
|
|
|
Type => SOCK_STREAM, |
110
|
|
|
|
|
|
|
Peer => $hostname, |
111
|
|
|
|
|
|
|
); |
112
|
|
|
|
|
|
|
}; |
113
|
20
|
100
|
66
|
|
|
4581
|
if ($@ || !$self->[SOCK]) { |
114
|
13
|
|
|
|
|
80
|
$self->[SOCK] = IO::Socket::UNIX->new( |
115
|
|
|
|
|
|
|
Type => SOCK_DGRAM, |
116
|
|
|
|
|
|
|
Peer => $hostname, |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
143
|
100
|
|
|
|
170422
|
die "Error in ->set_receiver: $!" unless $self->[SOCK]; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub set_priority { |
125
|
11
|
|
|
11
|
0
|
2537
|
my $self = shift; |
126
|
11
|
|
|
|
|
29
|
my ($facility, $severity) = @_; |
127
|
11
|
|
|
|
|
28
|
$self->[PRIORITY] = ($facility << 3) | $severity; |
128
|
11
|
|
|
|
|
32
|
$self->update_prefix(time); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub set_facility { |
132
|
1
|
|
|
1
|
0
|
22
|
my $self = shift; |
133
|
1
|
|
|
|
|
4
|
$self->set_priority(shift, $self->get_severity); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub set_severity { |
137
|
1
|
|
|
1
|
0
|
320
|
my $self = shift; |
138
|
1
|
|
|
|
|
4
|
$self->set_priority($self->get_facility, shift); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub set_sender { |
142
|
10
|
|
|
10
|
0
|
3096
|
my $self = shift; |
143
|
10
|
100
|
|
|
|
127
|
croak("sender required") unless defined $_[0]; |
144
|
9
|
|
|
|
|
23
|
$self->[SENDER] = shift; |
145
|
9
|
|
|
|
|
28
|
$self->update_prefix(time); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub set_name { |
149
|
10
|
|
|
10
|
0
|
3057
|
my $self = shift; |
150
|
10
|
100
|
|
|
|
134
|
croak("name required") unless defined $_[0]; |
151
|
9
|
|
|
|
|
21
|
$self->[NAME] = shift; |
152
|
9
|
|
|
|
|
22
|
$self->update_prefix(time); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub set_pid { |
156
|
9
|
|
|
9
|
0
|
2718
|
my $self = shift; |
157
|
9
|
|
|
|
|
19
|
$self->[PID] = shift; |
158
|
9
|
|
|
|
|
46
|
$self->update_prefix(time); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub set_format { |
162
|
12
|
|
|
12
|
0
|
16268
|
my $self = shift; |
163
|
12
|
|
|
|
|
23
|
$self->[FORMAT] = shift; |
164
|
12
|
|
|
|
|
34
|
$self->update_prefix(time); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub send { |
168
|
33
|
|
66
|
33
|
0
|
25830
|
my $now = $_[2] || time; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# update the prefix if seconds have rolled over |
171
|
33
|
50
|
|
|
|
98
|
if ($now != $_[0][LAST_TIME]) { |
172
|
0
|
|
|
|
|
0
|
$_[0]->update_prefix($now); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
33
|
100
|
|
|
|
1189
|
send($_[0][SOCK], $_[0][PREFIX] . $_[1], 0) || die "Error while sending: $!"; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
#no warnings 'redefine'; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub get_priority { |
181
|
3
|
|
|
3
|
0
|
304
|
my $self = shift; |
182
|
3
|
|
|
|
|
17
|
return $self->[PRIORITY]; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub get_facility { |
186
|
3
|
|
|
3
|
0
|
305
|
my $self = shift; |
187
|
3
|
|
|
|
|
19
|
return $self->[PRIORITY] >> 3; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub get_severity { |
191
|
3
|
|
|
3
|
0
|
10
|
my $self = shift; |
192
|
3
|
|
|
|
|
14
|
return $self->[PRIORITY] & 7; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub get_sender { |
196
|
2
|
|
|
2
|
0
|
6
|
my $self = shift; |
197
|
2
|
|
|
|
|
9
|
return $self->[SENDER]; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub get_name { |
201
|
2
|
|
|
2
|
0
|
5
|
my $self = shift; |
202
|
2
|
|
|
|
|
9
|
return $self->[NAME]; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub get_pid { |
206
|
2
|
|
|
2
|
0
|
5
|
my $self = shift; |
207
|
2
|
|
|
|
|
10
|
return $self->[PID]; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub get_format { |
211
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
212
|
0
|
|
|
|
|
0
|
return $self->[FORMAT]; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub _get_sock { |
216
|
2
|
|
|
2
|
|
204
|
my $self = shift; |
217
|
2
|
|
|
|
|
9
|
return $self->[SOCK]->fileno; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
1; |
221
|
|
|
|
|
|
|
__END__ |