CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

ZMexLogger.cc
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2//
3// ZMexLogger.cc - define basic logging behaviors
4//
5// History:
6// 970919 WEB Created based on code review 4 comments on
7// ZMexLogger behavior desired
8// 971007 WEB Removed limiting logger; all loggers now
9// optionally limit by exception severity
10// 971211 WEB Updated per code walkthrough
11// 971211 WEB Created from ZMexLogger.icc per code walkthrough
12// 971215 WEB Removed unused 2nd parm to ZMexLogger constructor
13// 971219 WEB Use std::flush instead of endl in ...::emit()
14// 980617 WEB Added namespace support
15// 990104 WEB Merged with .icc; restructured os data member
16// ownership
17// 990802 JVR Added support for augmented exception logging
18// 010410 MF Added ZMexValidationStyle
19//
20// ----------------------------------------------------------------------
21
22
25
26
27// ----------------------------------------------------------------------
28
29
30namespace zmex {
31
32
33// ----------------------------------------------------------------------
34
35
36// -----------------
37// ZMexLogBehavior::
38// -----------------
39
41
43
45ZMexLogBehavior::clone() const { return new ZMexLogBehavior( *this ); }
46
50
52 const std::string &
53) {
54 //DEBUG cerr << "ZMexLogBehavior::emit()" << endl;
55
56 // Do nothing with string& (but do it well!):
57 return ZMexNOTLOGGED;
58}
59
60bool ZMexLogBehavior::isTimeDesired() const { return true; }
61bool ZMexLogBehavior::isFilePathDesired() const { return true; }
62
63// --------------
64// ZMexLogNever::
65// --------------
66
70
72
74ZMexLogNever::clone() const { return new ZMexLogNever( *this ); }
75
79
81 const std::string &
82) {
83 //DEBUG cerr << "ZMexLogNever::emit()" << endl;
84
85 // Do nothing with string& (but do it well!):
86 return ZMexNOTLOGGED;
87}
88
89
90// ---------------
91// ZMexLogAlways::
92// ---------------
93
96, myOs( std::cerr )
97{ ; }
98
99ZMexLogAlways::ZMexLogAlways( std::ostream & os )
101, myOs( os )
102{ ; }
103
105
107ZMexLogAlways::clone() const { return new ZMexLogAlways( *this ); }
108
110 std::string s = x.logMessage(); //
111 if ( s != "" )
112 return emit( s );
113
114 x.logObject();
115 return ZMexLOGGED;
116}
117
119 const std::string & s
120) {
121 //DEBUG cerr << "ZMexLogAlways::emit( \"" << s << "\" )" << endl;
122
123 // Emit the message, flushing the output right away:
124 myOs << s << std::flush;
125 return ZMexLOGGED;
126}
127
128// ---------------
129// ZMexLogTwice::
130// ---------------
131
132ZMexLogTwice::ZMexLogTwice( std::ostream & os1 )
134, myOs1( os1 )
135, myOs2( std::cerr )
136{ ; }
137
138ZMexLogTwice::ZMexLogTwice( std::ostream & os1, std::ostream & os2 )
140, myOs1( os1 )
141, myOs2( os2 )
142{ ; }
143
145
147ZMexLogTwice::clone() const { return new ZMexLogTwice( *this ); }
148
150 std::string s = x.logMessage();
151 if (s != "")
152 return emit( s );
153
154 std::cerr << "WARNING: ZMexLogTwice() does not log in the usual manner for";
155 std::cerr << " SuperEx's.\n\t Its ostreams may not have received logs.\n";
156 x.logObject();
157 return ZMexLOGGED;
158}
159
161 const std::string & s
162) {
163 //DEBUG cerr << "ZMexLogTwice::emit( \"" << s << "\" )" << endl;
164
165 // Emit the message, flushing the output right away:
166 myOs1 << s << std::flush;
167 myOs2 << s << std::flush;
168 return ZMexLOGGED;
169}
170
171
172// ------------------
173// ZMexLogViaParent::
174// ------------------
175
179
181
183ZMexLogViaParent::clone() const { return new ZMexLogViaParent( *this ); }
184
188
189ZMexLogResult ZMexLogViaParent::emit( const std::string & ) {
190 //DEBUG cerr << "ZMexLogViaParent::emit( \"" << s << "\" )" << endl;
191
192 // Bump logging decisions to someone else's logger:
193 return ZMexLOGVIAPARENT;
194}
195
196
197// ------------------
198// ZMexValidationStyle::
199// ------------------
200
203, myOs( std::cerr )
204{ ; }
205
208, myOs( os )
209{ ; }
210
212
214ZMexValidationStyle::clone() const { return new ZMexValidationStyle( *this ); }
215
217 std::string s = x.logMessage();
218 if ( s != "" )
219 return emit( s );
220
221 x.logObject();
222 return ZMexLOGGED;
223}
224
226 const std::string & s
227) {
228 //DEBUG cerr << "ZMexValidationStyle::emit( \"" << s << "\" )" << endl;
229
230 // Emit the message, flushing the output right away:
231 myOs << s << std::flush;
232 return ZMexLOGGED;
233}
234
235bool ZMexValidationStyle::isTimeDesired() const { return false; }
236bool ZMexValidationStyle::isFilePathDesired() const { return false; }
237
238// ------------
239// ZMexLogger::
240// ------------
241
243 const ZMexLogBehavior & desiredBehavior
244)
245: ZMhandleTo<ZMexLogBehavior>( desiredBehavior )
246{ ; }
247 // Construct logger with specified behavior.
248
250 // Destroy logger with its behavior.
251
253 return rep_->emit( exc );
254}
255 // Force the given exception's message into the log.
256
257ZMexLogResult ZMexLogger::emit( const std::string & message ) {
258 return rep_->emit( message );
259}
260 // Force the given message into the log.
261
263 // Grant access to the representation
264 // to permit calling specialized behavior functions.
265
266
267// ----------------------------------------------------------------------
268
269
270} // namespace zmex
virtual ZMexLogResult emit(const ZMexception &x)
virtual ~ZMexLogAlways()
virtual ZMexLogAlways * clone() const
virtual ~ZMexLogBehavior()
Definition ZMexLogger.cc:42
virtual ZMexLogBehavior * clone() const
Definition ZMexLogger.cc:45
virtual bool isFilePathDesired() const
Definition ZMexLogger.cc:61
virtual ZMexLogResult emit(const ZMexception &x)
Definition ZMexLogger.cc:47
virtual bool isTimeDesired() const
Definition ZMexLogger.cc:60
virtual ~ZMexLogNever()
Definition ZMexLogger.cc:71
virtual ZMexLogNever * clone() const
Definition ZMexLogger.cc:74
virtual ZMexLogResult emit(const ZMexception &x)
Definition ZMexLogger.cc:76
virtual ZMexLogResult emit(const ZMexception &x)
ZMexLogTwice(std::ostream &os1)
virtual ZMexLogTwice * clone() const
virtual ~ZMexLogTwice()
virtual ZMexLogResult emit(const ZMexception &x)
virtual ZMexLogViaParent * clone() const
ZMexLogBehavior * control()
ZMexLogResult emit(const ZMexception &exc)
ZMexLogger(const ZMexLogBehavior &desiredBehavior)
virtual ZMexLogResult emit(const ZMexception &x)
virtual ZMexValidationStyle * clone() const
virtual bool isFilePathDesired() const
virtual bool isTimeDesired() const
virtual std::string logMessage(const std::string optText="") const