line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Log::Fine::Formatter::Syslog - Formatter for Syslog formatting |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 SYNOPSIS |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Formats messages in a style similar to syslog(1) |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Log::Fine::Formatter::Syslog; |
11
|
|
|
|
|
|
|
use Log::Fine::Handle::Console; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Instantiate a handle |
14
|
|
|
|
|
|
|
my $handle = Log::Fine::Handle::Console->new(); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Instantiate a formatter |
17
|
|
|
|
|
|
|
my $formatter = Log::Fine::Formatter::Syslog |
18
|
|
|
|
|
|
|
->new( name => 'syslog0'); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Set the formatter |
21
|
|
|
|
|
|
|
$handle->formatter( formatter => $formatter ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Format a msg |
24
|
|
|
|
|
|
|
my $str = $formatter->format(INFO, "Resistence is futile", 1); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
The syslog formatter logs messages in a format similar to that |
29
|
|
|
|
|
|
|
produced by syslog(1). |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
[]: |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
2
|
|
982
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
42
|
|
36
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
52
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
package Log::Fine::Formatter::Syslog; |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
2
|
|
6
|
use base qw( Log::Fine::Formatter ); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
98
|
|
41
|
|
|
|
|
|
|
|
42
|
2
|
|
|
2
|
|
6
|
use File::Basename; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
75
|
|
43
|
2
|
|
|
2
|
|
6
|
use Log::Fine; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
27
|
|
44
|
2
|
|
|
2
|
|
5
|
use Log::Fine::Formatter; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
27
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#use Log::Fine::Levels; |
47
|
2
|
|
|
2
|
|
5
|
use Log::Fine::Logger; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
30
|
|
48
|
2
|
|
|
2
|
|
4
|
use POSIX qw( strftime ); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
8
|
|
49
|
2
|
|
|
2
|
|
819
|
use Sys::Hostname; |
|
2
|
|
|
|
|
1409
|
|
|
2
|
|
|
|
|
114
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
our $VERSION = $Log::Fine::Formatter::VERSION; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Constant: LOG_TIMESTAMP_FORMAT |
54
|
|
|
|
|
|
|
# |
55
|
|
|
|
|
|
|
# strftime(3)-compatible format string |
56
|
2
|
50
|
|
|
|
269
|
use constant LOG_TIMESTAMP_FORMAT => ($^O eq "MSWin32") |
57
|
|
|
|
|
|
|
? "%b %d %H:%M:%S" |
58
|
2
|
|
|
2
|
|
8
|
: "%b %e %T"; |
|
2
|
|
|
|
|
2
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 METHODS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 format |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Formats the given message for the given level |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head3 Parameters |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=over |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item * level |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Level at which to log (see L) |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item * message |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Message to log |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=item * skip |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Controls caller skip level |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=back |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head3 Returns |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
The formatted text string in the form: |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
[]: > |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub format |
93
|
|
|
|
|
|
|
{ |
94
|
|
|
|
|
|
|
|
95
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
96
|
1
|
|
|
|
|
2
|
my $lvl = shift; |
97
|
1
|
|
|
|
|
1
|
my $msg = shift; |
98
|
1
|
50
|
|
|
|
4
|
my $skip = (defined $_[0]) ? shift : Log::Fine::Logger->LOG_SKIP_DEFAULT; |
99
|
|
|
|
|
|
|
|
100
|
1
|
|
|
|
|
5
|
my $host = (split(/\./, hostname))[0]; |
101
|
|
|
|
|
|
|
|
102
|
1
|
|
|
|
|
18
|
return sprintf("%s %s %s[%d]: %s\n", $self->_formatTime(), $host, basename($0), $$, $msg); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
} # format() |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 BUGS |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
109
|
|
|
|
|
|
|
C, or through the web interface at |
110
|
|
|
|
|
|
|
L. |
111
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
112
|
|
|
|
|
|
|
your bug as I make changes. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 SUPPORT |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
perldoc Log::Fine |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
You can also look for information at: |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=over 4 |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
L |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * CPAN Ratings |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
L |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
L |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item * Search CPAN |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
L |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=back |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 AUTHOR |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Christopher M. Fuhrman, C<< >> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 SEE ALSO |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
L, L |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Copyright (c) 2008-2010, 2013 Christopher M. Fuhrman, |
153
|
|
|
|
|
|
|
All rights reserved. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
This program is free software licensed under the... |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
The BSD License |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
The full text of the license can be found in the |
160
|
|
|
|
|
|
|
LICENSE file included with this module. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
1; # End of Log::Fine::Formatter::Syslog |