|
Gaudi Framework, version v21r9 |
| Home | Generated: 3 May 2010 |
#include <IssueLogger.h>


Definition at line 17 of file IssueLogger.h.
| IssueLogger::IssueLogger | ( | const std::string & | name, | |
| ISvcLocator * | svc | |||
| ) |
Definition at line 29 of file IssueLogger.cpp.
00030 : base_class(name, svc) { 00031 00032 declareProperty ("Output", m_outputfile ); 00033 declareProperty ("ReportLevel", m_reportLevelS="WARNING"); 00034 declareProperty ("TracebackLevel", m_traceLevelS="ERROR"); 00035 declareProperty ("ShowTime", m_showTime=false); 00036 00037 m_reportLevelS.declareUpdateHandler(&IssueLogger::setupLevels,this); 00038 m_traceLevelS.declareUpdateHandler(&IssueLogger::setupLevels,this); 00039 m_outputfile.declareUpdateHandler(&IssueLogger::setupStreams,this); 00040 00041 m_reportLevel = IssueSeverity::WARNING; 00042 m_traceLevel = IssueSeverity::ERROR; 00043 00044 for (int i=0; i<IssueSeverity::NUM_LEVELS; ++i) { 00045 m_logger[i] = 0; 00046 } 00047 00048 m_msgSevMap[MSG::NIL] = IssueSeverity::NIL; 00049 m_msgSevMap[MSG::VERBOSE] = IssueSeverity::VERBOSE; 00050 m_msgSevMap[MSG::DEBUG] = IssueSeverity::DEBUG; 00051 m_msgSevMap[MSG::INFO] = IssueSeverity::INFO; 00052 m_msgSevMap[MSG::WARNING] = IssueSeverity::WARNING; 00053 m_msgSevMap[MSG::ERROR] = IssueSeverity::ERROR; 00054 m_msgSevMap[MSG::FATAL] = IssueSeverity::FATAL; 00055 m_msgSevMap[MSG::ALWAYS] = IssueSeverity::ALWAYS; 00056 00057 m_sevMsgMap[IssueSeverity::NIL] = MSG::NIL; 00058 m_sevMsgMap[IssueSeverity::VERBOSE] = MSG::VERBOSE; 00059 m_sevMsgMap[IssueSeverity::DEBUG] = MSG::DEBUG; 00060 m_sevMsgMap[IssueSeverity::DEBUG1] = MSG::DEBUG; 00061 m_sevMsgMap[IssueSeverity::DEBUG2] = MSG::DEBUG; 00062 m_sevMsgMap[IssueSeverity::DEBUG3] = MSG::DEBUG; 00063 m_sevMsgMap[IssueSeverity::INFO] = MSG::INFO; 00064 m_sevMsgMap[IssueSeverity::WARNING] = MSG::WARNING; 00065 m_sevMsgMap[IssueSeverity::RECOVERABLE] = MSG::ERROR; 00066 m_sevMsgMap[IssueSeverity::ERROR] = MSG::ERROR; 00067 m_sevMsgMap[IssueSeverity::FATAL] = MSG::FATAL; 00068 m_sevMsgMap[IssueSeverity::ALWAYS] = MSG::ALWAYS; 00069 00070 m_levelTrans[IssueSeverity::VERBOSE] = "VERBOSE"; 00071 m_levelTrans[IssueSeverity::DEBUG] = "DEBUG"; 00072 m_levelTrans[IssueSeverity::DEBUG1] = "DEBUG1"; 00073 m_levelTrans[IssueSeverity::DEBUG2] = "DEBUG2"; 00074 m_levelTrans[IssueSeverity::DEBUG3] = "DEBUG3"; 00075 m_levelTrans[IssueSeverity::INFO] = "INFO"; 00076 m_levelTrans[IssueSeverity::WARNING] = "WARNING"; 00077 m_levelTrans[IssueSeverity::RECOVERABLE] = "RECOVERABLE"; 00078 m_levelTrans[IssueSeverity::ERROR] = "ERROR"; 00079 m_levelTrans[IssueSeverity::FATAL] = "FATAL"; 00080 m_levelTrans[IssueSeverity::ALWAYS] = "ALWAYS"; 00081 00082 m_levelSTrans["VERBOSE"] = IssueSeverity::VERBOSE; 00083 m_levelSTrans["DEBUG"] = IssueSeverity::DEBUG; 00084 m_levelSTrans["DEBUG1"] = IssueSeverity::DEBUG1; 00085 m_levelSTrans["DEBUG2"] = IssueSeverity::DEBUG2; 00086 m_levelSTrans["DEBUG3"] = IssueSeverity::DEBUG3; 00087 m_levelSTrans["INFO"] = IssueSeverity::INFO; 00088 m_levelSTrans["WARNING"] = IssueSeverity::WARNING; 00089 m_levelSTrans["RECOVERABLE"] = IssueSeverity::RECOVERABLE; 00090 m_levelSTrans["ERROR"] = IssueSeverity::ERROR; 00091 m_levelSTrans["FATAL"] = IssueSeverity::FATAL; 00092 m_levelSTrans["ALWAYS"] = IssueSeverity::ALWAYS; 00093 00094 00095 }
| IssueLogger::~IssueLogger | ( | ) | [protected, virtual] |
| StatusCode IssueLogger::initialize | ( | ) | [virtual] |
Reimplemented from Service.
Definition at line 106 of file IssueLogger.cpp.
00106 { 00107 00108 StatusCode st = Service::initialize(); 00109 if (st.isFailure()) { return st; } 00110 00111 setupDefaultLogger(); 00112 00113 return st; 00114 00115 }
| StatusCode IssueLogger::reinitialize | ( | ) | [virtual] |
Reimplemented from Service.
Definition at line 120 of file IssueLogger.cpp.
00120 { 00121 00122 MsgStream log ( msgSvc(), name() ); 00123 log << MSG::WARNING << "reinitialize not implemented" << endmsg; 00124 00125 00126 return StatusCode::SUCCESS; 00127 00128 }
| StatusCode IssueLogger::finalize | ( | void | ) | [virtual] |
Reimplemented from Service.
Definition at line 133 of file IssueLogger.cpp.
00133 { 00134 00135 MsgStream log ( msgSvc(), name() ); 00136 log << MSG::DEBUG << "IssueLogger::finalize" << endmsg; 00137 00138 for (int i=0; i<IssueSeverity::NUM_LEVELS; ++i) { 00139 IssueSeverity::Level j = IssueSeverity::Level (i); 00140 delete m_logger[j]; 00141 } 00142 00143 return Service::finalize(); 00144 }
| void IssueLogger::report | ( | IssueSeverity::Level | level, | |
| const std::string & | msg, | |||
| const std::string & | origin | |||
| ) | [virtual] |
Implements IIssueLogger.
Definition at line 247 of file IssueLogger.cpp.
00248 { 00249 00250 if ( lev < m_reportLevel) return; 00251 00252 std::string msg = m_levelTrans[lev] + " " + org + " \"" + str + "\""; 00253 00254 if (m_showTime) { 00255 const time_t t = time( 0 ); 00256 tm *tt = localtime( &t ); 00257 00258 ostringstream os; 00259 os << (tt->tm_hour < 10 ? "0" : "" ) << tt->tm_hour << ":" 00260 << (tt->tm_min < 10 ? "0" : "" ) << tt->tm_min << ":" 00261 << (tt->tm_sec < 10 ? "0" : "" ) << tt->tm_sec << " " 00262 << tt->tm_year + 1900 << "/" 00263 << (tt->tm_mon < 9 ? "0" : "" ) << tt->tm_mon+1 << "/" 00264 << (tt->tm_mday < 10 ? "0" : "" ) << tt->tm_mday << " " 00265 #ifdef __linux 00266 << tt->tm_zone; 00267 #else 00268 << " " ; 00269 #endif 00270 00271 msg += " [" + os.str() +"]"; 00272 00273 } 00274 00275 if (lev >= m_traceLevel) { 00276 std::string stack; 00277 getTraceBack(stack); 00278 msg += "\n" + stack; 00279 } 00280 00281 00282 m_log[lev](msg); 00283 00284 00285 }
| void IssueLogger::report | ( | const IssueSeverity & | err | ) | [virtual] |
| StatusCode IssueLogger::connect | ( | const std::string & | ident | ) | [private] |
Definition at line 158 of file IssueLogger.cpp.
00158 { 00159 00160 MsgStream log ( msgSvc(), name() ); 00161 Tokenizer tok(true); 00162 00163 string::size_type loc = ident.find(" "); 00164 // string stream = ident.substr(0,loc); // icc remark #177: variable "stream" was declared but never referenced 00165 // typedef std::pair<std::string,std::string> Prop; 00166 // std::vector<Prop> props; 00167 string val,VAL,TAG,filename; 00168 00169 tok.analyse(ident.substr(loc+1,ident.length()), " ", "", "", "=", "'", "'"); 00170 00171 for ( Tokenizer::Items::iterator i = tok.items().begin(); 00172 i != tok.items().end(); i++) { 00173 const std::string& tag = (*i).tag(); 00174 TAG = tag; 00175 toupper(TAG); 00176 00177 val = (*i).value(); 00178 VAL = val; 00179 toupper(VAL); 00180 00181 IssueSeverity::Level level; 00182 00183 if (TAG == "DEBUG") { 00184 level = IssueSeverity::DEBUG; 00185 } else if ( TAG == "INFO") { 00186 level = IssueSeverity::INFO; 00187 } else if ( TAG == "WARNING") { 00188 level = IssueSeverity::WARNING; 00189 } else if ( TAG == "RECOVERABLE") { 00190 level = IssueSeverity::RECOVERABLE; 00191 } else if ( TAG == "ERROR") { 00192 level = IssueSeverity::ERROR; 00193 } else if ( TAG == "FATAL") { 00194 level = IssueSeverity::FATAL; 00195 } else { 00196 log << MSG::ERROR << "Unknown output level \"" << TAG << "\"" 00197 << endmsg; 00198 continue; 00199 } 00200 00201 if (m_logger[level] != 0) { 00202 log << MSG::INFO << "closing stream " << m_logger[level]->name() 00203 << endmsg; 00204 delete m_logger[level]; 00205 m_logger[level] = 0; 00206 } 00207 00208 if (val == "MsgSvc") { 00209 m_logger[level] = new StreamLogger(msgSvc(), m_sevMsgMap[level]); 00210 m_log[level] = 00211 boost::bind(&StreamLogger::WriteToMsgSvc, m_logger[level], 00212 _1); 00213 } else if (val == "STDERR") { 00214 m_logger[level] = new StreamLogger(std::cerr); 00215 m_log[level] = 00216 boost::bind(&StreamLogger::WriteToStream, m_logger[level], 00217 _1); 00218 } else if (val == "STDOUT") { 00219 m_logger[level] = new StreamLogger(std::cout); 00220 m_log[level] = 00221 boost::bind(&StreamLogger::WriteToStream, m_logger[level], 00222 _1); 00223 } else { // A file 00224 try { 00225 m_logger[level] = new StreamLogger(val.c_str()); 00226 } 00227 catch (std::exception&) { 00228 m_logger[level] = 0; 00229 log << MSG::ERROR << "Unable to open file \"" << VAL 00230 << "\" for writing issues at level " << TAG << endmsg; 00231 return StatusCode::FAILURE; 00232 } 00233 m_log[level] = 00234 boost::bind(&StreamLogger::WriteToStream, m_logger[level], _1); 00235 } 00236 log << MSG::DEBUG << "Writing " << m_levelTrans[level] 00237 << " issues to " << m_logger[level]->name() << endmsg; 00238 00239 } 00240 00241 return StatusCode::SUCCESS; 00242 }
| void IssueLogger::getTraceBack | ( | std::string & | stack | ) | [private] |
Definition at line 149 of file IssueLogger.cpp.
00149 { 00150 const int depth = 30; 00151 const int offset = 5; 00152 System::backTrace(stack, depth, offset); 00153 }
| MSG::Level IssueLogger::sevToMsg | ( | IssueSeverity::Level & | lev | ) | [private] |
| IssueSeverity::Level IssueLogger::msgToSev | ( | MSG::Level & | lev | ) | [private] |
| void IssueLogger::setupDefaultLogger | ( | ) | [private] |
Definition at line 373 of file IssueLogger.cpp.
00373 { 00374 for (int i=1; i<IssueSeverity::NUM_LEVELS; ++i) { 00375 if (m_logger[i] == 0) { 00376 // default: dump to msgSvc 00377 IssueSeverity::Level j = IssueSeverity::Level (i); 00378 00379 m_logger[j] = new StreamLogger(msgSvc(), m_sevMsgMap[j]); 00380 m_log[j] = boost::bind(&StreamLogger::WriteToMsgSvc, m_logger[j], 00381 _1); 00382 00383 MsgStream log ( msgSvc(), name() ); 00384 log << MSG::DEBUG << "Writing " << m_levelTrans[j] 00385 << " issues to " << m_logger[j]->name() << endmsg; 00386 00387 } 00388 } 00389 }
| void IssueLogger::setupLevels | ( | Property & | prop | ) | [private] |
Definition at line 301 of file IssueLogger.cpp.
00301 { 00302 00303 00304 StringProperty *sap = dynamic_cast<StringProperty*> (&prop); 00305 if (sap == 0) { 00306 MsgStream log ( msgSvc(), name() ); 00307 log << MSG::ERROR << "Could not convert " << prop.name() 00308 << "to a StringProperty (which it should be!)" << endmsg; 00309 return; 00310 } 00311 00312 std::string val = sap->value(); 00313 00314 if (prop.name() == "ReportLevel") { 00315 if (m_levelSTrans.find(val) == m_levelSTrans.end()) { 00316 MsgStream log ( msgSvc(), name() ); 00317 log << MSG::ERROR 00318 << "Option ReportLevel: unknown Issue Severity level \"" 00319 << val << "\". Setting it WARNING" << endmsg; 00320 m_reportLevel = IssueSeverity::WARNING; 00321 return; 00322 } else { 00323 m_reportLevel = m_levelSTrans[m_reportLevelS]; 00324 } 00325 } else if (prop.name() == "TracebackLevel") { 00326 if (m_levelSTrans.find(val) == m_levelSTrans.end()) { 00327 MsgStream log ( msgSvc(), name() ); 00328 log << MSG::ERROR 00329 << "Option TracebackLevel: unknown Issue Severity level \"" 00330 << val << "\". Setting it to ERROR" << endmsg; 00331 m_traceLevel = IssueSeverity::ERROR; 00332 return; 00333 } else { 00334 m_traceLevel = m_levelSTrans[m_traceLevelS]; 00335 } 00336 } else { 00337 MsgStream log ( msgSvc(), name() ); 00338 log << MSG::ERROR << "setting up unknown property \"" << prop.name() 00339 << "\"" << endmsg; 00340 return; 00341 } 00342 00343 }
| void IssueLogger::setupStreams | ( | Property & | prop | ) | [private] |
Definition at line 348 of file IssueLogger.cpp.
00348 { 00349 00350 StringArrayProperty *sap = dynamic_cast<StringArrayProperty*>( &prop ); 00351 if (sap == 0) { 00352 MsgStream log ( msgSvc(), name() ); 00353 log << MSG::ERROR << "Could not convert " << prop.name() 00354 << "to a StringArrayProperty (which it should be!)" << endmsg; 00355 return; 00356 } 00357 00358 vector<string>::const_iterator itr; 00359 for (itr = sap->value().begin(); itr != sap->value().end(); ++itr) { 00360 if (connect(*itr).isFailure()) { 00361 MsgStream log ( msgSvc(), name() ); 00362 log << MSG::ERROR << "Could not setup stream " << *itr << endmsg; 00363 } 00364 } 00365 00366 return; 00367 00368 }
friend class SvcFactory< IssueLogger > [friend] |
Definition at line 20 of file IssueLogger.h.
StringArrayProperty IssueLogger::m_outputfile [private] |
Definition at line 39 of file IssueLogger.h.
StringProperty IssueLogger::m_reportLevelS [private] |
Definition at line 40 of file IssueLogger.h.
StringProperty IssueLogger::m_traceLevelS [private] |
Definition at line 40 of file IssueLogger.h.
BooleanProperty IssueLogger::m_showTime [private] |
Definition at line 41 of file IssueLogger.h.
Definition at line 43 of file IssueLogger.h.
Definition at line 43 of file IssueLogger.h.
StreamLogger* IssueLogger::m_logger[IssueSeverity::NUM_LEVELS] [private] |
Definition at line 45 of file IssueLogger.h.
boost::function<void (const std::string&)> IssueLogger::m_log[IssueSeverity::NUM_LEVELS] [private] |
Definition at line 46 of file IssueLogger.h.
Definition at line 48 of file IssueLogger.h.
Definition at line 49 of file IssueLogger.h.
Definition at line 50 of file IssueLogger.h.
Definition at line 51 of file IssueLogger.h.