Delegate/Syslog.pm

filter: Statementstmt 60.6% 20 / 33 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod n/a totaltotal 53.0% 26 / 49 CC 5 SCAR 21.0
CC
5
Cov
49%
_connect
20.0
_write
6.0
BEGIN
1.0
CRAP 8.2
« ErrorHandler.pm ↑ Summary Notepad.pm »
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Sys::Syslog;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Fault::Delegate;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Fault::ErrorHandler;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Fault::Msg;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 package Fault::Delegate::Syslog;
18 1 ▶use vars qw{@ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 @ISA = qw( Fault::Delegate );
20  
21 #=============================================================================
22 # Family internal methods
23 #=============================================================================
24  
25 0 ▶sub _write ($$) {
Subroutine _write: not called CC=2 SCAR=17.9
26 0 my ($self, $msg) = @_;
27 0 my $m = $msg->unstamped_log_line;
28  
29 0 ▶ if (!Sys::Syslog::syslog ($msg->priority, $m)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Sys::Syslog::syslog($msg->priority, $m)) 0 0 0
30 0 ($self->warn ("Failed log write: \'$m\' to syslog!")); return 0;}
31 0 return 1;
32 }
33  
34 #-----------------------------------------------------------------------------
35  
36 0 ▶sub _connect ($) {
Subroutine _connect: not called CC=4 SCAR=30.0
37 0 my $self = shift;
38 0 ▶ if (!$self->{'init'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"init"}) 0 0 0
39 0 ▶ if (!Sys::Syslog::openlog ("", 'cons,ndelay,pid,perror,user','user')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Sys::Syslog::openlog("", "cons,ndelay,pid,perror,user", "user")) 0 0 0
40 0 return 0;
41 }
42 0 my $msg = Fault::Msg->new ("Initialized syslog",'INFO','notice');
43 0 ▶ $self->{'init'} = 1 if ($self->_write ($msg));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_write($msg) 0 0 0
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-E<gt>new>
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-E<gt>log ($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<gt>_write ($msg)>
138  
139 =item B<$bool = $self-E<gt>_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 <amon@vnl.com>
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 <amon@vnl.com>
215 # Modified old Document::LogFile code into
216 # a very simple delegate that prints to syslog.
217 #
218 1 1;
« ErrorHandler.pm ↑ Summary Notepad.pm »