line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#================================ Syslog.pm ================================== |
2
|
|
|
|
|
|
|
# Filename: Syslog.pm |
3
|
|
|
|
|
|
|
# Description: Syslog logger delegate. |
4
|
|
|
|
|
|
|
# Original Author: Dale M. Amon |
5
|
|
|
|
|
|
|
# Revised by: $Author: amon $ |
6
|
|
|
|
|
|
|
# Date: $Date: 2008-08-28 23:20:19 $ |
7
|
|
|
|
|
|
|
# Version: $Revision: 1.9 $ |
8
|
|
|
|
|
|
|
# License: LGPL 2.1, Perl Artistic or BSD |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
#============================================================================= |
11
|
1
|
|
|
1
|
|
542
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
12
|
1
|
|
|
1
|
|
1152
|
use Sys::Syslog; |
|
1
|
|
|
|
|
14893
|
|
|
1
|
|
|
|
|
64
|
|
13
|
1
|
|
|
1
|
|
9
|
use Fault::Delegate; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
14
|
1
|
|
|
1
|
|
5
|
use Fault::ErrorHandler; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
15
|
1
|
|
|
1
|
|
7
|
use Fault::Msg; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package Fault::Delegate::Syslog; |
18
|
1
|
|
|
1
|
|
5
|
use vars qw{@ISA}; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
271
|
|
19
|
|
|
|
|
|
|
@ISA = qw( Fault::Delegate ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#============================================================================= |
22
|
|
|
|
|
|
|
# Family internal methods |
23
|
|
|
|
|
|
|
#============================================================================= |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _write ($$) { |
26
|
0
|
|
|
0
|
|
|
my ($self, $msg) = @_; |
27
|
0
|
|
|
|
|
|
my $m = $msg->unstamped_log_line; |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
if (!Sys::Syslog::syslog ($msg->priority, $m)) { |
30
|
0
|
|
|
|
|
|
($self->warn ("Failed log write: \'$m\' to syslog!")); return 0;} |
|
0
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
return 1; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _connect ($) { |
37
|
0
|
|
|
0
|
|
|
my $self = shift; |
38
|
0
|
0
|
|
|
|
|
if (!$self->{'init'}) { |
39
|
0
|
0
|
|
|
|
|
if (!Sys::Syslog::openlog ("", 'cons,ndelay,pid,perror,user','user')) { |
40
|
0
|
|
|
|
|
|
return 0; |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
|
my $msg = Fault::Msg->new ("Initialized syslog",'INFO','notice'); |
43
|
0
|
0
|
|
|
|
|
$self->{'init'} = 1 if ($self->_write ($msg)); |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
|
return 1; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#============================================================================= |
49
|
|
|
|
|
|
|
# Logger Delegate Protocol |
50
|
|
|
|
|
|
|
#============================================================================= |
51
|
|
|
|
|
|
|
# Utilizes Fault::Delegate parent methods with subclass overrides seen above. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#============================================================================= |
54
|
|
|
|
|
|
|
# Pod Documentation |
55
|
|
|
|
|
|
|
#============================================================================= |
56
|
|
|
|
|
|
|
# You may extract and format the documentation section with the 'perldoc' cmd. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 NAME |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Fault::Delegate::Syslog - Syslog delegate. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 SYNOPSIS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
use Fault::Delegate::Syslog; |
65
|
|
|
|
|
|
|
$self = Fault::Delegate::Syslog->new; |
66
|
|
|
|
|
|
|
$okay = $self->log ($msg); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 Inheritance |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
UNIVERSAL |
71
|
|
|
|
|
|
|
Fault::Delegate |
72
|
|
|
|
|
|
|
Fault::Delegate::Syslog |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 Description |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
This is a delegate that writes log messages to the syslog. Syslogging must be |
77
|
|
|
|
|
|
|
accessible to the calling program. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Fault::Delegate::Syslog satisfies the minimum requirements of the |
80
|
|
|
|
|
|
|
Fault::Delegate logger delegate protocol. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 Examples |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
use Fault::Delegate::Syslog; |
85
|
|
|
|
|
|
|
use Fault::Msg; |
86
|
|
|
|
|
|
|
use Fault::Logger; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $msg = Fault::Msg ("Arf!"); |
89
|
|
|
|
|
|
|
my $baz = Fault::Delegate::Syslog->new; |
90
|
|
|
|
|
|
|
my $waslogged = $baz->log ($msg); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Fault::Logger->new ($baz); |
93
|
|
|
|
|
|
|
my $waslogged = Fault::Logger->log ("Bow! Wow!"); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
[See Fault::Logger for a detailed example.] |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 Instance Variables |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
init True if a syslog connection was succesfully initialized. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 Class Methods |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=over 4 |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item B<$delegate = Fault::Delegate::Syslog-Enew> |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Create a logger delegate object that writes log messages to syslog. |
108
|
|
|
|
|
|
|
A warning is issued if the program cannot initialize and write a startup |
109
|
|
|
|
|
|
|
message to syslog. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Returns undef if it fails to set up the syslog connection. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=back 4 |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 Logger Protocol Instance Methods |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=over 4 |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item B<$didlog = $self-Elog ($msgobj)> |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Send the information contained in $msgobj to syslog at the $priority contained |
122
|
|
|
|
|
|
|
by it and return true if we succeeded in doing so. The message is formatted |
123
|
|
|
|
|
|
|
so that it will appear in the log like this: |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Apr 17 18:00:36 localhost UnspecifiedProcess[12638]: NOTE(notice): Testing syslogger again |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=back 4 |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 Private Class Methods |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
None. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 Private Instance Methods |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=over 4 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item B<$bool = $self-E_write ($msg)> |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item B<$bool = $self-E_connect> |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Impliments the above overrides to the internal family protocol utilized by |
142
|
|
|
|
|
|
|
the Fault:Delegate log and test methods. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=back 4 |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 Errors and Warnings |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Local warning messages are issued if the sys logger cannot be reached or has |
149
|
|
|
|
|
|
|
any problems whatever. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 KNOWN BUGS |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
See TODO. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 SEE ALSO |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Fault::Logger, Fault::Delegate, Fault::Msg, Sys::Syslog |
158
|
|
|
|
|
|
|
Fault::ErrorHandler |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 AUTHOR |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Dale Amon |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
#============================================================================= |
167
|
|
|
|
|
|
|
# CVS HISTORY |
168
|
|
|
|
|
|
|
#============================================================================= |
169
|
|
|
|
|
|
|
# $Log: Syslog.pm,v $ |
170
|
|
|
|
|
|
|
# Revision 1.9 2008-08-28 23:20:19 amon |
171
|
|
|
|
|
|
|
# perldoc section regularization. |
172
|
|
|
|
|
|
|
# |
173
|
|
|
|
|
|
|
# Revision 1.8 2008-08-17 21:56:37 amon |
174
|
|
|
|
|
|
|
# Make all titles fit CPAN standard. |
175
|
|
|
|
|
|
|
# |
176
|
|
|
|
|
|
|
# Revision 1.7 2008-07-24 21:17:24 amon |
177
|
|
|
|
|
|
|
# Moved all todo notes to elsewhere; made Stderr the default delegate instead of Stdout. |
178
|
|
|
|
|
|
|
# |
179
|
|
|
|
|
|
|
# Revision 1.6 2008-05-09 18:24:55 amon |
180
|
|
|
|
|
|
|
# Bugs and changes due to pre-release testing |
181
|
|
|
|
|
|
|
# |
182
|
|
|
|
|
|
|
# Revision 1.5 2008-05-07 18:14:55 amon |
183
|
|
|
|
|
|
|
# Simplification and standardization. Much more is inherited from Fault::Delegate. |
184
|
|
|
|
|
|
|
# |
185
|
|
|
|
|
|
|
# Revision 1.4 2008-05-05 19:25:49 amon |
186
|
|
|
|
|
|
|
# Catch any small changes before implimenting major changes |
187
|
|
|
|
|
|
|
# |
188
|
|
|
|
|
|
|
# Revision 1.3 2008-05-04 14:42:02 amon |
189
|
|
|
|
|
|
|
# Updates to perl doc; dropped subclass new method.. |
190
|
|
|
|
|
|
|
# |
191
|
|
|
|
|
|
|
# Revision 1.2 2008-05-03 00:56:57 amon |
192
|
|
|
|
|
|
|
# Changed standard argument ordering. |
193
|
|
|
|
|
|
|
# |
194
|
|
|
|
|
|
|
# Revision 1.1.1.1 2008-05-02 16:36:01 amon |
195
|
|
|
|
|
|
|
# Fault and Log System. Pared off of DMA base lib. |
196
|
|
|
|
|
|
|
# |
197
|
|
|
|
|
|
|
# Revision 1.6 2008-04-18 11:34:39 amon |
198
|
|
|
|
|
|
|
# Wrote logger delegate abstract superclass to simplify the code in all the |
199
|
|
|
|
|
|
|
# delegate classes. |
200
|
|
|
|
|
|
|
# |
201
|
|
|
|
|
|
|
# Revision 1.5 2008-04-11 22:25:23 amon |
202
|
|
|
|
|
|
|
# Add blank line after cut. |
203
|
|
|
|
|
|
|
# |
204
|
|
|
|
|
|
|
# Revision 1.4 2008-04-11 18:56:35 amon |
205
|
|
|
|
|
|
|
# Fixed quoting problem with formfeeds. |
206
|
|
|
|
|
|
|
# |
207
|
|
|
|
|
|
|
# Revision 1.3 2008-04-11 18:39:15 amon |
208
|
|
|
|
|
|
|
# Implimented new standard for headers and trailers. |
209
|
|
|
|
|
|
|
# |
210
|
|
|
|
|
|
|
# Revision 1.2 2008-04-10 15:01:08 amon |
211
|
|
|
|
|
|
|
# Added license to headers, removed claim that the documentation section still |
212
|
|
|
|
|
|
|
# relates to the old doc file. |
213
|
|
|
|
|
|
|
# |
214
|
|
|
|
|
|
|
# 20041203 Dale Amon |
215
|
|
|
|
|
|
|
# Modified old Document::LogFile code into |
216
|
|
|
|
|
|
|
# a very simple delegate that prints to syslog. |
217
|
|
|
|
|
|
|
# |
218
|
|
|
|
|
|
|
1; |