CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ErrorLog.cc
Go to the documentation of this file.
1 // ----------------------------------------------------------------------
2 //
3 // ErrorLog.cc
4 //
5 // Created 7/7/98 mf
6 // 5/2/99 web Added non-default constructor.
7 // 6/16/99 jvr Attaches a destination when an ErrorObj is logged and no
8 // destinations are attached $$ jvr
9 // 6/6/00 web Reflect consolidation of ELadministrator/X; consolidate
10 // ErrorLog/X
11 // 6/12/00 web Attach cerr, rather than cout, in case of no previously-
12 // attached destination
13 // 6/14/00 web Append missing quote on conditional output
14 // 3/13/01 mf hexTrigger and related global methods
15 // 3/13/01 mf setDiscardThreshold(), and discardThreshold mechanism
16 // 3/14/01 web g/setfill(0)/s//setfill('0')/g; move #include <string>
17 // 3/14/01 web Insert missing initializers in constructor
18 // 5/7/01 mf operator<< (const char[])
19 // 6/7/01 mf operator()(ErrorObj&) should have been doing level bookkeeping
20 // and abort checking; inserted this code
21 // 11/15/01 mf static_cast to unsigned int and long in comparisons in
22 // operator<<( ErrorLog & e, unsigned int n) and long, and
23 // also rwriting 0xFFFFFFFF as 0xFFFFFFFFL when comparing to a
24 // long. THese cure warnings when -Wall -pedantic are turned on.
25 // 3/06/01 mf getELdestControl() forwards to *a
26 // 12/3/02 mf discardVerbosityLevel, and items related to operator()(int)
27 // 6/23/03 mf moduleName() and subroutineName()
28 // 3/17/04 mf spaces after ints.
29 // 3/17/04 mf exit threshold
30 //
31 // --- CMS
32 //
33 // 12/12/05 mf replace exit() with throw
34 //
35 // ----------------------------------------------------------------------
36 
37 
44 
46 
47 #include <iostream>
48 #include <iomanip>
49 
50 // Possible Traces:
51 // #define ErrorLogCONSTRUCTOR_TRACE
52 // #define ErrorLogOUTPUT_TRACE
53 // #define ErrorLogENDMSG_TRACE
54 // #define ErrorLogEMIT_TRACE
55 
56 #ifdef ErrorLog_EMIT_TRACE
57  #include <string>
58 #endif
59 
60 namespace edm {
61 namespace service {
62 
63 
64 
65 // ----------------------------------------------------------------------
66 // ErrorLog:
67 // ----------------------------------------------------------------------
68 
71 , subroutine( "" )
72 , module( "" )
73 , hexTrigger(-1)
74 , spaceAfterInt(false)
75 , discardThreshold (ELzeroSeverity)
76 , discarding (false)
77 , debugVerbosityLevel(0)
78 , debugSeverityLevel(ELinfo)
79 , debugMessageId ("DEBUG")
80 {
81 
82  #ifdef ErrorLogCONSTRUCTOR_TRACE
83  std::cout << "Constructor for ErrorLog\n";
84  #endif
85 
86 } // ErrorLog()
87 
88 ErrorLog::ErrorLog( const ELstring & pkgName )
90 , subroutine( "" )
91 , module( pkgName )
92 , hexTrigger(-1)
93 , spaceAfterInt(false)
94 , discardThreshold (ELzeroSeverity)
95 , discarding (false)
96 , debugVerbosityLevel(0)
97 , debugSeverityLevel(ELinfo)
98 , debugMessageId ("DEBUG")
99 {
100 
101  #ifdef ErrorLogCONSTRUCTOR_TRACE
102  std::cout << "Constructor for ErrorLog (with pkgName = " << pkgName << ")\n";
103  #endif
104 
105 } // ErrorLog()
106 
107 
109 
110  #ifdef ErrorLogCONSTRUCTOR_TRACE
111  std::cout << "Destructor for ErrorLog\n";
112  #endif
113 
114 } // ~ErrorLog()
115 
117  const ELseverityLevel & sev
118 , const ELstring & id )
119 {
120 
121  if ( sev < discardThreshold ) {
122  discarding = true;
123  return *this;
124  }
125 
126  discarding = false;
127 
128  #ifdef ErrorLogENDMSG_TRACE
129  std::cout << "=:=:=: precautionary endmsg ( "
130  << sev.getName() << ", " << id << ")\n";
131  #endif
132 
133  endmsg(); // precautionary
134 
135  // ----- form ErrorObj for this new message:
136  //
137  a->msgIsActive = true;
138  a->msg.set ( sev, id );
139  a->msg.setProcess ( a->process() );
140  a->msg.setModule ( module );
142  a->msg.setReactedTo ( false );
143 
144  return *this;
145 
146 } // operator()( sev, id )
147 
148 
149 void ErrorLog::setSubroutine( const ELstring & subName ) {
150 
151  subroutine = subName;
152 
153 } // setSubroutine()
154 
155 static inline void msgexit(int s) {
156  std::ostringstream os;
157  os << "msgexit - MessageLogger Log requested to exit with status " << s;
159  throw e;
160 }
161 
162 static inline void msgabort() {
163  std::ostringstream os;
164  os << "msgabort - MessageLogger Log requested to abort";
166  throw e;
167 }
168 
169 static inline void possiblyAbOrEx (int s, int a, int e) {
170  if (s < a && s < e) return;
171  if (a < e) {
172  if ( s < e ) msgabort();
173  msgexit(s);
174  } else {
175  if ( s < a ) msgexit(s);
176  msgabort();
177  }
178 }
179 
181 
182  #ifdef ErrorLogENDMSG_TRACE
183  std::cout << "=:=:=: precautionary endmsg called from operator() (msg) \n";
184  #endif
185 
186  endmsg(); // precautionary
187 
188  // ----- will we need to poke/restore info into the message?
189  //
190  bool updateProcess ( msg.xid().process .length() == 0 );
191  bool updateModule ( msg.xid().module .length() == 0 );
192  bool updateSubroutine( msg.xid().subroutine.length() == 0 );
193 
194  // ----- poke, if needed:
195  //
196  if ( updateProcess ) msg.setProcess ( a->process() );
197  if ( updateModule ) msg.setModule ( module );
198  if ( updateSubroutine ) msg.setSubroutine( subroutine );
199 
200  // severity level statistics keeping: // $$ mf 6/7/01
201  int lev = msg.xid().severity.getLevel();
202  ++ a->severityCounts_[lev];
203  if ( lev > a->highSeverity_.getLevel() )
204  a->highSeverity_ = msg.xid().severity;
205 
206  a->context_->editErrorObj( msg );
207 
208  // ----- send the message to each destination:
209  //
210  if (a->sinks().begin() == a->sinks().end()) {
211  std::cerr << "\nERROR LOGGED WITHOUT DESTINATION!\n";
212  std::cerr << "Attaching destination \"cerr\" to ELadministrator by default\n"
213  << std::endl;
215  }
216  std::list<boost::shared_ptr<ELdestination> >::iterator d;
217  for ( d = a->sinks().begin(); d != a->sinks().end(); ++d )
218  if ( (*d)->log( msg ) )
219  msg.setReactedTo ( true );
220 
223  a->exitThreshold().getLevel() ); // $$ mf 3/17/04
224 
225  // ----- restore, if we poked above:
226  //
227  if ( updateProcess ) msg.setProcess( "" );
228  if ( updateModule ) msg.setModule( "" );
229  if ( updateSubroutine ) msg.setSubroutine( "" );
230 
231  return *this;
232 
233 } // operator()( )
234 
235 
236 void ErrorLog::setModule( const ELstring & modName ) {
237 
238  module = modName;
239 
240 } // setModule()
241 
242 
243 void ErrorLog::setPackage( const ELstring & pkgName ) {
244 
245  setModule( pkgName );
246 
247 } // setPackage()
248 
249 
250 ErrorLog & ErrorLog::operator() (int nbytes, char * data) {
251 
252  ELrecv ( nbytes, data, module );
253  return *this;
254 
255 } // operator() (nbytes, data)
256 
258  #ifdef ErrorLogOUTPUT_TRACE
259  std::cout << "=:=:=: ErrorLog output trace: f at " << std::hex << f
260  << std::endl;
261  #endif
262  if (discarding) return *this;
263  f( *this );
264  return *this;
265 
266 } // operator<<()
267 
268 
270 
271  #ifdef ErrorLogEMIT_TRACE
272  std::cout << " =:=:=: ErrorLog emit trace: string is: " << s << "\n";
273  #endif
274 
275  if ( ! a->msgIsActive )
276  (*this) ( ELunspecified, "..." );
277 
278  a->msg.emitToken( s );
279 
280  #ifdef ErrorLogEMIT_TRACE
281  std::cout << " =:=:=: ErrorLog emit trace: return from a->msg.emitToken()\n";
282  #endif
283 
284  return *this;
285 
286 } // emitToken()
287 
288 
290 
291  #ifdef ErrorLogENDMSG_TRACE
292  std::cout << "=:=:=: endmsg () -- msgIsActive = " << a->msgIsActive
293  << std::endl;
294  #endif
295 
296  if ( a->msgIsActive ) {
297  #ifdef ErrorLogENDMSG_TRACE
298  std::cout << "=:=:=: endmsg () -- finishMsg started\n";
299  #endif
300  a->finishMsg();
301  #ifdef ErrorLogENDMSG_TRACE
302  std::cout << "=:=:=: endmsg () -- finishMsg completed\n";
303  #endif
304  a->clearMsg();
305  }
306  return *this;
307 
308 } // endmsg()
309 
310 // ----------------------------------------------------------------------
311 // Advanced Control Options:
312 // ----------------------------------------------------------------------
313 
314 bool ErrorLog::setSpaceAfterInt(bool space) {
315  bool temp = spaceAfterInt;
316  spaceAfterInt = space;
317  return temp;
318 }
319 
320 int ErrorLog::setHexTrigger (int trigger) {
321  int oldTrigger = hexTrigger;
322  hexTrigger = trigger;
323  return oldTrigger;
324 }
325 
328  discardThreshold = sev;
329  return oldSev;
330 }
331 
334 }
335 
337  debugSeverityLevel = sev;
338  debugMessageId = id;
339 }
340 
342  ELdestControl & theDestControl) const {
343  return a->getELdestControl(name, theDestControl);
344 }
345 
346 // ----------------------------------------------------------------------
347 // Obtaining Information:
348 // ----------------------------------------------------------------------
349 
352 
353 // ----------------------------------------------------------------------
354 // Global endmsg:
355 // ----------------------------------------------------------------------
356 
357 void endmsg( ErrorLog & log ) { log.endmsg(); }
358 
359 // ----------------------------------------------------------------------
360 // operator<< for integer types
361 // ----------------------------------------------------------------------
362 
364  if (e.discarding) return e;
365  std::ostringstream ost;
366  ost << n;
367  int m = (n<0) ? -n : n;
368  if ( (e.hexTrigger >= 0) && (m >= e.hexTrigger) ) {
369  ost << " [0x"
370  << std::hex << std::setw(8) << std::setfill('0')
371  << n << "] ";
372  } else {
373  if (e.spaceAfterInt) ost << " "; // $$mf 3/17/04
374  }
375  return e.emitToken( ost.str() );
376 }
377 
378 ErrorLog & operator<<( ErrorLog & e, unsigned int n) {
379  if (e.discarding) return e;
380  std::ostringstream ost;
381  ost << n;
382  if ( (e.hexTrigger >= 0) &&
383  (n >= static_cast<unsigned int>(e.hexTrigger)) ) {
384  ost << "[0x"
385  << std::hex << std::setw(8) << std::setfill('0')
386  << n << "] ";
387  } else {
388  if (e.spaceAfterInt) ost << " "; // $$mf 3/17/04
389  }
390  return e.emitToken( ost.str() );
391 }
392 
394  if (e.discarding) return e;
395  std::ostringstream ost;
396  ost << n;
397  long m = (n<0) ? -n : n;
398  if ( (e.hexTrigger >= 0) && (m >= e.hexTrigger) ) {
399  int width = 8;
400  if ( static_cast<unsigned long>(n) > 0xFFFFFFFFL ) width = 16;
401  ost << "[0x"
402  << std::hex << std::setw(width) << std::setfill('0')
403  << n << "] ";
404  } else {
405  if (e.spaceAfterInt) ost << " "; // $$mf 3/17/04
406  }
407  return e.emitToken( ost.str() );
408 }
409 
410 ErrorLog & operator<<( ErrorLog & e, unsigned long n) {
411  if (e.discarding) return e;
412  std::ostringstream ost;
413  ost << n;
414  if ( (e.hexTrigger >= 0) &&
415  (n >= static_cast<unsigned long>(e.hexTrigger)) ) {
416  int width = 8;
417  if ( n > 0xFFFFFFFFL ) width = 16;
418  ost << "[0x"
419  << std::hex << std::setw(width) << std::setfill('0')
420  << n << "] ";
421  } else {
422  if (e.spaceAfterInt) ost << " "; // $$mf 3/17/04
423  }
424  return e.emitToken( ost.str() );
425 }
426 
428  if (e.discarding) return e;
429  std::ostringstream ost;
430  ost << n;
431  short m = (n<0) ? -n : n;
432  if ( (e.hexTrigger >= 0) && (m >= e.hexTrigger) ) {
433  ost << "[0x"
434  << std::hex << std::setw(4) << std::setfill('0')
435  << n << "] ";
436  } else {
437  if (e.spaceAfterInt) ost << " "; // $$mf 3/17/04
438  }
439  return e.emitToken( ost.str() );
440 }
441 
442 ErrorLog & operator<<( ErrorLog & e, unsigned short n) {
443  if (e.discarding) return e;
444  std::ostringstream ost;
445  ost << n;
446  if ( (e.hexTrigger >= 0) && (n >= e.hexTrigger) ) {
447  ost << "[0x"
448  << std::hex << std::setw(4) << std::setfill('0')
449  << n << "] ";
450  } else {
451  if (e.spaceAfterInt) ost << " "; // $$mf 3/17/04
452  }
453  return e.emitToken( ost.str() );
454 }
455 
456 
457 // ----------------------------------------------------------------------
458 // operator<< for const char[]
459 // ----------------------------------------------------------------------
460 
461 ErrorLog & operator<<( ErrorLog & e, const char s[] ) {
462  // Exactly equivalent to the general template.
463  // If this is not provided explicitly, then the template will
464  // be instantiated once for each length of string ever used.
465  if (e.discarding) return e;
466  std::ostringstream ost;
467  ost << s << ' ';
468  return e.emitToken( ost.str() );
469 }
470 
471 
472 // ----------------------------------------------------------------------
473 
474 
475 } // end of namespace service
476 } // end of namespace edm
void setModule(const ELstring &modName)
Definition: ErrorLog.cc:236
bool setSpaceAfterInt(bool space=true)
Definition: ErrorLog.cc:314
ELseverityLevel severity
Definition: ELextendedID.h:36
std::list< boost::shared_ptr< ELdestination > > & sinks()
ErrorLog & endmsg()
Definition: ErrorLog.cc:289
int severityCounts_[ELseverityLevel::nLevels]
bool getELdestControl(const ELstring &name, ELdestControl &theDestControl) const
Definition: ErrorLog.cc:341
virtual void set(const ELseverityLevel &sev, const ELstring &id)
Definition: ErrorObj.cc:249
static PFTauRenderPlugin instance
void setPackage(const ELstring &pkgName)
Definition: ErrorLog.cc:243
ErrorLog & operator()(const ELseverityLevel &sev, const ELstring &id)
Definition: ErrorLog.cc:116
virtual ErrorObj & emitToken(const ELstring &txt)
Definition: ErrorObj.cc:220
ELslProxy< ELunspecifiedGen > const ELunspecified
virtual void setSubroutine(const ELstring &subroutine)
Definition: ErrorObj.cc:193
static void msgabort()
void endmsg(ErrorLog &log)
Definition: ErrorLog.cc:357
const ELstring & process() const
ErrorLog & operator<<(void(*f)(ErrorLog &))
Definition: ErrorLog.cc:257
ELseverityLevel setDiscardThreshold(ELseverityLevel sev)
Definition: ErrorLog.cc:326
virtual void setReactedTo(bool r)
Definition: ErrorObj.cc:210
const ELextendedID & xid() const
Definition: ErrorObj.cc:146
void setDebugMessages(ELseverityLevel sev, ELstring id)
Definition: ErrorLog.cc:336
ELseverityLevel discardThreshold
Definition: ErrorLog.h:129
ErrorLog & emitToken(const ELstring &msg)
Definition: ErrorLog.cc:269
ELslProxy< ELzeroSeverityGen > const ELzeroSeverity
static void possiblyAbOrEx(int s, int a, int e)
Definition: ErrorLog.cc:169
const ELstring getName() const
void setSubroutine(const ELstring &subName)
Definition: ErrorLog.cc:149
double f[11][100]
void setDebugVerbosity(int debugVerbosity)
Definition: ErrorLog.cc:332
ELstring subroutineName() const
Definition: ErrorLog.cc:351
bool getELdestControl(const ELstring &name, ELdestControl &theControl)
boost::shared_ptr< ELcontextSupplier > context_
ErrorLog & operator<<(ErrorLog &e, const T &t)
ELstring subroutine
Definition: ELextendedID.h:38
ELslProxy< ELinfoGen > const ELinfo
ELseverityLevel debugSeverityLevel
Definition: ErrorLog.h:132
ELstring moduleName() const
Definition: ErrorLog.cc:350
int setHexTrigger(int trigger)
Definition: ErrorLog.cc:320
ELadministrator * a
Definition: ErrorLog.h:121
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
virtual void setProcess(const ELstring &proc)
Definition: ErrorObj.cc:203
double a
Definition: hdecay.h:121
ELstring debugMessageId
Definition: ErrorLog.h:133
tuple cout
Definition: gather_cfg.py:121
static void msgexit(int s)
ELdestControl attach(const ELdestination &sink)
void ELrecv(int nbytes, const char *data)
Definition: ELrecv.cc:42
const ELseverityLevel & exitThreshold() const
std::string ELstring
Definition: ELstring.h:26
Definition: vlib.h:209
const ELseverityLevel & abortThreshold() const
virtual void setModule(const ELstring &module)
Definition: ErrorObj.cc:188