Delegate/Stdout.pm

filter: Statementstmt 68.0% 17 / 25 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 100% 1 / 1 totaltotal 62.1% 23 / 37 CC 3 SCAR 11.7
CC
3
Cov
59%
_write
6.0
test
6.0
BEGIN
1.0
CRAP 3.2
« Delegate/Stderr.pm ↑ Summary
1 #================================ Stdout.pm ===================================
2 # Filename: Stdout.pm
3 # Description: Stdout print logger delegate.
4 # Original Author: Dale M. Amon
5 # Revised by: $Author: amon $
6 # Date: $Date: 2008-08-30 19:22:27 $
7 # Version: $Revision: 1.7 $
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 Fault::DebugPrinter;
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::Msg;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 package Fault::Delegate::Stdout;
17 1 ▶use vars qw{@ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 @ISA = qw( Fault::Delegate );
19  
20 #=============================================================================
21 # Family internal methods
22 #=============================================================================
23 # Warn is used here because if you can't even print to stdout you are probably
24 # effed so you might as well punt directly to Perl and see if it can do any
25 # better!
26  
27 0 ▶sub _write ($$) {
Subroutine _write: not called CC=2 SCAR=17.9
28 0 my ($self,$msg) = @_;
29 0 my $line = $msg->stamped_log_line;
30  
31 0 ▶ if (!print "$line\n") {
Branch: 1 branch
BranchTrueFalseTotal
unless (print "$line\n") 0 0 0
32 0 warn ("$0: Failed to log message to stdout: \'$line\'!\n");
33 0 return 0;
34 }
35 0 return 1;
36 }
37  
38 #-----------------------------------------------------------------------------
39 # Override so we only print annoying init message on the terminal if we are
40 # debugging.
41  
42 0 ▶sub test ($) {
Subroutine test: not called CC=2 SCAR=17.9
Pod documented
43 0 my $s = shift;
44 0 ▶ (Fault::DebugPrinter->level > 0) ? $s->SUPER::test : 1;
Branch: 1 branch
BranchTrueFalseTotal
'Fault::DebugPrinter'->level > 0 ? : 0 0 0
45 }
46  
47 #=============================================================================
48 # Primary Logger Callback Methods
49 #=============================================================================
50 # Utilizes Fault::Delegate parent methods with subclass overrides seen above.
51
52 #=============================================================================
53 # Pod Documentation
54 #=============================================================================
55 # You may extract and format the documentation section with the 'perldoc' cmd.
56  
57 =head1 NAME
58  
59 Fault::Delegate::Stdout - Print logger delegate.
60  
61 =head1 SYNOPSIS
62  
63 use Fault::Delegate::Stdout;
64 $self = Fault::Delegate::Stdout->new;
65 $okay = $self->log ($msg);
66 $bool = $self->test;
67  
68 =head1 Inheritance
69  
70 UNIVERSAL
71 Fault::Delegate
72 Fault::Delegate::Stdout
73  
74 =head1 Description
75  
76 This is a Logger delegate that writes all the log messages to stdout. It is
77 Logger's default delegate if no other is given. It is also a pretty good
78 one to start with when you are trying to understand how this system works.
79  
80 It satisfies the absolute minimum requirements of the Fault::Delegate logger
81 delegate protocol.
82  
83 =head1 Examples
84  
85 use Fault::Delegate::Stdout;
86 use Fault::Logger;
87 use Fault::Msg;
88  
89 my $msg = Fault::Msg ("Arf!");
90 my $baz = Fault::Delegate::Stdout->new ("/tmp/mylogfile");
91 my $waslogged = $baz->log ($msg);
92  
93 Fault::Logger->new ($baz);
94 my $waslogged = Fault::Logger->log ("Bow! Wow!");
95  
96 =head1 Instance Variables
97  
98 None.
99  
100 =head1 Class Methods
101  
102 =over 4
103  
104 =item B<$delegate = Fault::Delegate::Stdout-E<gt>new>
105  
106 Create a logger delegate object that prints log messages to stdout. Prints
107 a warning message and returns undef on failure.
108  
109 =back 4
110  
111 =head1 Logger Protocol Instance Methods
112  
113 =over 4
114  
115 =item B<$okay = $self-E<gt>log ($msg)>
116  
117 Print a time-stamped message to stdout using information
118 taken from Fault::Msg object $msg in the format:
119  
120 $date $time UTC> $process: $type($priority): $msg\n
121  
122 for example:
123  
124 20021207 223010 UTC> MyProcess: NOTE(notice): Nothing happened today.\n
125  
126 Return true if the message was printed.
127  
128 =back 4
129  
130 =head1 Private Class Methods
131  
132 None.
133  
134 =head1 Private Instance Methods
135  
136 =over 4
137  
138 =item B<$bool = $self-E<gt>test>
139  
140 If the debug level has been set to at least one in Fault::DebugPrinter,
141 it executes the test method of the parent, Fault::Delegate class. Otherwise
142 it always returns true. This was added so that an annoying initial message
143 from the Fault system will not be printed on a terminal unless it is
144 actually wanted for debugging purposees.
145  
146 =item B<$bool = $self-E<gt>test>
147  
148 Executes a _connect, a log write and a _disconnect. It returns true if
149 this succeeds. This is useful in personalized subclass new methods.
150  
151 =item B<$bool = $self-E<gt>_write ($msg)>
152  
153 Impliments the above override to the internal family protocol utilized by
154 the Fault:Delegate log and test methods.
155  
156 =back 4
157  
158 =head1 Errors and Warnings
159  
160 Local warning messages are issued if the sys logger cannot be reached or has
161 any problems whatever.
162  
163 =head1 KNOWN BUGS
164  
165 See TODO.
166  
167 =head1 SEE ALSO
168  
169 Fault::Logger, Fault::Delegate, Fault::Msg
170  
171 =head1 AUTHOR
172  
173 Dale Amon <amon@vnl.com>
174  
175 =cut
176
177 #=============================================================================
178 # CVS HISTORY
179 #=============================================================================
180 # $Log: Stdout.pm,v $
181 # Revision 1.7 2008-08-30 19:22:27 amon
182 # Prevent test method from printing to terminal unless debugging.
183 #
184 # Revision 1.6 2008-08-28 23:20:19 amon
185 # perldoc section regularization.
186 #
187 # Revision 1.5 2008-08-17 21:56:37 amon
188 # Make all titles fit CPAN standard.
189 #
190 # Revision 1.4 2008-05-07 18:14:55 amon
191 # Simplification and standardization. Much more is inherited from
192 # Fault::Delegate.
193 #
194 # Revision 1.3 2008-05-04 14:40:56 amon
195 # Updates to perl doc; dropped subclass new method..
196 #
197 # Revision 1.2 2008-05-03 00:56:57 amon
198 # Changed standard argument ordering.
199 #
200 # Revision 1.1.1.1 2008-05-02 16:36:35 amon
201 # Fault and Log System. Pared off of DMA base lib.
202 #
203 # Revision 1.7 2008-04-18 11:34:39 amon
204 # Wrote logger delegate abstract superclass to simplify the code in all the
205 # delegate classes.
206 #
207 # Revision 1.6 2008-04-11 22:25:23 amon
208 # Add blank line after cut.
209 #
210 # Revision 1.5 2008-04-11 21:17:33 amon
211 # Removed my = 0; my = 1/; from log method. No idea why it was there as
212 # is not used.
213 #
214 # Revision 1.4 2008-04-11 18:56:35 amon
215 # Fixed quoting problem with formfeeds.
216 #
217 # Revision 1.3 2008-04-11 18:39:15 amon
218 # Implimented new standard for headers and trailers.
219 #
220 # Revision 1.2 2008-04-10 15:01:08 amon
221 # Added license to headers, removed claim that the documentation section still
222 # relates to the old doc file.
223 #
224 # 20041203 Dale Amon <amon@vnl.com>
225 # Modified old Document::LogFile code into
226 # a very simple delegate that just prints.
227 1 1;
« Delegate/Stderr.pm ↑ Summary