CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
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
23#include "CLHEP/Exceptions/ZMexLogger.h"
24#include "CLHEP/Exceptions/ZMexception.h"
25#include "CLHEP/RefCount/ZMhandleTo.h"
26
27#include <iostream>
28#include <string>
29
30// ----------------------------------------------------------------------
31
32
33namespace zmex {
34
35
36// ----------------------------------------------------------------------
37
38
39// -----------------
40// ZMexLogBehavior::
41// -----------------
42
44
46
48ZMexLogBehavior::clone() const { return new ZMexLogBehavior( *this ); }
49
51 return ZMexNOTLOGGED;
52}
53
55 const std::string &
56) {
57 //DEBUG cerr << "ZMexLogBehavior::emit()" << endl;
58
59 // Do nothing with string& (but do it well!):
60 return ZMexNOTLOGGED;
61}
62
63bool ZMexLogBehavior::isTimeDesired() const { return true; }
64bool ZMexLogBehavior::isFilePathDesired() const { return true; }
65
66// --------------
67// ZMexLogNever::
68// --------------
69
72{ ; }
73
75
77ZMexLogNever::clone() const { return new ZMexLogNever( *this ); }
78
80 return ZMexNOTLOGGED; //
81}
82
84 const std::string &
85) {
86 //DEBUG cerr << "ZMexLogNever::emit()" << endl;
87
88 // Do nothing with string& (but do it well!):
89 return ZMexNOTLOGGED;
90}
91
92
93// ---------------
94// ZMexLogAlways::
95// ---------------
96
99, myOs( std::cerr )
100{ ; }
101
104, myOs( os )
105{ ; }
106
108
110ZMexLogAlways::clone() const { return new ZMexLogAlways( *this ); }
111
113 std::string s = x.logMessage(); //
114 if ( s != "" )
115 return emit( s );
116
117 x.logObject();
118 return ZMexLOGGED;
119}
120
122 const std::string & s
123) {
124 //DEBUG cerr << "ZMexLogAlways::emit( \"" << s << "\" )" << endl;
125
126 // Emit the message, flushing the output right away:
127 myOs << s << std::flush;
128 return ZMexLOGGED;
129}
130
131// ---------------
132// ZMexLogTwice::
133// ---------------
134
135ZMexLogTwice::ZMexLogTwice( std::ostream & os1 )
137, myOs1( os1 )
138, myOs2( std::cerr )
139{ ; }
140
141ZMexLogTwice::ZMexLogTwice( std::ostream & os1, std::ostream & os2 )
143, myOs1( os1 )
144, myOs2( os2 )
145{ ; }
146
148
150ZMexLogTwice::clone() const { return new ZMexLogTwice( *this ); }
151
153 std::string s = x.logMessage();
154 if (s != "")
155 return emit( s );
156
157 std::cerr << "WARNING: ZMexLogTwice() does not log in the usual manner for";
158 std::cerr << " SuperEx's.\n\t Its ostreams may not have received logs.\n";
159 x.logObject();
160 return ZMexLOGGED;
161}
162
164 const std::string & s
165) {
166 //DEBUG cerr << "ZMexLogTwice::emit( \"" << s << "\" )" << endl;
167
168 // Emit the message, flushing the output right away:
169 myOs1 << s << std::flush;
170 myOs2 << s << std::flush;
171 return ZMexLOGGED;
172}
173
174
175// ------------------
176// ZMexLogViaParent::
177// ------------------
178
181{ ; }
182
184
186ZMexLogViaParent::clone() const { return new ZMexLogViaParent( *this ); }
187
189 return ZMexLOGVIAPARENT; //
190}
191
192ZMexLogResult ZMexLogViaParent::emit( const std::string & ) {
193 //DEBUG cerr << "ZMexLogViaParent::emit( \"" << s << "\" )" << endl;
194
195 // Bump logging decisions to someone else's logger:
196 return ZMexLOGVIAPARENT;
197}
198
199
200// ------------------
201// ZMexValidationStyle::
202// ------------------
203
206, myOs( std::cerr )
207{ ; }
208
211, myOs( os )
212{ ; }
213
215
217ZMexValidationStyle::clone() const { return new ZMexValidationStyle( *this ); }
218
220 std::string s = x.logMessage();
221 if ( s != "" )
222 return emit( s );
223
224 x.logObject();
225 return ZMexLOGGED;
226}
227
229 const std::string & s
230) {
231 //DEBUG cerr << "ZMexValidationStyle::emit( \"" << s << "\" )" << endl;
232
233 // Emit the message, flushing the output right away:
234 myOs << s << std::flush;
235 return ZMexLOGGED;
236}
237
238bool ZMexValidationStyle::isTimeDesired() const { return false; }
239bool ZMexValidationStyle::isFilePathDesired() const { return false; }
240
241// ------------
242// ZMexLogger::
243// ------------
244
246 const ZMexLogBehavior & desiredBehavior
247)
248: ZMhandleTo<ZMexLogBehavior>( desiredBehavior )
249{ ; }
250 // Construct logger with specified behavior.
251
253 // Destroy logger with its behavior.
254
256 return rep_->emit( exc );
257}
258 // Force the given exception's message into the log.
259
260ZMexLogResult ZMexLogger::emit( const std::string & message ) {
261 return rep_->emit( message );
262}
263 // Force the given message into the log.
264
266 // Grant access to the representation
267 // to permit calling specialized behavior functions.
268
269
270// ----------------------------------------------------------------------
271
272
273} // namespace zmex
ZMexLogBehavior * rep_
Definition: ZMhandleTo.h:39
virtual ZMexLogResult emit(const ZMexception &x)
Definition: ZMexLogger.cc:112
virtual ~ZMexLogAlways()
Definition: ZMexLogger.cc:107
virtual ZMexLogAlways * clone() const
Definition: ZMexLogger.cc:110
virtual ~ZMexLogBehavior()
Definition: ZMexLogger.cc:45
virtual ZMexLogBehavior * clone() const
Definition: ZMexLogger.cc:48
virtual bool isFilePathDesired() const
Definition: ZMexLogger.cc:64
virtual ZMexLogResult emit(const ZMexception &x)
Definition: ZMexLogger.cc:50
virtual bool isTimeDesired() const
Definition: ZMexLogger.cc:63
virtual ~ZMexLogNever()
Definition: ZMexLogger.cc:74
virtual ZMexLogNever * clone() const
Definition: ZMexLogger.cc:77
virtual ZMexLogResult emit(const ZMexception &x)
Definition: ZMexLogger.cc:79
virtual ZMexLogResult emit(const ZMexception &x)
Definition: ZMexLogger.cc:152
ZMexLogTwice(std::ostream &os1)
Definition: ZMexLogger.cc:135
virtual ZMexLogTwice * clone() const
Definition: ZMexLogger.cc:150
virtual ~ZMexLogTwice()
Definition: ZMexLogger.cc:147
virtual ZMexLogResult emit(const ZMexception &x)
Definition: ZMexLogger.cc:188
virtual ~ZMexLogViaParent()
Definition: ZMexLogger.cc:183
virtual ZMexLogViaParent * clone() const
Definition: ZMexLogger.cc:186
ZMexLogBehavior * control()
Definition: ZMexLogger.cc:265
ZMexLogResult emit(const ZMexception &exc)
Definition: ZMexLogger.cc:255
ZMexLogger(const ZMexLogBehavior &desiredBehavior)
Definition: ZMexLogger.cc:245
virtual ZMexLogResult emit(const ZMexception &x)
Definition: ZMexLogger.cc:219
virtual ZMexValidationStyle * clone() const
Definition: ZMexLogger.cc:217
virtual bool isFilePathDesired() const
Definition: ZMexLogger.cc:239
virtual bool isTimeDesired() const
Definition: ZMexLogger.cc:238
virtual void logObject() const
Definition: ZMexception.h:464
virtual std::string logMessage(const std::string optText="") const
Definition: ZMexception.cc:122
Definition: ZMerrno.h:52
ZMexLogResult
Definition: ZMexLogResult.h:19
@ ZMexLOGVIAPARENT
Definition: ZMexLogResult.h:19
@ ZMexNOTLOGGED
Definition: ZMexLogResult.h:19
@ ZMexLOGGED
Definition: ZMexLogResult.h:19