line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#================================ Stderr.pm =================================== |
2
|
|
|
|
|
|
|
# Filename: Stderr.pm |
3
|
|
|
|
|
|
|
# Description: Stderr 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.4 $ |
8
|
|
|
|
|
|
|
# License: LGPL 2.1, Perl Artistic or BSD |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
#============================================================================= |
11
|
1
|
|
|
1
|
|
541
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
12
|
1
|
|
|
1
|
|
4
|
use Fault::Delegate; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
13
|
1
|
|
|
1
|
|
4
|
use Fault::Msg; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
package Fault::Delegate::Stderr; |
16
|
1
|
|
|
1
|
|
5
|
use vars qw{@ISA}; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
226
|
|
17
|
|
|
|
|
|
|
@ISA = qw( Fault::Delegate ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#============================================================================= |
20
|
|
|
|
|
|
|
# Family internal methods |
21
|
|
|
|
|
|
|
#============================================================================= |
22
|
|
|
|
|
|
|
# Warn is used here because if you can't even print to stderr you are probably |
23
|
|
|
|
|
|
|
# effed so you might as well punt directly to Perl and see if it can do any |
24
|
|
|
|
|
|
|
# better! |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _write ($$) { |
27
|
0
|
|
|
0
|
|
|
my ($self,$msg) = @_; |
28
|
0
|
|
|
|
|
|
my $line = $msg->stamped_log_line; |
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
if (!print STDERR "$line\n") { |
31
|
0
|
|
|
|
|
|
warn ("$0: Failed to log message to stderr: \'$line\'!\n"); |
32
|
0
|
|
|
|
|
|
return 0; |
33
|
|
|
|
|
|
|
} |
34
|
0
|
|
|
|
|
|
return 1; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
38
|
|
|
|
|
|
|
# Override so we only print annoying init message on the terminal if we are |
39
|
|
|
|
|
|
|
# debugging. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub test ($) { |
42
|
0
|
|
|
0
|
1
|
|
my $s = shift; |
43
|
0
|
0
|
|
|
|
|
(Fault::DebugPrinter->level > 0) ? $s->SUPER::test : 1; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#============================================================================= |
47
|
|
|
|
|
|
|
# Primary Logger Callback Methods |
48
|
|
|
|
|
|
|
#============================================================================= |
49
|
|
|
|
|
|
|
# Utilizes Fault::Delegate parent methods with subclass overrides seen above. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#============================================================================= |
52
|
|
|
|
|
|
|
# Pod Documentation |
53
|
|
|
|
|
|
|
#============================================================================= |
54
|
|
|
|
|
|
|
# You may extract and format the documentation section with the 'perldoc' cmd. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 NAME |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Fault::Delegate::Stderr - Stderr print logger delegate. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 SYNOPSIS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
use Fault::Delegate::Stderr; |
63
|
|
|
|
|
|
|
$self = Fault::Delegate::Stderr->new; |
64
|
|
|
|
|
|
|
$okay = $self->log ($msg); |
65
|
|
|
|
|
|
|
$bool = $self->test; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 Inheritance |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
UNIVERSAL |
70
|
|
|
|
|
|
|
Fault::Delegate |
71
|
|
|
|
|
|
|
Fault::Delegate::Stderr |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 Description |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
This is a Logger delegate that writes all the log messages to stderr. It is |
76
|
|
|
|
|
|
|
Logger's default delegate if no other is given. It is also a pretty good |
77
|
|
|
|
|
|
|
one to start with when you are trying to understand how this system works. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
It satisfies the absolute minimum requirements of the Fault::Delegate logger |
80
|
|
|
|
|
|
|
delegate protocol. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 Examples |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
use Fault::Delegate::Stderr; |
85
|
|
|
|
|
|
|
use Fault::Logger; |
86
|
|
|
|
|
|
|
use Fault::Msg; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $msg = Fault::Msg ("Arf!"); |
89
|
|
|
|
|
|
|
my $baz = Fault::Delegate::Stderr->new ("/tmp/mylogfile"); |
90
|
|
|
|
|
|
|
my $waslogged = $baz->log ($msg); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Fault::Logger->new ($baz); |
93
|
|
|
|
|
|
|
my $waslogged = Fault::Logger->log ("Bow! Wow!"); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 Instance Variables |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
None. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 Class Methods |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=over 4 |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item B<$delegate = Fault::Delegate::Stderr-Enew> |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Create a logger delegate object that prints log messages to stderr. Prints |
106
|
|
|
|
|
|
|
a warning message and returns undef on failure. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=back 4 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 Logger Protocol Instance Methods |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=over 4 |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item B<$okay = $self-Elog ($msg)> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Print a time-stamped message to stderr using information |
117
|
|
|
|
|
|
|
taken from Fault::Msg object $msg in the format: |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
$date $time UTC> $process: $type($priority): $msg\n |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
for example: |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
20021207 223010 UTC> MyProcess: NOTE(notice): Nothing happened today.\n |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Return true if the message was printed. |
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-Etest> |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
If the debug level has been set to at least one in Fault::DebugPrinter, |
140
|
|
|
|
|
|
|
it executes the test method of the parent, Fault::Delegate class. Otherwise |
141
|
|
|
|
|
|
|
it always returns true. This was added so that an annoying initial message |
142
|
|
|
|
|
|
|
from the Fault system will not be printed on a terminal unless it is |
143
|
|
|
|
|
|
|
actually wanted for debugging purposees. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item B<$bool = $self-E_write ($msg)> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Impliments the above override to the internal family protocol utilized by |
148
|
|
|
|
|
|
|
the Fault:Delegate log and test methods. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=back 4 |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 Errors and Warnings |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Local warning messages are issued if the sys logger cannot be reached or has |
155
|
|
|
|
|
|
|
any problems whatever. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 KNOWN BUGS |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
See TODO. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 SEE ALSO |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Fault::Logger, Fault::Delegate, Fault::Msg |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 AUTHOR |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Dale Amon |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
#============================================================================= |
172
|
|
|
|
|
|
|
# CVS HISTORY |
173
|
|
|
|
|
|
|
#============================================================================= |
174
|
|
|
|
|
|
|
# $Log: Stderr.pm,v $ |
175
|
|
|
|
|
|
|
# Revision 1.4 2008-08-30 19:22:27 amon |
176
|
|
|
|
|
|
|
# Prevent test method from printing to terminal unless debugging. |
177
|
|
|
|
|
|
|
# |
178
|
|
|
|
|
|
|
# Revision 1.3 2008-08-28 23:20:19 amon |
179
|
|
|
|
|
|
|
# perldoc section regularization. |
180
|
|
|
|
|
|
|
# |
181
|
|
|
|
|
|
|
# Revision 1.2 2008-08-17 21:56:37 amon |
182
|
|
|
|
|
|
|
# Make all titles fit CPAN standard. |
183
|
|
|
|
|
|
|
# |
184
|
|
|
|
|
|
|
# Revision 1.1 2008-07-22 14:32:17 amon |
185
|
|
|
|
|
|
|
# Added Notepad and Delegate::Stderr classes |
186
|
|
|
|
|
|
|
# |
187
|
|
|
|
|
|
|
# 20080722 Dale Amon |
188
|
|
|
|
|
|
|
# Modified old Fault::Delegate::Stdout code |
189
|
|
|
|
|
|
|
# to print to stderr instead of stdout. |
190
|
|
|
|
|
|
|
1; |