Gaudi Framework, version v23r5

Home   Generated: Wed Nov 28 2012
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
IssueLogger.cpp
Go to the documentation of this file.
1 #include "IssueLogger.h"
2 
7 #include "GaudiKernel/System.h"
8 #include "GaudiKernel/Time.h"
9 
10 #include <sstream>
11 #include <streambuf>
12 #include <algorithm>
13 
14 #include "boost/bind.hpp"
15 
16 using namespace std;
17 
19 
20 //*************************************************************************//
21 inline void toupper(std::string &s)
22 {
23  std::transform(s.begin(), s.end(), s.begin(),
24  (int(*)(int)) toupper);
25 }
26 
27 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
28 
30  : base_class(name, svc) {
31 
32  declareProperty ("Output", m_outputfile );
33  declareProperty ("ReportLevel", m_reportLevelS="WARNING");
34  declareProperty ("TracebackLevel", m_traceLevelS="ERROR");
35  declareProperty ("ShowTime", m_showTime=false);
36 
40 
43 
44  for (int i=0; i<IssueSeverity::NUM_LEVELS; ++i) {
45  m_logger[i] = 0;
46  }
47 
56 
69 
81 
93 
94 
95 }
96 
97 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
98 
100 
101 }
102 
103 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
104 
107 
109  if (st.isFailure()) { return st; }
110 
112 
113  return st;
114 
115 }
116 
117 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
118 
121 
122  MsgStream log ( msgSvc(), name() );
123  log << MSG::WARNING << "reinitialize not implemented" << endmsg;
124 
125 
126  return StatusCode::SUCCESS;
127 
128 }
129 
130 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
131 
134 
135  MsgStream log ( msgSvc(), name() );
136  log << MSG::DEBUG << "IssueLogger::finalize" << endmsg;
137 
138  for (int i=0; i<IssueSeverity::NUM_LEVELS; ++i) {
140  delete m_logger[j];
141  }
142 
143  return Service::finalize();
144 }
145 
146 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
147 
148 void
150  const int depth = 30;
151  const int offset = 5;
152  System::backTrace(stack, depth, offset);
153 }
154 
155 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
156 
159 
160  MsgStream log ( msgSvc(), name() );
161  Tokenizer tok(true);
162 
163  string::size_type loc = ident.find(" ");
164 // string stream = ident.substr(0,loc); // icc remark #177: variable "stream" was declared but never referenced
165 // typedef std::pair<std::string,std::string> Prop;
166 // std::vector<Prop> props;
167  string val,VAL,TAG,filename;
168 
169  tok.analyse(ident.substr(loc+1,ident.length()), " ", "", "", "=", "'", "'");
170 
171  for ( Tokenizer::Items::iterator i = tok.items().begin();
172  i != tok.items().end(); i++) {
173  const std::string& tag = (*i).tag();
174  TAG = tag;
175  toupper(TAG);
176 
177  val = (*i).value();
178  VAL = val;
179  toupper(VAL);
180 
182 
183  if (TAG == "DEBUG") {
184  level = IssueSeverity::DEBUG;
185  } else if ( TAG == "INFO") {
186  level = IssueSeverity::INFO;
187  } else if ( TAG == "WARNING") {
188  level = IssueSeverity::WARNING;
189  } else if ( TAG == "RECOVERABLE") {
191  } else if ( TAG == "ERROR") {
192  level = IssueSeverity::ERROR;
193  } else if ( TAG == "FATAL") {
194  level = IssueSeverity::FATAL;
195  } else {
196  log << MSG::ERROR << "Unknown output level \"" << TAG << "\""
197  << endmsg;
198  continue;
199  }
200 
201  if (m_logger[level] != 0) {
202  log << MSG::INFO << "closing stream " << m_logger[level]->name()
203  << endmsg;
204  delete m_logger[level];
205  m_logger[level] = 0;
206  }
207 
208  if (val == "MsgSvc") {
209  m_logger[level] = new StreamLogger(msgSvc(), m_sevMsgMap[level]);
210  m_log[level] =
211  boost::bind(&StreamLogger::WriteToMsgSvc, m_logger[level],
212  _1);
213  } else if (val == "STDERR") {
215  m_log[level] =
216  boost::bind(&StreamLogger::WriteToStream, m_logger[level],
217  _1);
218  } else if (val == "STDOUT") {
220  m_log[level] =
221  boost::bind(&StreamLogger::WriteToStream, m_logger[level],
222  _1);
223  } else { // A file
224  try {
225  m_logger[level] = new StreamLogger(val.c_str());
226  }
227  catch (std::exception&) {
228  m_logger[level] = 0;
229  log << MSG::ERROR << "Unable to open file \"" << VAL
230  << "\" for writing issues at level " << TAG << endmsg;
231  return StatusCode::FAILURE;
232  }
233  m_log[level] =
234  boost::bind(&StreamLogger::WriteToStream, m_logger[level], _1);
235  }
236  log << MSG::DEBUG << "Writing " << m_levelTrans[level]
237  << " issues to " << m_logger[level]->name() << endmsg;
238 
239  }
240 
241  return StatusCode::SUCCESS;
242 }
243 
244 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
245 
246 void
248  const std::string& org) {
249 
250  if ( lev < m_reportLevel) return;
251 
252  std::string msg = m_levelTrans[lev] + " " + org + " \"" + str + "\"";
253 
254  if (m_showTime) {
255  msg += " [" + Gaudi::Time::current().format(true, "%H:%M:%S %Y/%m/%d %Z") +"]";
256  }
257 
258  if (lev >= m_traceLevel) {
260  getTraceBack(stack);
261  msg += "\n" + stack;
262  }
263 
264 
265  m_log[lev](msg);
266 
267 
268 }
269 
270 
271 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
272 
273 
274 void
276 
277  report(err.getLevel(), err.getMsg(), err.getOrigin());
278 
279 }
280 
281 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
282 
283 void
285 
286 
287  StringProperty *sap = dynamic_cast<StringProperty*> (&prop);
288  if (sap == 0) {
289  MsgStream log ( msgSvc(), name() );
290  log << MSG::ERROR << "Could not convert " << prop.name()
291  << "to a StringProperty (which it should be!)" << endmsg;
292  return;
293  }
294 
295  std::string val = sap->value();
296 
297  if (prop.name() == "ReportLevel") {
298  if (m_levelSTrans.find(val) == m_levelSTrans.end()) {
299  MsgStream log ( msgSvc(), name() );
300  log << MSG::ERROR
301  << "Option ReportLevel: unknown Issue Severity level \""
302  << val << "\". Setting it WARNING" << endmsg;
304  return;
305  } else {
307  }
308  } else if (prop.name() == "TracebackLevel") {
309  if (m_levelSTrans.find(val) == m_levelSTrans.end()) {
310  MsgStream log ( msgSvc(), name() );
311  log << MSG::ERROR
312  << "Option TracebackLevel: unknown Issue Severity level \""
313  << val << "\". Setting it to ERROR" << endmsg;
315  return;
316  } else {
318  }
319  } else {
320  MsgStream log ( msgSvc(), name() );
321  log << MSG::ERROR << "setting up unknown property \"" << prop.name()
322  << "\"" << endmsg;
323  return;
324  }
325 
326 }
327 
328 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
329 
330 void
332 
333  StringArrayProperty *sap = dynamic_cast<StringArrayProperty*>( &prop );
334  if (sap == 0) {
335  MsgStream log ( msgSvc(), name() );
336  log << MSG::ERROR << "Could not convert " << prop.name()
337  << "to a StringArrayProperty (which it should be!)" << endmsg;
338  return;
339  }
340 
342  for (itr = sap->value().begin(); itr != sap->value().end(); ++itr) {
343  if (connect(*itr).isFailure()) {
344  MsgStream log ( msgSvc(), name() );
345  log << MSG::ERROR << "Could not setup stream " << *itr << endmsg;
346  }
347  }
348 
349  return;
350 
351 }
352 
353 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
354 
355 void
357  for (int i=1; i<IssueSeverity::NUM_LEVELS; ++i) {
358  if (m_logger[i] == 0) {
359  // default: dump to msgSvc
361 
362  m_logger[j] = new StreamLogger(msgSvc(), m_sevMsgMap[j]);
363  m_log[j] = boost::bind(&StreamLogger::WriteToMsgSvc, m_logger[j],
364  _1);
365 
366  MsgStream log ( msgSvc(), name() );
367  log << MSG::DEBUG << "Writing " << m_levelTrans[j]
368  << " issues to " << m_logger[j]->name() << endmsg;
369 
370  }
371  }
372 }

Generated at Wed Nov 28 2012 12:17:16 for Gaudi Framework, version v23r5 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004