CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ELtsErrorLog.cc
Go to the documentation of this file.
1 // ----------------------------------------------------------------------
2 //
3 // ELtsErrorLog.cc
4 //
5 // Created 5/31/01 mf Base implementations for all the templates in
6 // ThreadSafeErrorLog<Mutex>
7 //
8 // 11/15/01 mf static_cast to unsigned int and long in comparisons in
9 // operator<<( ErrorLog & e, unsigned int n) and long, and
10 // also rwriting 0xFFFFFFFF as 0xFFFFFFFFL when comparing to a
11 // long. THese cure warnings when -Wall -pedantic are turned on.
12 // 3/06/01 mf getELdestControl() which forwards to *a
13 //
14 // ----------------------------------------------------------------------
15 
20 
22 
23 #include <iostream>
24 #include <iomanip>
25 #include <sstream>
26 
27 
28 // Possible Traces:
29 // #define ErrorLogCONSTRUCTOR_TRACE
30 // #define ErrorLogOUTPUT_TRACE
31 // #define ErrorLogENDMSG_TRACE
32 #ifdef ErrorLogEMIT_TRACE
33  #include <string>
34 #endif
35 
36 namespace edm {
37 namespace service {
38 
39 
40 // ----------------------------------------------------------------------
41 // Birth and Death:
42 // ----------------------------------------------------------------------
43 
45 : a( ELadministrator::instance() )
46 , e()
47 , process("")
48 , msgIsActive (false)
49 , msg(ELunspecified, "...")
50 {
51  #ifdef ErrorLogCONSTRUCTOR_TRACE
52  std::cout << "Constructor for ThreadSafeErrorLog\n";
53  #endif
54 }
55 
57 : a( ELadministrator::instance() )
58 , e(pkgName)
59 , process("")
60 , msgIsActive (false)
61 , msg(ELunspecified, "...")
62 {
63  #ifdef ErrorLogCONSTRUCTOR_TRACE
64  std::cout << "Constructor for ThreadSafeErrorLog (with pkgName = "
65  << pkgName << ")\n";
66  #endif
67 }
68 
70 : a( ELadministrator::instance() )
71 , e(ee)
72 , process("")
73 , msgIsActive (false)
74 , msg(ELunspecified, "...")
75 {
76  #ifdef ErrorLogCONSTRUCTOR_TRACE
77  std::cout << "Constructor for ThreadSafeErrorLog from ErrorLog\n";
78  #endif
79 }
80 
82 : a( ELadministrator::instance() )
83 , e(ee.e)
84 , process(ee.process)
85 , msgIsActive (ee.msgIsActive)
86 , msg(ee.msg)
87 {
88  #ifdef ErrorLogCONSTRUCTOR_TRACE
89  std::cout << "Copy constructor for ThreadSafeErrorLog \n";
90  #endif
91 }
92 
94 {
95  #ifdef ErrorLogCONSTRUCTOR_TRACE
96  std::cout << "Destructor for ThreadSafeErrorLog\n";
97  #endif
98 }
99 
100 // ----------------------------------------------------------------------
101 // Setup for preamble parts
102 // ----------------------------------------------------------------------
103 
104 void ELtsErrorLog::setSubroutine( const ELstring & subName ) {
105  e.setSubroutine (subName);
106 } // setSubroutine()
107 
108 void ELtsErrorLog::setModule( const ELstring & modName ) {
109  e.setModule (modName);
110 } // setModule()
111 
112 void ELtsErrorLog::setPackage( const ELstring & pkgName ) {
113  e.setModule (pkgName);
114 } // setPackage()
115 
116 void ELtsErrorLog::setProcess( const ELstring & procName ) {
117  process = procName;
118 } // setProcess()
119 
120 int ELtsErrorLog::setHexTrigger (int trigger) {
121  return e.setHexTrigger (trigger);
122 }
123 
125  return e.setDiscardThreshold(sev);
126 }
127 
129  e.setDebugVerbosity (debugVerbosity);
130 }
131 
133  e.setDebugMessages (sev, id);
134 }
135 
136 // ----------------------------------------------------------------------
137 // Recovery of an ELdestControl handle
138 // ----------------------------------------------------------------------
139 
141  ELdestControl & theDestControl) const {
142  return a->getELdestControl ( name, theDestControl );
143 }
144 
145 
146 // ----------------------------------------------------------------------
147 // Message Initiation
148 // ----------------------------------------------------------------------
149 
151 {
152  if ( sev < e.discardThreshold ) {
153  e.discarding = true;
154  return;
155  }
156  e.discarding = false;
157  #ifdef ErrorLogENDMSG_TRACE
158  std::cout << "=:=:=: precautionary endmsg ( "
159  << sev.getName() << ", " << id << ")\n";
160  #endif
161 
162  // Unlike the case for ErrorLog, it is not necessary to check
163  // msgIsActive because the calling code was forced to do that
164  // (since if it WAS active, ELtsErrorLog can't do the Mutex LOCK.)
165 
166  // ----- form ErrorObj for this new message:
167  //
168  msg.clear();
169  msgIsActive = true;
170  msg.set ( sev, id );
171  msg.setProcess ( process );
172  msg.setModule ( e.module );
174  msg.setReactedTo ( false );
175 
176  return;
177 
178 } // operator()( )
179 
180 // ----------------------------------------------------------------------
181 // Message Continuation:
182 // item() method used by emitToken(string)
183 // ----------------------------------------------------------------------
184 
185 
186 void ELtsErrorLog::item ( const ELstring & s ) {
187  if ( ! msgIsActive )
188  initiateMsg ( ELunspecified, "..." );
189  msg.emitToken( s );
190 } // emitToken()
191 
192 // ----------------------------------------------------------------------
193 // Message Continuation:
194 // item() methods used by operator<< for integer types
195 // ----------------------------------------------------------------------
196 
197 void ELtsErrorLog::item ( int n ) {
198  if (e.discarding) return;
199  std::ostringstream ost;
200  ost << n << ' ';
201  int m = (n<0) ? -n : n;
202  if ( (e.hexTrigger >= 0) && (m >= e.hexTrigger) ) {
203  ost << "[0x"
204  << std::hex << std::setw(8) << std::setfill('0')
205  << n << "] ";
206  }
207  msg.emitToken( ost.str() );
208 }
209 
210 void ELtsErrorLog::item ( unsigned int n ) {
211  if (e.discarding) return;
212  std::ostringstream ost;
213  ost << n << ' ';
214  if ( (e.hexTrigger >= 0) &&
215  (n >= static_cast<unsigned int>(e.hexTrigger)) ) {
216  ost << "[0x"
217  << std::hex << std::setw(8) << std::setfill('0')
218  << n << "] ";
219  }
220  msg.emitToken( ost.str() );
221 }
222 
223 void ELtsErrorLog::item ( long n ) {
224  if (e.discarding) return;
225  std::ostringstream ost;
226  ost << n << ' ';
227  long m = (n<0) ? -n : n;
228  if ( (e.hexTrigger >= 0) && (m >= e.hexTrigger) ) {
229  int width = 8;
230  if ( static_cast<unsigned long>(n) > 0xFFFFFFFFL ) width = 16;
231  ost << "[0x"
232  << std::hex << std::setw(width) << std::setfill('0')
233  << n << "] ";
234  }
235  msg.emitToken( ost.str() );
236 }
237 
238 void ELtsErrorLog::item ( unsigned long n ) {
239  if (e.discarding) return;
240  std::ostringstream ost;
241  ost << n << ' ';
242  if ( (e.hexTrigger >= 0) &&
243  (n >= static_cast<unsigned long>(e.hexTrigger)) ) {
244  int width = 8;
245  if ( n > 0xFFFFFFFFL ) width = 16;
246  ost << "[0x"
247  << std::hex << std::setw(width) << std::setfill('0')
248  << n << "] ";
249  }
250  msg.emitToken( ost.str() );
251 }
252 
253 void ELtsErrorLog::item ( short n ) {
254  if (e.discarding) return;
255  std::ostringstream ost;
256  ost << n << ' ';
257  short m = (n<0) ? -n : n;
258  if ( (e.hexTrigger >= 0) && (m >= e.hexTrigger) ) {
259  ost << "[0x"
260  << std::hex << std::setw(4) << std::setfill('0')
261  << n << "] ";
262  }
263  msg.emitToken( ost.str() );
264 }
265 
266 void ELtsErrorLog::item ( unsigned short n ) {
267  if (e.discarding) return;
268  std::ostringstream ost;
269  ost << n << ' ';
270  if ( (e.hexTrigger >= 0) && (n >= e.hexTrigger) ) {
271  ost << "[0x"
272  << std::hex << std::setw(4) << std::setfill('0')
273  << n << "] ";
274  }
275  msg.emitToken( ost.str() );
276 }
277 
278 // ----------------------------------------------------------------------
279 // Message Completion:
280 // ----------------------------------------------------------------------
281 
283 
284  // ----- will we need to poke/restore info into the message?
285  //
286  bool updateProcess ( msg.xid().process .length() == 0 );
287  bool updateModule ( msg.xid().module .length() == 0 );
288  bool updateSubroutine( msg.xid().subroutine.length() == 0 );
289 
290  // ----- poke, if needed:
291  //
292  if ( updateProcess ) msg.setProcess ( process );
293  if ( updateModule ) msg.setModule ( e.module );
294  if ( updateSubroutine ) msg.setSubroutine( e.subroutine );
295 
296  return ( updateProcess || updateModule || updateSubroutine );
297 
298 }
299 
300 static inline void msgabort() {
302  "msgabort - MessageLogger tsErrorLog requested to abort");
303  throw e;
304 }
305 
307 
308  // NOTE -- this is never called except in cases where a <Mutex> LOCK
309  // is in scope. That is, this code should be treated as a
310  // critical section.
311 
312  // severity level statistics keeping:
313  int lev = msg.xid().severity.getLevel();
314  ++ a->severityCounts_[lev];
315  if ( lev > a->highSeverity_.getLevel() )
316  a->highSeverity_ = msg.xid().severity;
317 
318  // context-based editing (if specified; usually just returns)
319  a->context_->editErrorObj( msg );
320 
321  // ----- send the message to each destination:
322  //
323  if (a->sinks().begin() == a->sinks().end()) {
324  std::cerr << "\nERROR LOGGED WITHOUT DESTINATION!\n";
325  std::cerr << "Attaching destination \"cerr\" to ELadministrator by default\n"
326  << std::endl;
328  }
329  std::list<boost::shared_ptr<ELdestination> >::iterator d;
330  for ( d = a->sinks().begin(); d != a->sinks().end(); ++d )
331  if ( (*d)->log( msg ) )
332  msg.setReactedTo (true );
333 
334 
335  if ( msg.xid().severity.getLevel() >= a->abortThreshold().getLevel()
336  &&
338  msgabort();
339  }
340 
341 }
342 
343 } // end of namespace service
344 } // end of namespace edm
void setModule(const ELstring &modName)
Definition: ErrorLog.cc:236
ELadministrator * a
Definition: ELtsErrorLog.h:98
ELseverityLevel severity
Definition: ELextendedID.h:36
std::list< boost::shared_ptr< ELdestination > > & sinks()
int severityCounts_[ELseverityLevel::nLevels]
virtual void clear()
Definition: ErrorObj.cc:242
virtual void set(const ELseverityLevel &sev, const ELstring &id)
Definition: ErrorObj.cc:229
void setDebugVerbosity(int debugVerbosity)
void setPackage(const ELstring &pkgName)
ELseverityLevel setDiscardThreshold(ELseverityLevel sev)
virtual ErrorObj & emitToken(const ELstring &txt)
Definition: ErrorObj.cc:200
bool getELdestControl(const ELstring &name, ELdestControl &theDestControl) const
int setHexTrigger(int trigger)
ELslProxy< ELunspecifiedGen > const ELunspecified
virtual void setSubroutine(const ELstring &subroutine)
Definition: ErrorObj.cc:173
static void msgabort()
bool pokeMsg(edm::ErrorObj &msg)
ELslProxy< ELhighestSeverityGen > const ELhighestSeverity
ELseverityLevel setDiscardThreshold(ELseverityLevel sev)
Definition: ErrorLog.cc:326
virtual void setReactedTo(bool r)
Definition: ErrorObj.cc:190
void setProcess(const ELstring &procName)
const ELextendedID & xid() const
Definition: ErrorObj.cc:126
void setDebugMessages(ELseverityLevel sev, ELstring id)
Definition: ErrorLog.cc:336
ELseverityLevel discardThreshold
Definition: ErrorLog.h:129
const ELstring getName() const
void setDebugMessages(ELseverityLevel sev, ELstring id)
void setSubroutine(const ELstring &subName)
void setSubroutine(const ELstring &subName)
Definition: ErrorLog.cc:149
void setDebugVerbosity(int debugVerbosity)
Definition: ErrorLog.cc:332
bool getELdestControl(const ELstring &name, ELdestControl &theControl)
boost::shared_ptr< ELcontextSupplier > context_
ELstring subroutine
Definition: ELextendedID.h:38
void setModule(const ELstring &modName)
int setHexTrigger(int trigger)
Definition: ErrorLog.cc:320
void dispatch(edm::ErrorObj &msg)
tuple process
Definition: align_tpl.py:3
virtual void setProcess(const ELstring &proc)
Definition: ErrorObj.cc:183
double a
Definition: hdecay.h:121
void initiateMsg(const ELseverityLevel &sev, const ELstring &id)
tuple cout
Definition: gather_cfg.py:41
string s
Definition: asciidump.py:422
ELdestControl attach(const ELdestination &sink)
std::string ELstring
Definition: ELstring.h:26
const ELseverityLevel & abortThreshold() const
virtual void setModule(const ELstring &module)
Definition: ErrorObj.cc:168