line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Log::Fine::Handle::Syslog - Output log messages to syslog |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 SYNOPSIS |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Provides logging to syslog() |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Log::Fine; |
11
|
|
|
|
|
|
|
use Log::Fine::Handle::Syslog; |
12
|
|
|
|
|
|
|
use Sys::Syslog; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Get a new logger |
15
|
|
|
|
|
|
|
my $log = Log::Fine->logger("foo"); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Create a new syslog handle |
18
|
|
|
|
|
|
|
my $handle = Log::Fine::Handle::Syslog |
19
|
|
|
|
|
|
|
->new( name => 'syslog0', |
20
|
|
|
|
|
|
|
mask => LOGMASK_EMERG | LOGMASK_ALERT | LOGMASK_CRIT | LOGMASK_ERR | LOGMASK_WARNING | LOGMASK_NOTICE | LOGMASK_INFO, |
21
|
|
|
|
|
|
|
ident => $0, |
22
|
|
|
|
|
|
|
logopts => 'pid', |
23
|
|
|
|
|
|
|
facility => LOG_LEVEL0 ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Register the handle |
26
|
|
|
|
|
|
|
$log->registerHandle($handle); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Log something |
29
|
|
|
|
|
|
|
$log->(INFO, "Opened new log handle"); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Log::Fine::Handle::Syslog provides logging via the standard UNIX |
34
|
|
|
|
|
|
|
syslog facility. For more information, it is I recommended |
35
|
|
|
|
|
|
|
that you read the L documentation. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
3
|
|
127716
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
67
|
|
40
|
3
|
|
|
3
|
|
9
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
96
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
package Log::Fine::Handle::Syslog; |
43
|
|
|
|
|
|
|
|
44
|
3
|
|
|
3
|
|
9
|
use base qw( Log::Fine::Handle ); |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
738
|
|
45
|
|
|
|
|
|
|
|
46
|
3
|
|
|
3
|
|
13
|
use File::Basename; |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
136
|
|
47
|
3
|
|
|
3
|
|
10
|
use Log::Fine; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
57
|
|
48
|
3
|
|
|
3
|
|
498
|
use Sys::Syslog 0.13 qw( :standard :macros ); |
|
3
|
|
|
|
|
7920
|
|
|
3
|
|
|
|
|
747
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
our $VERSION = $Log::Fine::Handle::VERSION; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Constant: LOG_MAPPING |
53
|
|
|
|
|
|
|
# |
54
|
|
|
|
|
|
|
# Maps Log::Fine LOG_LEVELS to Sys::Syslog equivalents |
55
|
|
|
|
|
|
|
|
56
|
3
|
|
|
|
|
788
|
use constant LOG_MAPPING => { |
57
|
|
|
|
|
|
|
0 => LOG_EMERG, |
58
|
|
|
|
|
|
|
1 => LOG_ALERT, |
59
|
|
|
|
|
|
|
2 => LOG_CRIT, |
60
|
|
|
|
|
|
|
3 => LOG_ERR, |
61
|
|
|
|
|
|
|
4 => LOG_WARNING, |
62
|
|
|
|
|
|
|
5 => LOG_NOTICE, |
63
|
|
|
|
|
|
|
6 => LOG_INFO, |
64
|
|
|
|
|
|
|
7 => LOG_DEBUG, |
65
|
3
|
|
|
3
|
|
13
|
}; |
|
3
|
|
|
|
|
5
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Private Methods |
68
|
|
|
|
|
|
|
# -------------------------------------------------------------------- |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
{ |
71
|
|
|
|
|
|
|
my $flag = 0; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Getter/Setter for flag |
74
|
|
|
|
|
|
|
sub _flag |
75
|
|
|
|
|
|
|
{ |
76
|
6
|
50
|
66
|
6
|
|
29
|
$flag = 1 if (defined $_[0] and $_[0] =~ /\d/ and $_[0] > 0); |
|
|
|
66
|
|
|
|
|
77
|
6
|
|
|
|
|
28
|
return $flag; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# -------------------------------------------------------------------- |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 METHODS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 msgWrite |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
See L |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Note that this method B make use of a formatter as this is |
90
|
|
|
|
|
|
|
handled by the syslog facility. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub msgWrite |
95
|
|
|
|
|
|
|
{ |
96
|
|
|
|
|
|
|
|
97
|
2
|
|
|
2
|
1
|
3
|
my $self = shift; |
98
|
2
|
|
|
|
|
3
|
my $lvl = shift; |
99
|
2
|
|
|
|
|
2
|
my $msg = shift; |
100
|
2
|
|
|
|
|
2
|
my $skip = shift; # NOT USED |
101
|
2
|
|
|
|
|
3
|
my $map = LOG_MAPPING; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Write to syslog |
104
|
2
|
|
|
|
|
9
|
syslog($map->{$lvl}, $msg); |
105
|
|
|
|
|
|
|
|
106
|
2
|
|
|
|
|
521
|
return $self; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
} # msgWrite() |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# -------------------------------------------------------------------- |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
## |
113
|
|
|
|
|
|
|
# Initializes our object |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub _init |
116
|
|
|
|
|
|
|
{ |
117
|
|
|
|
|
|
|
|
118
|
4
|
|
|
4
|
|
6
|
my $self = shift; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# Perform any necessary upper class initializations |
121
|
4
|
|
|
|
|
14
|
$self->SUPER::_init(); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# Make sure we have one and only one syslog object defined |
124
|
4
|
100
|
|
|
|
5
|
$self->_fatal(sprintf("One and _only_ one %s object may be defined", ref $self)) |
125
|
|
|
|
|
|
|
if _flag(); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# Set ident |
128
|
2
|
|
|
|
|
102
|
$self->{ident} = basename $0; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# Set the default logopts (to be passed to Sys::Syslog::openlog() |
131
|
|
|
|
|
|
|
$self->{logopts} = "pid" |
132
|
2
|
50
|
33
|
|
|
11
|
unless (defined $self->{logopts} and $self->{logopts} =~ /\w+/); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# Set the default facility |
135
|
|
|
|
|
|
|
$self->{facility} = LOG_LOCAL0 |
136
|
|
|
|
|
|
|
unless (defined $self->{facility} |
137
|
2
|
100
|
66
|
|
|
12
|
and $self->{facility} =~ /\w+/); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# Open the syslog connection and set flag |
140
|
2
|
|
|
|
|
9
|
openlog($self->{ident}, $self->{logopts}, $self->{facility}); |
141
|
2
|
|
|
|
|
40
|
_flag(1); |
142
|
|
|
|
|
|
|
|
143
|
2
|
|
|
|
|
3
|
return $self; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
} # _init() |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 BUGS |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
150
|
|
|
|
|
|
|
C, or through the web interface at |
151
|
|
|
|
|
|
|
L. |
152
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
153
|
|
|
|
|
|
|
your bug as I make changes. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 SUPPORT |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
perldoc Log::Fine |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
You can also look for information at: |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=over 4 |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
L |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item * CPAN Ratings |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
L |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
L |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item * Search CPAN |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
L |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=back |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 AUTHOR |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Christopher M. Fuhrman, C<< >> |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 SEE ALSO |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
L, L, L |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Copyright (c) 2008, 2010, 2013 Christopher M. Fuhrman, |
194
|
|
|
|
|
|
|
All rights reserved. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
This program is free software licensed under the... |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
The BSD License |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
The full text of the license can be found in the |
201
|
|
|
|
|
|
|
LICENSE file included with this module. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
1; # End of Log::Fine::Handle::Syslog |