line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Implemented optimizations: |
2
|
|
|
|
|
|
|
# * log-method's (ERR(), WARN(), etc.) implementation generated |
3
|
|
|
|
|
|
|
# individually for each log-object (depending on it configuration) |
4
|
|
|
|
|
|
|
# to include only minimum necessary code to do it work |
5
|
|
|
|
|
|
|
# - each time log-object configuration changes (by calling config()) |
6
|
|
|
|
|
|
|
# log-method's implementation re-generated to comply new configuration |
7
|
|
|
|
|
|
|
# - different log-objects may have different configuration and so will |
8
|
|
|
|
|
|
|
# need different implementation for same log-methods - so we have to |
9
|
|
|
|
|
|
|
# use unique package/class for each log-object (with class names looks |
10
|
|
|
|
|
|
|
# like 'Log::Fast::_12345678') - these classes will implement only |
11
|
|
|
|
|
|
|
# log-methods and inherit everything else from parent class (Log::Fast) |
12
|
|
|
|
|
|
|
# * implementation for log-methods inactive on current log level replaced |
13
|
|
|
|
|
|
|
# by empty 'sub{}' |
14
|
|
|
|
|
|
|
# - each time log level changes (by calling config() or level()) |
15
|
|
|
|
|
|
|
# implementation of all log-methods updated according to current |
16
|
|
|
|
|
|
|
# log level and set either to real implementation or empty 'sub{}' |
17
|
|
|
|
|
|
|
# * if prefixes %D and/or %T are used, then cache will be used to store |
18
|
|
|
|
|
|
|
# formatted date/time to avoid calculating it often than once per second |
19
|
|
|
|
|
|
|
# * when logging to syslog, packet header (which may contain: |
20
|
|
|
|
|
|
|
# log level, facility, timestamp, hostname, ident and pid) will be cached |
21
|
|
|
|
|
|
|
# (one cached header per each log level) |
22
|
|
|
|
|
|
|
# - if {add_timestamp} is true, then cached header will be used only for |
23
|
|
|
|
|
|
|
# one second and then recalculated |
24
|
|
|
|
|
|
|
# - if user change {ident} (by calling config() or ident()) cached |
25
|
|
|
|
|
|
|
# headers will be recalculated |
26
|
|
|
|
|
|
|
# * if log-methods will be called with single param sprintf() won't be used |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
package Log::Fast; |
29
|
|
|
|
|
|
|
|
30
|
8
|
|
|
8
|
|
197858
|
use warnings; |
|
8
|
|
|
|
|
22
|
|
|
8
|
|
|
|
|
284
|
|
31
|
8
|
|
|
8
|
|
43
|
use strict; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
255
|
|
32
|
8
|
|
|
8
|
|
36
|
use Carp; |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
630
|
|
33
|
|
|
|
|
|
|
|
34
|
8
|
|
|
8
|
|
178
|
use 5.008; |
|
8
|
|
|
|
|
27
|
|
|
8
|
|
|
|
|
365
|
|
35
|
8
|
|
|
8
|
|
7007
|
use version; our $VERSION = qv('1.0.6'); # REMINDER: update Changes |
|
8
|
|
|
|
|
17578
|
|
|
8
|
|
|
|
|
44
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# REMINDER: update dependencies in Makefile.PL |
38
|
8
|
|
|
8
|
|
648
|
use Scalar::Util qw( refaddr ); |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
831
|
|
39
|
8
|
|
|
8
|
|
6762
|
use Socket; |
|
8
|
|
|
|
|
30314
|
|
|
8
|
|
|
|
|
4651
|
|
40
|
8
|
|
|
8
|
|
15943
|
use Sys::Hostname (); |
|
8
|
|
|
|
|
16299
|
|
|
8
|
|
|
|
|
168
|
|
41
|
8
|
|
|
8
|
|
9532
|
use Time::HiRes (); |
|
8
|
|
|
|
|
16328
|
|
|
8
|
|
|
|
|
246
|
|
42
|
8
|
|
|
8
|
|
10982
|
use Sys::Syslog (); # for _PATH_LOG() |
|
8
|
|
|
|
|
170592
|
|
|
8
|
|
|
|
|
379
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# from RFC3164 |
46
|
8
|
|
|
8
|
|
81
|
use constant LOG_USER => 1*8; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
673
|
|
47
|
8
|
|
|
8
|
|
45
|
use constant LOG_ERR => 3; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
324
|
|
48
|
8
|
|
|
8
|
|
38
|
use constant LOG_WARNING => 4; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
455
|
|
49
|
8
|
|
|
8
|
|
48
|
use constant LOG_NOTICE => 5; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
339
|
|
50
|
8
|
|
|
8
|
|
39
|
use constant LOG_INFO => 6; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
308
|
|
51
|
8
|
|
|
8
|
|
34
|
use constant LOG_DEBUG => 7; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
796
|
|
52
|
8
|
|
|
|
|
1575
|
use constant PRI => { |
53
|
|
|
|
|
|
|
ERR => LOG_ERR, |
54
|
|
|
|
|
|
|
WARN => LOG_WARNING, |
55
|
|
|
|
|
|
|
NOTICE => LOG_NOTICE, |
56
|
|
|
|
|
|
|
INFO => LOG_INFO, |
57
|
|
|
|
|
|
|
DEBUG => LOG_DEBUG, |
58
|
8
|
|
|
8
|
|
39
|
}; |
|
8
|
|
|
|
|
12
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
use constant DEFAULTS => { |
61
|
|
|
|
|
|
|
level => 'DEBUG', |
62
|
|
|
|
|
|
|
prefix => q{}, |
63
|
|
|
|
|
|
|
type => 'fh', |
64
|
|
|
|
|
|
|
# used only when {type}='fh': |
65
|
|
|
|
|
|
|
fh => \*STDERR, |
66
|
|
|
|
|
|
|
# used only when {type}='unix': |
67
|
|
|
|
|
|
|
path => Sys::Syslog::_PATH_LOG() || '/dev/log', ## no critic(ProtectPrivateSubs) |
68
|
|
|
|
|
|
|
facility => LOG_USER, |
69
|
|
|
|
|
|
|
add_timestamp => 1, |
70
|
|
|
|
|
|
|
add_hostname => 0, |
71
|
|
|
|
|
|
|
hostname => Sys::Hostname::hostname(), |
72
|
8
|
|
|
|
|
48
|
ident => do { my $s = $0; utf8::decode($s); $s =~ s{\A.*/(?=.)}{}xms; $s }, |
|
8
|
|
|
|
|
119
|
|
|
8
|
|
|
|
|
70
|
|
|
8
|
|
|
|
|
49
|
|
|
8
|
|
|
|
|
1325
|
|
73
|
|
|
|
|
|
|
add_pid => 1, |
74
|
|
|
|
|
|
|
pid => $$, |
75
|
8
|
|
|
8
|
|
44
|
}; |
|
8
|
|
|
|
|
13
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $GLOBAL; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub new { |
80
|
11
|
|
|
11
|
1
|
2514
|
my ($class, $opt) = @_; |
81
|
11
|
|
100
|
|
|
63
|
$opt ||= {}; |
82
|
11
|
100
|
|
|
|
75
|
croak 'options must be HASHREF' if ref $opt ne 'HASH'; |
83
|
|
|
|
|
|
|
|
84
|
10
|
|
|
|
|
103
|
my $self = { # will also contain all keys defined in DEFAULTS constant |
85
|
|
|
|
|
|
|
# used only when {type}='unix': |
86
|
|
|
|
|
|
|
_sock => undef, # socket to {path} |
87
|
|
|
|
|
|
|
_header_ERR => q{}, # cached "<PRI>TIMESTAMP IDENT[PID]: " |
88
|
|
|
|
|
|
|
_header_WARN => q{}, # --"-- |
89
|
|
|
|
|
|
|
_header_NOTICE => q{}, # --"-- |
90
|
|
|
|
|
|
|
_header_INFO => q{}, # --"-- |
91
|
|
|
|
|
|
|
_header_DEBUG => q{}, # --"-- |
92
|
|
|
|
|
|
|
_header_time => 0, # last update time for {_header_*} |
93
|
|
|
|
|
|
|
# used only if {prefix} contain %D or %T: |
94
|
|
|
|
|
|
|
_date => q{}, # cached "YYYY-MM-DD" |
95
|
|
|
|
|
|
|
_time => q{}, # cached "HH:MM:SS" |
96
|
|
|
|
|
|
|
_dt_time => 0, # last update time for {_date} and {_time} |
97
|
|
|
|
|
|
|
}; |
98
|
|
|
|
|
|
|
|
99
|
10
|
|
|
|
|
63
|
my $sub_class = $class . '::_' . refaddr($self); |
100
|
8
|
|
|
8
|
|
68
|
{ no strict 'refs'; |
|
8
|
|
|
|
|
22
|
|
|
8
|
|
|
|
|
7618
|
|
|
10
|
|
|
|
|
18
|
|
101
|
10
|
|
|
|
|
17
|
@{$sub_class.'::ISA'} = ( $class ); |
|
10
|
|
|
|
|
243
|
|
102
|
|
|
|
|
|
|
} |
103
|
10
|
|
|
|
|
29
|
bless $self, $sub_class; |
104
|
|
|
|
|
|
|
|
105
|
10
|
|
|
|
|
16
|
$self->config({ %{ DEFAULTS() }, %{ $opt } }); ## no critic |
|
10
|
|
|
|
|
58
|
|
|
10
|
|
|
|
|
134
|
|
106
|
|
|
|
|
|
|
|
107
|
10
|
|
|
|
|
111
|
return $self; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub global { |
111
|
6
|
|
|
6
|
1
|
6361
|
my $class = shift; |
112
|
6
|
|
66
|
|
|
47
|
$GLOBAL ||= $class->new(); |
113
|
6
|
|
|
|
|
18
|
return $GLOBAL; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub config { |
117
|
49
|
|
|
49
|
1
|
118416
|
my ($self, $opt) = @_; |
118
|
49
|
100
|
|
|
|
192
|
croak 'options must be HASHREF' if ref $opt ne 'HASH'; |
119
|
|
|
|
|
|
|
|
120
|
47
|
|
|
|
|
61
|
for my $key (keys %{ $opt }) { |
|
47
|
|
|
|
|
220
|
|
121
|
167
|
100
|
|
|
|
333
|
if (!exists DEFAULTS->{ $key }) { |
122
|
1
|
|
|
|
|
11
|
croak 'unknown option: '.$key; |
123
|
|
|
|
|
|
|
} |
124
|
166
|
|
|
|
|
409
|
$self->{ $key } = $opt->{ $key }; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
46
|
|
|
|
|
190
|
$self->_generate_methods(); |
128
|
45
|
100
|
|
|
|
299
|
if ($self->{type} eq 'unix') { |
129
|
14
|
|
|
|
|
40
|
$self->_connect_unix(); |
130
|
14
|
|
|
|
|
43
|
$self->ident($self->{ident}); |
131
|
|
|
|
|
|
|
} |
132
|
45
|
|
|
|
|
185
|
$self->level($self->{level}); |
133
|
|
|
|
|
|
|
|
134
|
44
|
|
|
|
|
87
|
return; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub level { |
138
|
54
|
|
|
54
|
1
|
2056
|
my ($self, $level) = @_; |
139
|
54
|
|
|
|
|
99
|
my $prev_level = $self->{level}; |
140
|
54
|
100
|
|
|
|
131
|
if (defined $level) { |
141
|
52
|
100
|
|
|
|
132
|
if (!exists PRI->{$level}) { |
142
|
2
|
|
|
|
|
3
|
croak '{level} must be one of: '.join ', ', keys %{ PRI() }; |
|
2
|
|
|
|
|
29
|
|
143
|
|
|
|
|
|
|
} |
144
|
50
|
|
|
|
|
76
|
$self->{level} = $level; |
145
|
50
|
|
|
|
|
153
|
$self->_setup_level(); |
146
|
|
|
|
|
|
|
} |
147
|
52
|
|
|
|
|
86
|
return $prev_level; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub ident { |
151
|
18
|
|
|
18
|
1
|
471
|
my ($self, $ident) = @_; |
152
|
18
|
|
|
|
|
33
|
my $prev_ident = $self->{ident}; |
153
|
18
|
100
|
|
|
|
34
|
if (defined $ident) { |
154
|
17
|
|
|
|
|
27
|
$self->{ident} = $ident; |
155
|
17
|
|
|
|
|
34
|
$self->_update_header(); |
156
|
|
|
|
|
|
|
} |
157
|
18
|
|
|
|
|
38
|
return $prev_ident; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
### Internal |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub _connect_unix { |
163
|
14
|
|
|
14
|
|
19
|
my ($self) = @_; |
164
|
14
|
50
|
|
|
|
576
|
socket $self->{_sock}, AF_UNIX, SOCK_DGRAM, 0 or croak "socket: $!"; |
165
|
14
|
50
|
|
|
|
66
|
connect $self->{_sock}, sockaddr_un($self->{path}) or croak "connect: $!"; |
166
|
14
|
|
|
|
|
423
|
return; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub _update_header { |
170
|
17
|
|
|
17
|
|
21
|
my ($self) = @_; |
171
|
17
|
|
|
|
|
18
|
my $h = q{}; |
172
|
17
|
100
|
|
|
|
40
|
if ($self->{add_timestamp}) { |
173
|
3
|
|
|
|
|
11
|
$self->{_header_time} = time; |
174
|
3
|
|
|
|
|
232
|
$h .= substr localtime $self->{_header_time}, 4, 16; ## no critic(ProhibitMagicNumbers) |
175
|
|
|
|
|
|
|
} |
176
|
17
|
100
|
|
|
|
38
|
if ($self->{add_hostname}) { |
177
|
3
|
|
|
|
|
8
|
$h .= $self->{hostname} . q{ }; |
178
|
|
|
|
|
|
|
} |
179
|
17
|
|
|
|
|
24
|
my $ident_utf8 = $self->{ident}; |
180
|
17
|
|
|
|
|
33
|
utf8::encode($ident_utf8); |
181
|
17
|
|
|
|
|
17
|
$h .= $ident_utf8; |
182
|
17
|
100
|
|
|
|
33
|
if ($self->{add_pid}) { |
183
|
4
|
|
|
|
|
12
|
$h .= '[' . $self->{pid} . ']'; |
184
|
|
|
|
|
|
|
} |
185
|
17
|
|
|
|
|
23
|
$h .= ': '; |
186
|
17
|
|
|
|
|
19
|
for my $level (keys %{ PRI() }) { |
|
17
|
|
|
|
|
57
|
|
187
|
85
|
|
|
|
|
228
|
$self->{'_header_'.$level} |
188
|
|
|
|
|
|
|
= '<' . ($self->{facility} + PRI->{$level}) . '>' . $h; |
189
|
|
|
|
|
|
|
} |
190
|
17
|
|
|
|
|
41
|
return; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub _setup_level { |
194
|
50
|
|
|
50
|
|
61
|
my ($self) = @_; |
195
|
50
|
|
|
|
|
94
|
my $pkg = ref $self; |
196
|
50
|
|
|
|
|
54
|
for my $level (keys %{ PRI() }) { |
|
50
|
|
|
|
|
217
|
|
197
|
250
|
|
|
|
|
1059
|
my $is_active = PRI->{$level} <= PRI->{$self->{level}}; |
198
|
8
|
|
|
8
|
|
48
|
no strict 'refs'; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
265
|
|
199
|
8
|
|
|
8
|
|
40
|
no warnings 'redefine'; ## no critic |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
5103
|
|
200
|
250
|
100
|
|
10
|
|
424
|
*{$pkg.q{::}.$level} = $is_active ? \&{$pkg.q{::_}.$level} : sub {}; |
|
250
|
|
|
|
|
3406
|
|
|
236
|
|
|
|
|
594
|
|
|
10
|
|
|
|
|
12
|
|
201
|
|
|
|
|
|
|
} |
202
|
50
|
|
|
|
|
122
|
return; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub _generate_methods { ## no critic(ProhibitExcessComplexity) |
206
|
46
|
|
|
46
|
|
61
|
my ($self) = @_; |
207
|
46
|
|
|
|
|
75
|
my $pkg = ref $self; |
208
|
|
|
|
|
|
|
|
209
|
46
|
|
|
|
|
181
|
my %feature = map {$_=>1} $self->{prefix} =~ /%(.)/xmsg; |
|
44
|
|
|
|
|
100
|
|
210
|
46
|
|
100
|
|
|
193
|
$feature{timestamp} = $self->{type} eq 'unix' && $self->{add_timestamp}; |
211
|
|
|
|
|
|
|
|
212
|
46
|
|
|
|
|
167
|
my @pfx = split /(%.)/xms, $self->{prefix}; |
213
|
46
|
|
|
|
|
129
|
for (0 .. $#pfx) { |
214
|
93
|
|
|
|
|
136
|
utf8::encode($pfx[$_]); |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
46
|
|
|
|
|
54
|
for my $level (keys %{ PRI() }) { |
|
46
|
|
|
|
|
134
|
|
218
|
|
|
|
|
|
|
# ... begin |
219
|
226
|
|
|
|
|
309
|
my $code = <<'EOCODE'; |
220
|
|
|
|
|
|
|
sub { |
221
|
|
|
|
|
|
|
my $self = shift; |
222
|
|
|
|
|
|
|
my $msg = @_==1 ? $_[0] : sprintf shift, map {ref eq 'CODE' ? $_->() : $_} @_; |
223
|
|
|
|
|
|
|
utf8::encode($msg); |
224
|
|
|
|
|
|
|
EOCODE |
225
|
|
|
|
|
|
|
# ... if needed, get current time |
226
|
226
|
100
|
100
|
|
|
1490
|
if ($feature{S}) { |
|
|
100
|
100
|
|
|
|
|
227
|
20
|
|
|
|
|
27
|
$code .= <<'EOCODE'; |
228
|
|
|
|
|
|
|
my $msec = sprintf '%.05f', Time::HiRes::time(); |
229
|
|
|
|
|
|
|
my $time = int $msec; |
230
|
|
|
|
|
|
|
EOCODE |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
elsif ($feature{D} || $feature{T} || $feature{timestamp}) { |
233
|
20
|
|
|
|
|
26
|
$code .= <<'EOCODE'; |
234
|
|
|
|
|
|
|
my $time = time; |
235
|
|
|
|
|
|
|
EOCODE |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
# ... if needed, update caches |
238
|
226
|
100
|
100
|
|
|
790
|
if ($feature{D} || $feature{T}) { |
239
|
25
|
|
|
|
|
28
|
$code .= <<'EOCODE'; |
240
|
|
|
|
|
|
|
if ($self->{_dt_time} != $time) { |
241
|
|
|
|
|
|
|
$self->{_dt_time} = $time; |
242
|
|
|
|
|
|
|
my ($sec,$min,$hour,$mday,$mon,$year) = localtime $time; |
243
|
|
|
|
|
|
|
$self->{_date} = sprintf '%04d-%02d-%02d', $year+1900, $mon+1, $mday; |
244
|
|
|
|
|
|
|
$self->{_time} = sprintf '%02d:%02d:%02d', $hour, $min, $sec; |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
EOCODE |
247
|
|
|
|
|
|
|
} |
248
|
226
|
100
|
|
|
|
398
|
if ($feature{timestamp}) { |
249
|
15
|
|
|
|
|
18
|
$code .= <<'EOCODE'; |
250
|
|
|
|
|
|
|
if ($self->{_header_time} != $time) { |
251
|
|
|
|
|
|
|
$self->_update_header(); |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
EOCODE |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
# ... calculate prefix |
256
|
226
|
|
|
|
|
254
|
$code .= <<'EOCODE'; |
257
|
|
|
|
|
|
|
my $prefix = q{} |
258
|
|
|
|
|
|
|
EOCODE |
259
|
226
|
|
|
|
|
470
|
for my $pfx (@pfx) { |
260
|
465
|
100
|
|
|
|
1526
|
if ($pfx eq q{%L}) { ## no critic(ProhibitCascadingIfElse) |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
261
|
30
|
|
|
|
|
63
|
$code .= <<"EOCODE" |
262
|
|
|
|
|
|
|
. "\Q$level\E" |
263
|
|
|
|
|
|
|
EOCODE |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
elsif ($pfx eq q{%S}) { |
266
|
25
|
|
|
|
|
31
|
$code .= <<'EOCODE' |
267
|
|
|
|
|
|
|
. $msec |
268
|
|
|
|
|
|
|
EOCODE |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
elsif ($pfx eq q{%D}) { |
271
|
25
|
|
|
|
|
37
|
$code .= <<'EOCODE' |
272
|
|
|
|
|
|
|
. $self->{_date} |
273
|
|
|
|
|
|
|
EOCODE |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
elsif ($pfx eq q{%T}) { |
276
|
25
|
|
|
|
|
33
|
$code .= <<'EOCODE' |
277
|
|
|
|
|
|
|
. $self->{_time} |
278
|
|
|
|
|
|
|
EOCODE |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
elsif ($pfx eq q{%P}) { |
281
|
30
|
|
|
|
|
35
|
$code .= <<'EOCODE' |
282
|
|
|
|
|
|
|
. caller(0) |
283
|
|
|
|
|
|
|
EOCODE |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
elsif ($pfx eq q{%F}) { |
286
|
30
|
|
|
|
|
41
|
$code .= <<'EOCODE' |
287
|
|
|
|
|
|
|
. do { my $s = (caller(1))[3] || q{}; substr $s, 1+rindex $s, ':' } |
288
|
|
|
|
|
|
|
EOCODE |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
elsif ($pfx eq q{%_}) { |
291
|
30
|
|
|
|
|
47
|
$code .= <<'EOCODE' |
292
|
|
|
|
|
|
|
. do { my $n=0; 1 while caller(2 + $n++); ' ' x $n } |
293
|
|
|
|
|
|
|
EOCODE |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
elsif ($pfx eq q{%%}) { |
296
|
25
|
|
|
|
|
38
|
$code .= <<'EOCODE' |
297
|
|
|
|
|
|
|
. '%' |
298
|
|
|
|
|
|
|
EOCODE |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
else { |
301
|
245
|
|
|
|
|
407
|
$code .= <<"EOCODE" |
302
|
|
|
|
|
|
|
. "\Q$pfx\E" |
303
|
|
|
|
|
|
|
EOCODE |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
} |
306
|
226
|
|
|
|
|
251
|
$code .= <<'EOCODE'; |
307
|
|
|
|
|
|
|
; |
308
|
|
|
|
|
|
|
EOCODE |
309
|
|
|
|
|
|
|
# ... output |
310
|
226
|
100
|
|
|
|
1206
|
if ($self->{type} eq 'fh') { |
|
|
100
|
|
|
|
|
|
311
|
155
|
|
|
|
|
206
|
$code .= <<'EOCODE'; |
312
|
|
|
|
|
|
|
print { $self->{fh} } $prefix, $msg, "\n" or die "print() to log: $!"; |
313
|
|
|
|
|
|
|
EOCODE |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
elsif ($self->{type} eq 'unix') { |
316
|
70
|
|
|
|
|
116
|
$code .= <<"EOCODE"; |
317
|
|
|
|
|
|
|
my \$header = \$self->{_header_$level}; |
318
|
|
|
|
|
|
|
EOCODE |
319
|
70
|
|
|
|
|
91
|
$code .= <<'EOCODE'; |
320
|
|
|
|
|
|
|
send $self->{_sock}, $header.$prefix.$msg, 0 or do { |
321
|
|
|
|
|
|
|
$self->_connect_unix(); |
322
|
|
|
|
|
|
|
send $self->{_sock}, $header.$prefix.$msg, 0 or die "send() to syslog: $!"; |
323
|
|
|
|
|
|
|
}; |
324
|
|
|
|
|
|
|
EOCODE |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
else { |
327
|
1
|
|
|
|
|
12
|
croak '{type} should be "fh" or "unix"'; |
328
|
|
|
|
|
|
|
} |
329
|
|
|
|
|
|
|
# ... end |
330
|
225
|
|
|
|
|
221
|
$code .= <<'EOCODE'; |
331
|
|
|
|
|
|
|
} |
332
|
|
|
|
|
|
|
EOCODE |
333
|
|
|
|
|
|
|
# install generated method |
334
|
8
|
|
|
8
|
|
48
|
no strict 'refs'; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
376
|
|
335
|
8
|
|
|
8
|
|
48
|
no warnings 'redefine'; ## no critic |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
891
|
|
336
|
225
|
0
|
|
1
|
|
43335
|
*{$pkg.'::_'.$level} = eval $code; ## no critic |
|
225
|
50
|
|
|
|
1299
|
|
|
1
|
50
|
|
|
|
3
|
|
|
1
|
0
|
|
|
|
3
|
|
|
0
|
50
|
|
|
|
0
|
|
|
1
|
50
|
|
|
|
3
|
|
|
1
|
0
|
|
|
|
1
|
|
|
1
|
50
|
|
|
|
2
|
|
|
1
|
50
|
|
|
|
6
|
|
|
1
|
0
|
|
|
|
2
|
|
|
1
|
50
|
|
|
|
4
|
|
|
0
|
50
|
|
|
|
0
|
|
|
1
|
0
|
|
|
|
2
|
|
|
1
|
50
|
|
|
|
2
|
|
|
1
|
50
|
|
|
|
1
|
|
|
1
|
0
|
|
|
|
5
|
|
|
4
|
50
|
|
|
|
6
|
|
|
4
|
0
|
|
|
|
9
|
|
|
0
|
0
|
|
|
|
0
|
|
|
4
|
0
|
|
|
|
8
|
|
|
4
|
0
|
|
|
|
5
|
|
|
4
|
0
|
|
|
|
4
|
|
|
4
|
0
|
|
|
|
18
|
|
|
3
|
0
|
|
|
|
5
|
|
|
3
|
0
|
|
|
|
6
|
|
|
0
|
50
|
|
|
|
0
|
|
|
3
|
50
|
|
|
|
6
|
|
|
3
|
50
|
|
|
|
6
|
|
|
3
|
50
|
|
|
|
4
|
|
|
3
|
50
|
|
|
|
16
|
|
|
4
|
0
|
|
|
|
103
|
|
|
4
|
0
|
|
|
|
11
|
|
|
0
|
0
|
|
|
|
0
|
|
|
3
|
0
|
|
|
|
7
|
|
|
3
|
0
|
|
|
|
6
|
|
|
3
|
0
|
|
|
|
5
|
|
|
3
|
0
|
|
|
|
25
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
3
|
0
|
|
|
|
9
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
504
|
|
|
1
|
|
|
|
|
3
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
27
|
|
|
|
|
11511
|
|
|
27
|
|
|
|
|
57
|
|
|
0
|
|
|
|
|
0
|
|
|
27
|
|
|
|
|
47
|
|
|
27
|
|
|
|
|
24
|
|
|
28
|
|
|
|
|
27
|
|
|
28
|
|
|
|
|
89
|
|
|
28
|
|
|
|
|
66
|
|
|
27
|
|
|
|
|
134
|
|
|
28
|
|
|
|
|
69
|
|
|
28
|
|
|
|
|
31
|
|
|
27
|
|
|
|
|
140
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
21
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
5
|
|
|
0
|
|
|
|
|
0
|
|
337
|
|
|
|
|
|
|
} |
338
|
|
|
|
|
|
|
|
339
|
45
|
|
|
|
|
165
|
return; |
340
|
|
|
|
|
|
|
} |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
344
|
|
|
|
|
|
|
__END__ |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
=encoding utf8 |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
=head1 NAME |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
Log::Fast - Fast and flexible logger |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
=head1 SYNOPSIS |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
use Log::Fast; |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
$LOG = Log::Fast->global(); |
358
|
|
|
|
|
|
|
$LOG = Log::Fast->new({ |
359
|
|
|
|
|
|
|
level => 'WARN', |
360
|
|
|
|
|
|
|
prefix => '%D %T [%L] ', |
361
|
|
|
|
|
|
|
type => 'fh', |
362
|
|
|
|
|
|
|
fh => \*STDOUT, |
363
|
|
|
|
|
|
|
}); |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
use Sys::Syslog qw( LOG_DAEMON ); |
366
|
|
|
|
|
|
|
$LOG->config({ |
367
|
|
|
|
|
|
|
prefix => '', |
368
|
|
|
|
|
|
|
type => 'unix', |
369
|
|
|
|
|
|
|
path => '/dev/log', |
370
|
|
|
|
|
|
|
facility => LOG_DAEMON, |
371
|
|
|
|
|
|
|
add_timestamp => 1, |
372
|
|
|
|
|
|
|
add_hostname => 1, |
373
|
|
|
|
|
|
|
hostname => 'somehost', |
374
|
|
|
|
|
|
|
ident => 'someapp', |
375
|
|
|
|
|
|
|
add_pid => 1, |
376
|
|
|
|
|
|
|
pid => $$, |
377
|
|
|
|
|
|
|
}); |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
$LOG->ident('anotherapp'); |
380
|
|
|
|
|
|
|
$LOG->level('INFO'); |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
$LOG->ERR('Some error'); |
383
|
|
|
|
|
|
|
$LOG->WARN('Some warning'); |
384
|
|
|
|
|
|
|
$LOG->NOTICE('user %s logged in', $user); |
385
|
|
|
|
|
|
|
$LOG->INFO('data loaded'); |
386
|
|
|
|
|
|
|
$LOG->DEBUG('user %s have %d things', $user, sub { |
387
|
|
|
|
|
|
|
return SlowOperation_GetAmountOfThingsFor($user); |
388
|
|
|
|
|
|
|
}); |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
=head1 DESCRIPTION |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
This is very fast logger, designed for use in applications with thousands |
393
|
|
|
|
|
|
|
high-level events/operations per second (like network servers with |
394
|
|
|
|
|
|
|
thousands clients or web spiders which download hundreds url per second). |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
For example, on Core2Duo sending about 5000 messages to log on enabled |
397
|
|
|
|
|
|
|
log levels or 20000 messages on disabled log levels in I<one second> will |
398
|
|
|
|
|
|
|
slow down your application only by 2-3%. |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
Comparing to some other CPAN modules, this one (in average): |
401
|
|
|
|
|
|
|
faster than L<Log::Dispatch> in about 45 times, |
402
|
|
|
|
|
|
|
faster than L<Log::Handler> in about 15 times, |
403
|
|
|
|
|
|
|
faster than L<Sys::Syslog> in about 7 times, |
404
|
|
|
|
|
|
|
and slower than L<Log::Syslog::Fast> in about 2 times. |
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
=head2 FEATURES |
407
|
|
|
|
|
|
|
|
408
|
|
|
|
|
|
|
=over |
409
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
=item * Global and local logger objects |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
=item * Output to any open filehandle or local syslog |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
=item * 5 log levels: ERR, WARN, NOTICE, INFO, DEBUG |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
=item * Configurable prefix (log level, date/time, caller function name) |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
=item * sprintf() support |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
=item * Unicode support (UTF8) |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
=item * Can avoid calculating log message content on disabled log levels |
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
=back |
425
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
=head1 INTERFACE |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
=over |
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
=item Log::Fast->global() |
432
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
When called first time will create global log object using |
434
|
|
|
|
|
|
|
L<default options|/OPTIONS> (you can reconfigure it using C<config()> later). |
435
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
Global log object is useful if your application consists of several |
437
|
|
|
|
|
|
|
independent modules which should share same logging options configured |
438
|
|
|
|
|
|
|
outside of these modules. In this case all these modules should use |
439
|
|
|
|
|
|
|
same C<global()> log object instead of creating C<new()> independent log |
440
|
|
|
|
|
|
|
objects in each module. |
441
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
Return global log object. |
443
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
=item Log::Fast->new( [\%opt] ) |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
Create new log object, configured using L<defaults|/OPTIONS> and |
448
|
|
|
|
|
|
|
user-provided options, if any. |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
Return created log object. |
451
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
=item $LOG->config( \%opt ) |
454
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
Reconfigure log object. Any options (see L</OPTIONS>) can be changed at |
456
|
|
|
|
|
|
|
any time, including changing output B<{type}> or setting options useless |
457
|
|
|
|
|
|
|
with current output type (new values for these options will be used later, |
458
|
|
|
|
|
|
|
if output type will be changed). |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
If you need to change only log B<{level}> or syslog's B<{ident}> you should use |
461
|
|
|
|
|
|
|
C<level()> or C<ident()> methods because they are much faster than more general |
462
|
|
|
|
|
|
|
C<config()>. |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
Return nothing. Throw exception if unable to connect to syslog. |
465
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
=item $LOG->level( [$level] ) |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
If B<$level> given will change current log level. |
470
|
|
|
|
|
|
|
This is same as call C<< config({ level=>$level }) >> but much faster. |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
Return previous log level. |
473
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
=item $LOG->ident( [$ident] ) |
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
If B<$ident> given will change current syslog's ident. |
478
|
|
|
|
|
|
|
This is same as call C<< config({ ident=>$ident }) >> but much faster. |
479
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
Return previous syslog's ident. |
481
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
|
483
|
|
|
|
|
|
|
=item $LOG->ERR( $message ) |
484
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
=item $LOG->ERR( $format, @list ) |
486
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
=item $LOG->WARN( $message ) |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
=item $LOG->WARN( $format, @list ) |
490
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
=item $LOG->NOTICE( $message ) |
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
=item $LOG->NOTICE( $format, @list ) |
494
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
=item $LOG->INFO( $message ) |
496
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
=item $LOG->INFO( $format, @list ) |
498
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
=item $LOG->DEBUG( $message ) |
500
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
=item $LOG->DEBUG( $format, @list ) |
502
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
Output B<$message> to log using different log levels. |
504
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
If B<$format, @list> used instead of B<$message>, then use |
506
|
|
|
|
|
|
|
C<sprintf($format, @list)> to calculate log message. |
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
If B<@list> will contain CODEREF, they will be called (in LIST context) |
509
|
|
|
|
|
|
|
and returned values will be placed inside B<@list> inplace of CODEREF. |
510
|
|
|
|
|
|
|
This can be used to avoid calculating log message (or it part) on disabled |
511
|
|
|
|
|
|
|
log levels - these CODEREFs will be executed only on enabled log levels. |
512
|
|
|
|
|
|
|
Example available in L</SYNOPSIS>. |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
If B<$message> or items in B<@list> will be Unicode strings, they will be |
515
|
|
|
|
|
|
|
converted to UTF8 before sending to log. |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
Return nothing. Throw exception if fail to write message to log. |
518
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
=back |
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
=head1 OPTIONS |
524
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
Defaults for all options are: |
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
level => 'DEBUG', |
528
|
|
|
|
|
|
|
prefix => q{}, |
529
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
type => 'fh', |
531
|
|
|
|
|
|
|
fh => \*STDERR, |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
# these will be used if you will call config({ type=>'unix' }) |
534
|
|
|
|
|
|
|
path => Sys::Syslog::_PATH_LOG() || '/dev/log', |
535
|
|
|
|
|
|
|
facility => LOG_USER, |
536
|
|
|
|
|
|
|
add_timestamp => 1, |
537
|
|
|
|
|
|
|
add_hostname => 0, |
538
|
|
|
|
|
|
|
hostname => Sys::Hostname::hostname(), |
539
|
|
|
|
|
|
|
ident => ..., # calculated from $0 |
540
|
|
|
|
|
|
|
add_pid => 1, |
541
|
|
|
|
|
|
|
pid => $$, |
542
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
=over |
545
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
=item level |
547
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
Current log level. Possible values are: |
549
|
|
|
|
|
|
|
C<'ERR'>, C<'WARN'>, C<'NOTICE'>, C<'INFO'>, C<'DEBUG'>. |
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
Only messages on current or higher levels will be sent to log. |
552
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
=item prefix |
555
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
String, which will be output at beginning of each log message. |
557
|
|
|
|
|
|
|
May contain these placeholders: |
558
|
|
|
|
|
|
|
|
559
|
|
|
|
|
|
|
%L - log level of current message |
560
|
|
|
|
|
|
|
%S - hi-resolution time (seconds.microseconds) |
561
|
|
|
|
|
|
|
%D - current date in format YYYY-MM-DD |
562
|
|
|
|
|
|
|
%T - current time in format HH:MM:SS |
563
|
|
|
|
|
|
|
%P - caller's function package ('main' or 'My::Module') |
564
|
|
|
|
|
|
|
%F - caller's function name |
565
|
|
|
|
|
|
|
%_ - X spaces, where X is current stack depth |
566
|
|
|
|
|
|
|
%% - % character |
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
Example output with prefix C<'%D %T [%L]%_%P::%F() '>: |
569
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
2010-11-17 18:06:20 [INFO] main::() something from main script |
571
|
|
|
|
|
|
|
2010-11-17 18:06:53 [INFO] main::a() something from a |
572
|
|
|
|
|
|
|
2010-11-17 18:09:09 [INFO] main::b2() something from b1->b2 |
573
|
|
|
|
|
|
|
2010-11-17 18:06:56 [INFO] main::c() something from c |
574
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
If it will be Unicode string, it will be converted to UTF8. |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
=item type |
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
Output type. Possible values are: C<'fh'> (output to any already open |
581
|
|
|
|
|
|
|
filehandle) and C<'unix'> (output to syslog using UNIX socket). |
582
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
When B<{type}> set to C<'fh'> you have to also set B<{fh}> to any open |
584
|
|
|
|
|
|
|
filehandle (like C<\*STDERR>). |
585
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
When B<{type}> set to C<'unix'> you have to also set B<{path}> to path to |
587
|
|
|
|
|
|
|
existing unix socket (typically it's C<'/dev/log'>). |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
Luckily, default values for both B<{fh}> and B<{path}> are already provided, |
590
|
|
|
|
|
|
|
so usually it's enough to just set B<{type}>. |
591
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
=item fh |
594
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
File handle to write log messages if B<{type}> set to C<'fh'>. |
596
|
|
|
|
|
|
|
|
597
|
|
|
|
|
|
|
=item path |
598
|
|
|
|
|
|
|
|
599
|
|
|
|
|
|
|
Syslog's UNIX socket path to write log messages if B<{type}> set to C<'unix'>. |
600
|
|
|
|
|
|
|
|
601
|
|
|
|
|
|
|
=item facility |
602
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
Syslog's facility (see L<Sys::Syslog/Facilities> for a list of well-known facilities). |
604
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
This module doesn't export any constants, so if you wanna change it from default |
606
|
|
|
|
|
|
|
LOG_USER value, you should import facility constants from L<Sys::Syslog> module. |
607
|
|
|
|
|
|
|
Example available in L</SYNOPSIS>. |
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
=item add_timestamp |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
If TRUE will include timestamp in syslog messages. |
613
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
=item add_hostname |
616
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
If TRUE will include hostname in syslog messages. |
618
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
=item hostname |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
Host name which will be included in syslog messages if B<{add_hostname}> is TRUE. |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
|
625
|
|
|
|
|
|
|
=item ident |
626
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
Syslog's ident (application name) field. |
628
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
If it will be Unicode string, it will be converted to UTF8. |
630
|
|
|
|
|
|
|
Using non-ASCII ALPHANUMERIC ident isn't allowed by RFC, but usually |
631
|
|
|
|
|
|
|
works. |
632
|
|
|
|
|
|
|
|
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
=item add_pid |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
If TRUE will include PID in syslog messages. |
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
|
639
|
|
|
|
|
|
|
=item pid |
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
PID which will be included in syslog messages if B<{add_pid}> is TRUE. |
642
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
=back |
645
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
=head1 SPEED HINTS |
648
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
Empty prefix is fastest. Prefixes C<%L>, C<%P> and C<%%> are fast enough, |
650
|
|
|
|
|
|
|
C<%D> and C<%T> has average speed, C<%S>, C<%F> and C<%_> are slowest. |
651
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
Output to file is about 4 times faster than to syslog. |
653
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
Calling log with single parameter is faster than with many parameters |
655
|
|
|
|
|
|
|
(because in second case sprintf() have to be used). |
656
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
No bugs have been reported. |
661
|
|
|
|
|
|
|
|
662
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
=head1 SUPPORT |
664
|
|
|
|
|
|
|
|
665
|
|
|
|
|
|
|
Please report any bugs or feature requests through the web interface at |
666
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Log-Fast>. |
667
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress |
668
|
|
|
|
|
|
|
on your bug as I make changes. |
669
|
|
|
|
|
|
|
|
670
|
|
|
|
|
|
|
You can also look for information at: |
671
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
=over 4 |
673
|
|
|
|
|
|
|
|
674
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
675
|
|
|
|
|
|
|
|
676
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Log-Fast> |
677
|
|
|
|
|
|
|
|
678
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
679
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
L<http://annocpan.org/dist/Log-Fast> |
681
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
=item * CPAN Ratings |
683
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/Log-Fast> |
685
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
=item * Search CPAN |
687
|
|
|
|
|
|
|
|
688
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/Log-Fast/> |
689
|
|
|
|
|
|
|
|
690
|
|
|
|
|
|
|
=back |
691
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
|
693
|
|
|
|
|
|
|
=head1 AUTHOR |
694
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
Alex Efros C<< <powerman-asdf@ya.ru> >> |
696
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
|
698
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
699
|
|
|
|
|
|
|
|
700
|
|
|
|
|
|
|
Copyright 2010,2012 Alex Efros <powerman-asdf@ya.ru>. |
701
|
|
|
|
|
|
|
|
702
|
|
|
|
|
|
|
This program is distributed under the MIT (X11) License: |
703
|
|
|
|
|
|
|
L<http://www.opensource.org/licenses/mit-license.php> |
704
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person |
706
|
|
|
|
|
|
|
obtaining a copy of this software and associated documentation |
707
|
|
|
|
|
|
|
files (the "Software"), to deal in the Software without |
708
|
|
|
|
|
|
|
restriction, including without limitation the rights to use, |
709
|
|
|
|
|
|
|
copy, modify, merge, publish, distribute, sublicense, and/or sell |
710
|
|
|
|
|
|
|
copies of the Software, and to permit persons to whom the |
711
|
|
|
|
|
|
|
Software is furnished to do so, subject to the following |
712
|
|
|
|
|
|
|
conditions: |
713
|
|
|
|
|
|
|
|
714
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be |
715
|
|
|
|
|
|
|
included in all copies or substantial portions of the Software. |
716
|
|
|
|
|
|
|
|
717
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
718
|
|
|
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
719
|
|
|
|
|
|
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
720
|
|
|
|
|
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
721
|
|
|
|
|
|
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
722
|
|
|
|
|
|
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
723
|
|
|
|
|
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
724
|
|
|
|
|
|
|
OTHER DEALINGS IN THE SOFTWARE. |
725
|
|
|
|
|
|
|
|