line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Syslog::Fast::PP; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
10512
|
use 5.006002; |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
227
|
|
4
|
8
|
|
|
8
|
|
23
|
use strict; |
|
8
|
|
|
|
|
7
|
|
|
8
|
|
|
|
|
166
|
|
5
|
8
|
|
|
8
|
|
23
|
use warnings; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
160
|
|
6
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
1848
|
use Log::Syslog::Fast::Constants ':all'; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
2108
|
|
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
|
|
55
|
use Carp; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
349
|
|
15
|
8
|
|
|
8
|
|
3202
|
use POSIX 'strftime'; |
|
8
|
|
|
|
|
33451
|
|
|
8
|
|
|
|
|
38
|
|
16
|
8
|
|
|
8
|
|
9782
|
use IO::Socket::IP; |
|
8
|
|
|
|
|
166089
|
|
|
8
|
|
|
|
|
46
|
|
17
|
8
|
|
|
8
|
|
3544
|
use IO::Socket::UNIX; |
|
8
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
56
|
|
18
|
8
|
|
|
8
|
|
4762
|
use Socket; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
3601
|
|
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
0
|
|
0
|
sub DESTROY { } |
21
|
|
|
|
|
|
|
|
22
|
8
|
|
|
8
|
|
32
|
use constant PRIORITY => 0; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
373
|
|
23
|
8
|
|
|
8
|
|
26
|
use constant SENDER => 1; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
235
|
|
24
|
8
|
|
|
8
|
|
24
|
use constant NAME => 2; |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
222
|
|
25
|
8
|
|
|
8
|
|
54
|
use constant PID => 3; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
234
|
|
26
|
8
|
|
|
8
|
|
23
|
use constant SOCK => 4; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
228
|
|
27
|
8
|
|
|
8
|
|
32
|
use constant LAST_TIME => 5; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
247
|
|
28
|
8
|
|
|
8
|
|
28
|
use constant PREFIX => 6; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
237
|
|
29
|
8
|
|
|
8
|
|
24
|
use constant PREFIX_LEN => 7; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
265
|
|
30
|
8
|
|
|
8
|
|
30
|
use constant FORMAT => 8; |
|
8
|
|
|
|
|
7
|
|
|
8
|
|
|
|
|
7053
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub new { |
33
|
34
|
|
|
34
|
0
|
111602
|
my $ref = shift; |
34
|
34
|
100
|
|
|
|
95
|
$ref = __PACKAGE__ unless defined $ref; |
35
|
34
|
|
33
|
|
|
142
|
my $class = ref $ref || $ref; |
36
|
|
|
|
|
|
|
|
37
|
34
|
|
|
|
|
54
|
my ($proto, $hostname, $port, $facility, $severity, $sender, $name) = @_; |
38
|
|
|
|
|
|
|
|
39
|
34
|
100
|
|
|
|
226
|
croak "hostname required" unless defined $hostname; |
40
|
33
|
100
|
|
|
|
153
|
croak "sender required" unless defined $sender; |
41
|
32
|
100
|
|
|
|
151
|
croak "name required" unless defined $name; |
42
|
|
|
|
|
|
|
|
43
|
31
|
|
|
|
|
154
|
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
|
|
|
|
|
103
|
$self->update_prefix(time()); |
56
|
|
|
|
|
|
|
|
57
|
31
|
|
|
|
|
35
|
eval { $self->set_receiver($proto, $hostname, $port) }; |
|
31
|
|
|
|
|
63
|
|
58
|
31
|
100
|
|
|
|
97
|
die "Error in ->new: $@" if $@; |
59
|
22
|
|
|
|
|
59
|
return $self; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub update_prefix { |
63
|
73
|
|
|
73
|
0
|
72
|
my $self = shift; |
64
|
73
|
|
|
|
|
60
|
my $t = shift; |
65
|
|
|
|
|
|
|
|
66
|
73
|
|
|
|
|
98
|
$self->[LAST_TIME] = $t; |
67
|
|
|
|
|
|
|
|
68
|
73
|
|
|
|
|
2475
|
my $timestr = strftime("%h %e %T", localtime $t); |
69
|
73
|
100
|
|
|
|
193
|
if ($self->[FORMAT] == LOG_RFC5424) { |
70
|
4
|
|
|
|
|
65
|
$timestr = strftime("%Y-%m-%dT%H:%M:%S%z", localtime $t); |
71
|
4
|
|
|
|
|
27
|
$timestr =~ s/(\d{2})$/:$1/; # see http://tools.ietf.org/html/rfc3339#section-5.6 time-numoffset |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
73
|
|
|
|
|
296
|
$self->[PREFIX] = sprintf "<%d>%s %s %s[%d]: ", |
75
|
|
|
|
|
|
|
$self->[PRIORITY], $timestr, $self->[SENDER], $self->[NAME], $self->[PID]; |
76
|
73
|
100
|
|
|
|
179
|
if ($self->[FORMAT] == LOG_RFC5424) { |
77
|
4
|
|
|
|
|
16
|
$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
|
11129
|
my $self = shift; |
84
|
140
|
100
|
|
|
|
310
|
croak("hostname required") unless defined $_[1]; |
85
|
|
|
|
|
|
|
|
86
|
139
|
|
|
|
|
166
|
my ($proto, $hostname, $port) = @_; |
87
|
|
|
|
|
|
|
|
88
|
139
|
100
|
|
|
|
234
|
if ($proto == LOG_TCP) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
89
|
109
|
|
|
|
|
406
|
$self->[SOCK] = IO::Socket::IP->new( |
90
|
|
|
|
|
|
|
Proto => 'tcp', |
91
|
|
|
|
|
|
|
PeerHost => $hostname, |
92
|
|
|
|
|
|
|
PeerPort => $port, |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
elsif ($proto == LOG_UDP) { |
96
|
12
|
|
|
|
|
70
|
$self->[SOCK] = IO::Socket::IP->new( |
97
|
|
|
|
|
|
|
Proto => 'udp', |
98
|
|
|
|
|
|
|
PeerHost => $hostname, |
99
|
|
|
|
|
|
|
PeerPort => $port, |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
elsif ($proto == LOG_UNIX) { |
103
|
18
|
|
|
|
|
14
|
eval { |
104
|
18
|
|
|
|
|
82
|
$self->[SOCK] = IO::Socket::UNIX->new( |
105
|
|
|
|
|
|
|
Type => SOCK_STREAM, |
106
|
|
|
|
|
|
|
Peer => $hostname, |
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
}; |
109
|
18
|
100
|
66
|
|
|
2195
|
if ($@ || !$self->[SOCK]) { |
110
|
12
|
|
|
|
|
47
|
$self->[SOCK] = IO::Socket::UNIX->new( |
111
|
|
|
|
|
|
|
Type => SOCK_DGRAM, |
112
|
|
|
|
|
|
|
Peer => $hostname, |
113
|
|
|
|
|
|
|
); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
139
|
100
|
|
|
|
46649
|
die "Error in ->set_receiver: $!" unless $self->[SOCK]; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub set_priority { |
121
|
11
|
|
|
11
|
0
|
1671
|
my $self = shift; |
122
|
11
|
|
|
|
|
16
|
my ($facility, $severity) = @_; |
123
|
11
|
|
|
|
|
27
|
$self->[PRIORITY] = ($facility << 3) | $severity; |
124
|
11
|
|
|
|
|
25
|
$self->update_prefix(time); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub set_facility { |
128
|
1
|
|
|
1
|
0
|
10
|
my $self = shift; |
129
|
1
|
|
|
|
|
3
|
$self->set_priority(shift, $self->get_severity); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub set_severity { |
133
|
1
|
|
|
1
|
0
|
187
|
my $self = shift; |
134
|
1
|
|
|
|
|
3
|
$self->set_priority($self->get_facility, shift); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub set_sender { |
138
|
10
|
|
|
10
|
0
|
1903
|
my $self = shift; |
139
|
10
|
100
|
|
|
|
99
|
croak("sender required") unless defined $_[0]; |
140
|
9
|
|
|
|
|
20
|
$self->[SENDER] = shift; |
141
|
9
|
|
|
|
|
23
|
$self->update_prefix(time); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub set_name { |
145
|
10
|
|
|
10
|
0
|
2068
|
my $self = shift; |
146
|
10
|
100
|
|
|
|
114
|
croak("name required") unless defined $_[0]; |
147
|
9
|
|
|
|
|
14
|
$self->[NAME] = shift; |
148
|
9
|
|
|
|
|
20
|
$self->update_prefix(time); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub set_pid { |
152
|
9
|
|
|
9
|
0
|
1631
|
my $self = shift; |
153
|
9
|
|
|
|
|
14
|
$self->[PID] = shift; |
154
|
9
|
|
|
|
|
25
|
$self->update_prefix(time); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub set_format { |
158
|
4
|
|
|
4
|
0
|
644
|
my $self = shift; |
159
|
4
|
|
|
|
|
6
|
$self->[FORMAT] = shift; |
160
|
4
|
|
|
|
|
9
|
$self->update_prefix(time); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub send { |
164
|
25
|
|
66
|
25
|
0
|
11907
|
my $now = $_[2] || time; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# update the prefix if seconds have rolled over |
167
|
25
|
50
|
|
|
|
61
|
if ($now != $_[0][LAST_TIME]) { |
168
|
0
|
|
|
|
|
0
|
$_[0]->update_prefix($now); |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
25
|
100
|
|
|
|
590
|
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
|
184
|
my $self = shift; |
178
|
3
|
|
|
|
|
14
|
return $self->[PRIORITY]; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub get_facility { |
182
|
3
|
|
|
3
|
0
|
213
|
my $self = shift; |
183
|
3
|
|
|
|
|
9
|
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
|
4
|
my $self = shift; |
193
|
2
|
|
|
|
|
7
|
return $self->[SENDER]; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub get_name { |
197
|
2
|
|
|
2
|
0
|
3
|
my $self = shift; |
198
|
2
|
|
|
|
|
8
|
return $self->[NAME]; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub get_pid { |
202
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
203
|
2
|
|
|
|
|
5
|
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
|
|
102
|
my $self = shift; |
213
|
2
|
|
|
|
|
5
|
return $self->[SOCK]->fileno; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
1; |
217
|
|
|
|
|
|
|
__END__ |