| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Sys::Syslog::OO; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
19623
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
43
|
|
|
4
|
1
|
|
|
1
|
|
1244
|
use Sys::Syslog qw(:DEFAULT setlogsock); |
|
|
1
|
|
|
|
|
27245
|
|
|
|
1
|
|
|
|
|
148
|
|
|
5
|
1
|
|
|
1
|
|
8
|
use Carp; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
515
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
|
10
|
|
|
|
|
|
|
|
|
11
|
0
|
|
|
0
|
0
|
|
my ($class, $opts) = (@_); |
|
12
|
|
|
|
|
|
|
|
|
13
|
0
|
0
|
|
|
|
|
croak "Sys::Syslog::OO - Must pass in a hash ref of options!" |
|
14
|
|
|
|
|
|
|
unless ref($opts) eq 'HASH'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
0
|
0
|
|
|
|
|
croak "Sys::Syslog::OO - Missing logging facility!" |
|
17
|
|
|
|
|
|
|
if ! defined $opts->{'facility'}; |
|
18
|
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $label = ""; |
|
20
|
|
|
|
|
|
|
|
|
21
|
0
|
0
|
|
|
|
|
if (exists $opts->{'label'}) { |
|
22
|
0
|
|
|
|
|
|
$label = $opts->{'label'}; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
else { |
|
25
|
0
|
|
|
|
|
|
$label = $0; |
|
26
|
0
|
|
|
|
|
|
$label =~ s#.*/##; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
0
|
0
|
|
|
|
if ((exists $opts->{'host'}->{'ip'}) && |
|
30
|
|
|
|
|
|
|
(defined $opts->{'host'}->{'ip'})) { |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
setlogsock($opts->{'host'}->{'proto'}); |
|
33
|
0
|
|
|
|
|
|
$Sys::Syslog::host = $opts->{'host'}->{'ip'}; |
|
34
|
0
|
|
|
|
|
|
openlog($label, 'ndelay pid', $opts->{'facility'}); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
else { |
|
38
|
0
|
|
|
|
|
|
openlog($label, 'pid', $opts->{'facility'}); |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
return bless $opts, $class; |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub debug { |
|
46
|
0
|
|
|
0
|
0
|
|
my ($self, $msg) = @_; |
|
47
|
0
|
|
|
|
|
|
$self->logger('debug', $msg); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub verbose { |
|
51
|
0
|
|
|
0
|
0
|
|
my ($self, $msg) = @_; |
|
52
|
0
|
|
|
|
|
|
$self->info($msg); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub info { |
|
56
|
0
|
|
|
0
|
0
|
|
my ($self, $msg) = @_; |
|
57
|
0
|
|
|
|
|
|
$self->logger('info', $msg); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub error { |
|
61
|
0
|
|
|
0
|
0
|
|
my ($self, $msg) = @_; |
|
62
|
0
|
|
|
|
|
|
$self->logger('err', $msg); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub warn { |
|
66
|
0
|
|
|
0
|
0
|
|
my ($self, $msg) = @_; |
|
67
|
0
|
|
|
|
|
|
$self->logger('warn', $msg); |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub notice { |
|
71
|
0
|
|
|
0
|
0
|
|
my ($self, $msg) = @_; |
|
72
|
0
|
|
|
|
|
|
$self->logger('notice', $msg); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub alert { |
|
76
|
0
|
|
|
0
|
0
|
|
my ($self, $msg) = @_; |
|
77
|
0
|
|
|
|
|
|
$self->logger('alert', $msg); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub logger { |
|
81
|
0
|
|
|
0
|
0
|
|
my ($self, $level, $msg) = (@_); |
|
82
|
0
|
|
|
|
|
|
syslog("${level}|$self->{'facility'}", '%s', "\U$level\E $msg"); |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=pod |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 NAME |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Sys::Syslog::OO - Thin object-oriented wrapper around Sys::Syslog::OO |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
package My::Cool::Package; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
use Sys::Syslog::OO; |
|
99
|
|
|
|
|
|
|
use base qw(Sys::Syslog::OO); |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub new { |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my ($class, $cfg) = @_; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
my $facility = 'LOG_LOCAL7'; |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
if (exists $cfg->{'syslog_facility'}) { |
|
108
|
|
|
|
|
|
|
$facility = $cfg->{'syslog_facility'}; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
my $self = $class->SUPER::new({'label' => 'mycoolprogram', |
|
112
|
|
|
|
|
|
|
'facility' => $facility }); |
|
113
|
|
|
|
|
|
|
# ... other initialization code ... |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
return $self; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Thin OO-wrapper around Sys::Syslog. Why? Less chance of mis-typing |
|
121
|
|
|
|
|
|
|
log levels and less noisy code. Can also be used with multiple-inheritence |
|
122
|
|
|
|
|
|
|
to add logging to a new or existing class. |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 THANKS |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Special thanks to Mike Fischer, Jason Livingood, and Comcast for allowing |
|
127
|
|
|
|
|
|
|
me to contribute this code to the OSS community. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 AUTHOR |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Max Schubert Emaxschube@cpan.orgE |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Copyright (C) 2009 by Max Schubert / Comcast |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
138
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.8 or, |
|
139
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |