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 
30 namespace zmex {
31 
32 
33 // ----------------------------------------------------------------------
34 
35 
36 // -----------------
37 // ZMexLogBehavior::
38 // -----------------
39 
41 
43 
45 ZMexLogBehavior::clone() const { return new ZMexLogBehavior( *this ); }
46 
48  return ZMexNOTLOGGED;
49 }
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 
60 bool ZMexLogBehavior::isTimeDesired() const { return true; }
61 bool ZMexLogBehavior::isFilePathDesired() const { return true; }
62 
63 // --------------
64 // ZMexLogNever::
65 // --------------
66 
69 { ; }
70 
72 
74 ZMexLogNever::clone() const { return new ZMexLogNever( *this ); }
75 
77  return ZMexNOTLOGGED; //
78 }
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 
99 ZMexLogAlways::ZMexLogAlways( std::ostream & os )
100 : ZMexLogBehavior()
101 , myOs( os )
102 { ; }
103 
105 
107 ZMexLogAlways::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 
132 ZMexLogTwice::ZMexLogTwice( std::ostream & os1 )
133 : ZMexLogBehavior()
134 , myOs1( os1 )
135 , myOs2( std::cerr )
136 { ; }
137 
138 ZMexLogTwice::ZMexLogTwice( std::ostream & os1, std::ostream & os2 )
139 : ZMexLogBehavior()
140 , myOs1( os1 )
141 , myOs2( os2 )
142 { ; }
143 
145 
146 ZMexLogTwice *
147 ZMexLogTwice::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 
177 : ZMexLogBehavior()
178 { ; }
179 
181 
183 ZMexLogViaParent::clone() const { return new ZMexLogViaParent( *this ); }
184 
186  return ZMexLOGVIAPARENT; //
187 }
188 
189 ZMexLogResult 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 
202 : ZMexLogBehavior()
203 , myOs( std::cerr )
204 { ; }
205 
207 : ZMexLogBehavior()
208 , myOs( os )
209 { ; }
210 
212 
214 ZMexValidationStyle::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 
235 bool ZMexValidationStyle::isTimeDesired() const { return false; }
236 bool 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 
257 ZMexLogResult 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)
Definition: ZMexLogger.cc:109
virtual ~ZMexLogAlways()
Definition: ZMexLogger.cc:104
virtual ZMexLogAlways * clone() const
Definition: ZMexLogger.cc:107
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)
Definition: ZMexLogger.cc:149
ZMexLogTwice(std::ostream &os1)
Definition: ZMexLogger.cc:132
virtual ZMexLogTwice * clone() const
Definition: ZMexLogger.cc:147
virtual ~ZMexLogTwice()
Definition: ZMexLogger.cc:144
virtual ZMexLogResult emit(const ZMexception &x)
Definition: ZMexLogger.cc:185
virtual ~ZMexLogViaParent()
Definition: ZMexLogger.cc:180
virtual ZMexLogViaParent * clone() const
Definition: ZMexLogger.cc:183
ZMexLogBehavior * control()
Definition: ZMexLogger.cc:262
ZMexLogResult emit(const ZMexception &exc)
Definition: ZMexLogger.cc:252
ZMexLogger(const ZMexLogBehavior &desiredBehavior)
Definition: ZMexLogger.cc:242
virtual ZMexLogResult emit(const ZMexception &x)
Definition: ZMexLogger.cc:216
virtual ZMexValidationStyle * clone() const
Definition: ZMexLogger.cc:214
virtual bool isFilePathDesired() const
Definition: ZMexLogger.cc:236
virtual bool isTimeDesired() const
Definition: ZMexLogger.cc:235
virtual void logObject() const
virtual std::string logMessage(const std::string optText="") const
Definition: ZMexception.cc:120