![]() |
|
|
Generated: 18 Jul 2008 |
#include <MessageSvc.h>
Inheritance diagram for MessageSvc:


Definition at line 31 of file MessageSvc.h.
Public Types | |
| typedef std::pair< std::string, std::ostream * > | NamedStream |
| typedef std::multimap< int, NamedStream > | StreamMap |
| typedef std::multimap< StatusCode, Message > | MessageMap |
| typedef std::map< std::string, int > | ThresholdMap |
Public Member Functions | |
| MessageSvc (const std::string &name, ISvcLocator *svcloc) | |
| virtual | ~MessageSvc () |
| virtual StatusCode | reinitialize () |
| Reinitialize Service. | |
| virtual StatusCode | initialize () |
| Initialize Service. | |
| virtual StatusCode | finalize () |
| Finalize Service. | |
| virtual void | reportMessage (const Message &message) |
| Report a message by sending a Message object to the message serivice. | |
| virtual void | reportMessage (const StatusCode &code, const std::string &source="") |
| Report an error to the message service. | |
| virtual void | reportMessage (const char *source, int type, const char *message) |
| Report a message by specifying the source, severity level and text. | |
| virtual void | reportMessage (const std::string &source, int type, const std::string &message) |
| Report a message by specifying the source, severity level and text. | |
| virtual void | insertMessage (const StatusCode &code, const Message &message) |
| Insert a message to be sent for a given status code into the error code repository. | |
| virtual void | eraseMessage () |
| Erase all messages associated to all status codes. | |
| virtual void | eraseMessage (const StatusCode &code) |
| Erase message associated to a given status code. | |
| virtual void | eraseMessage (const StatusCode &code, const Message &message) |
| Erase a given message associated to a given status code. | |
| virtual void | insertStream (int message_type, const std::string &name, std::ostream *stream) |
| Add a new stream for a message type (severity level). | |
| virtual void | eraseStream () |
| Delete all the streams. | |
| virtual void | eraseStream (int message_type) |
| Delete all the streams for a given message type (severity level). | |
| virtual void | eraseStream (int message_type, std::ostream *stream) |
| Delete a single stream for a given message type (severity level). | |
| virtual void | eraseStream (std::ostream *stream) |
| Delete all occurrences of a stream. | |
| virtual std::ostream * | defaultStream () const |
| Get the default stream. | |
| virtual void | setDefaultStream (std::ostream *stream) |
| Set the default stream. | |
| virtual int | outputLevel () const |
| Retrieve the current output level threshold. | |
| virtual int | outputLevel (const std::string &source) const |
| Retrieve the current output level threshold for a given message source. | |
| virtual void | setOutputLevel (int new_level) |
| Set new global output level threshold. | |
| virtual void | setOutputLevel (const std::string &source, int new_level) |
| Set new output level threshold for a given message source. | |
| virtual StatusCode | queryInterface (const InterfaceID &riid, void **ppvUnknown) |
| Query interfaces of Interface. | |
| virtual bool | useColor () const |
| Show whether colrs are used. | |
| virtual std::string | getLogColor (int logLevel) const |
| Get the color codes for various log levels. | |
| virtual int | messageCount (MSG::Level logLevel) const |
| Get the number of messages issued at a particular level. | |
Private Types | |
| typedef std::map< std::string, MSG::Color > | ColorMap |
| typedef std::map< std::string, std::ostream * > | LoggedStreamsMap_t |
Private Member Functions | |
| std::string | colTrans (std::string, int) |
| void | initColors (Property &prop) |
| void | setupColors (Property &prop) |
| void | setupLimits (Property &prop) |
| void | setupThreshold (Property &prop) |
| void | setupLogStreams () |
| void | tee (const std::string &sourceName, const std::string &logFileName, const std::set< std::string > &declaredOutFileNames) |
Private Attributes | |
| std::ostream * | m_defaultStream |
| Pointer to the output stream. | |
| Message | m_defaultMessage |
| Default Message. | |
| StreamMap | m_streamMap |
| Stream map. | |
| MessageMap | m_messageMap |
| Message map. | |
| ThresholdMap | m_thresholdMap |
| Output level threshold map. | |
| std::string | m_defaultFormat |
| Default format for the messages. | |
| std::string | m_defaultTimeFormat |
| Default format for timestamps in the messages. | |
| StringArrayProperty | m_thresholdProp [MSG::NUM_LEVELS] |
| Properties controling. | |
| BooleanProperty | m_color |
| BooleanProperty | m_stats |
| UnsignedIntegerProperty | m_statLevel |
| StringArrayProperty | m_logColors [MSG::NUM_LEVELS] |
| IntegerProperty | m_msgLimit [MSG::NUM_LEVELS] |
| std::string | m_logColorCodes [MSG::NUM_LEVELS] |
| std::map< std::string, msgAry > | m_sourceMap |
| BooleanProperty | m_suppress |
| ColorMap | m_colMap |
| int | m_msgCount [MSG::NUM_LEVELS] |
| std::map< std::string, std::string > | m_loggedStreamsName |
| LoggedStreamsMap_t | m_loggedStreams |
| boost::mutex | m_reportMutex |
| Mutex to synchronize multiple threads printing. | |
| boost::mutex | m_messageMapMutex |
| Mutex to synchronize multiple access to m_messageMap. | |
| boost::mutex | m_thresholdMapMutex |
| Mutex to synchronize multiple access to m_thresholdMap (. | |
Classes | |
| struct | msgAry |
| typedef std::pair< std::string, std::ostream* > MessageSvc::NamedStream |
Definition at line 34 of file MessageSvc.h.
| typedef std::multimap< int, NamedStream > MessageSvc::StreamMap |
Definition at line 35 of file MessageSvc.h.
| typedef std::multimap< StatusCode, Message > MessageSvc::MessageMap |
Definition at line 36 of file MessageSvc.h.
| typedef std::map< std::string, int > MessageSvc::ThresholdMap |
Definition at line 37 of file MessageSvc.h.
typedef std::map<std::string, MSG::Color> MessageSvc::ColorMap [private] |
Definition at line 149 of file MessageSvc.h.
typedef std::map<std::string, std::ostream*> MessageSvc::LoggedStreamsMap_t [private] |
Definition at line 155 of file MessageSvc.h.
| MessageSvc::MessageSvc | ( | const std::string & | name, | |
| ISvcLocator * | svcloc | |||
| ) |
Definition at line 23 of file MessageSvc.cpp.
References MSG::ALWAYS, std::cout, MSG::DEBUG, MSG::ERROR, MSG::FATAL, Message::getDefaultFormat(), Message::getDefaultTimeFormat(), MSG::INFO, initColors(), levelNames, MSG::NIL, MSG::NUM_LEVELS, setupColors(), setupLimits(), setupThreshold(), MSG::VERBOSE, and MSG::WARNING.
00024 : Service( name, svcloc ) { 00025 m_defaultStream = &std::cout; 00026 m_outputLevel = MSG::NIL; 00027 declareProperty( "Format", m_defaultFormat = Message::getDefaultFormat() ); 00028 declareProperty( "timeFormat", m_defaultTimeFormat = Message::getDefaultTimeFormat() ); 00029 declareProperty( "showStats", m_stats = false ); 00030 declareProperty( "statLevel", m_statLevel = 0 ); 00031 00032 // Special properties to control output level of individual sources 00033 declareProperty( "setVerbose", m_thresholdProp[MSG::VERBOSE] ); 00034 declareProperty( "setDebug", m_thresholdProp[MSG::DEBUG] ); 00035 declareProperty( "setInfo", m_thresholdProp[MSG::INFO] ); 00036 declareProperty( "setWarning", m_thresholdProp[MSG::WARNING] ); 00037 declareProperty( "setError", m_thresholdProp[MSG::ERROR] ); 00038 declareProperty( "setFatal", m_thresholdProp[MSG::FATAL] ); 00039 declareProperty( "setAlways", m_thresholdProp[MSG::ALWAYS] ); 00040 00041 declareProperty( "useColors", m_color=false); 00042 m_color.declareUpdateHandler(&MessageSvc::initColors, this); 00043 00044 declareProperty( "fatalColorCode", m_logColors[MSG::FATAL] ); 00045 declareProperty( "errorColorCode", m_logColors[MSG::ERROR] ); 00046 declareProperty( "warningColorCode", m_logColors[MSG::WARNING] ); 00047 declareProperty( "infoColorCode", m_logColors[MSG::INFO] ); 00048 declareProperty( "debugColorCode", m_logColors[MSG::DEBUG] ); 00049 declareProperty( "verboseColorCode", m_logColors[MSG::VERBOSE] ); 00050 declareProperty( "alwaysColorCode", m_logColors[MSG::ALWAYS] ); 00051 00052 const int defaultLimit = 500; 00053 declareProperty( "fatalLimit", m_msgLimit[MSG::FATAL] = defaultLimit ); 00054 declareProperty( "errorLimit", m_msgLimit[MSG::ERROR] = defaultLimit ); 00055 declareProperty( "warningLimit", m_msgLimit[MSG::WARNING] = defaultLimit ); 00056 declareProperty( "infoLimit", m_msgLimit[MSG::INFO] = defaultLimit ); 00057 declareProperty( "debugLimit", m_msgLimit[MSG::DEBUG] = defaultLimit ); 00058 declareProperty( "verboseLimit", m_msgLimit[MSG::VERBOSE] = defaultLimit ); 00059 declareProperty( "alwaysLimit", m_msgLimit[MSG::ALWAYS] = 0 ); 00060 00061 declareProperty( "defaultLimit", m_msgLimit[MSG::NIL] = defaultLimit ); 00062 00063 declareProperty( "enableSuppression", m_suppress = false ); 00064 00065 declareProperty( "loggedStreams", 00066 m_loggedStreamsName, 00067 "MessageStream sources we want to dump into a logfile" ); 00068 00069 for (int ic=0; ic<MSG::NUM_LEVELS; ++ic) { 00070 m_logColors[ic].declareUpdateHandler(&MessageSvc::setupColors, this); 00071 m_msgLimit[ic].declareUpdateHandler(&MessageSvc::setupLimits, this); 00072 m_thresholdProp[ic].declareUpdateHandler(&MessageSvc::setupThreshold, this); 00073 } 00074 00075 levelNames[0] = "NIL"; 00076 levelNames[1] = "VERBOSE"; 00077 levelNames[2] = "DEBUG"; 00078 levelNames[3] = "INFO"; 00079 levelNames[4] = "WARNING"; 00080 levelNames[5] = "ERROR"; 00081 levelNames[6] = "FATAL"; 00082 levelNames[7] = "ALWAYS"; 00083 00084 for (int i=0; i<MSG::NUM_LEVELS; ++i) { 00085 m_msgCount[i] = 0; 00086 } 00087 00088 }
| MessageSvc::~MessageSvc | ( | ) | [virtual] |
Definition at line 92 of file MessageSvc.cpp.
References m_loggedStreams.
00093 { 00094 // closing log-files, if any 00095 LoggedStreamsMap_t::iterator iStream = m_loggedStreams.begin(); 00096 LoggedStreamsMap_t::iterator endStream = m_loggedStreams.end(); 00097 for ( ; iStream != endStream; ++iStream ) { 00098 delete iStream->second; 00099 iStream->second = 0; 00100 } 00101 }
| StatusCode MessageSvc::reinitialize | ( | ) | [virtual] |
Reinitialize Service.
Reimplemented from Service.
Definition at line 141 of file MessageSvc.cpp.
References initialize(), Service::m_state, and Gaudi::StateMachine::OFFLINE.
00141 { 00142 m_state = Gaudi::StateMachine::OFFLINE; 00143 return initialize(); 00144 }
| StatusCode MessageSvc::initialize | ( | ) | [virtual] |
Initialize Service.
Reimplemented from Service.
Definition at line 106 of file MessageSvc.cpp.
References MSG::BLACK, MSG::BLUE, MSG::CYAN, MSG::GREEN, Service::initialize(), StatusCode::isFailure(), m_colMap, m_color, Service::m_messageSvc, MSG::PURPLE, MSG::RED, Service::setProperties(), setupLogStreams(), StatusCode::SUCCESS, MSG::WHITE, and MSG::YELLOW.
Referenced by reinitialize().
00106 { 00107 StatusCode sc; 00108 sc = Service::initialize(); 00109 if( sc.isFailure() ) return sc; 00110 // Release pointer to myself done in Service base class 00111 if( m_messageSvc ) { 00112 m_messageSvc->release(); 00113 m_messageSvc = 0; 00114 } 00115 // Set my own properties 00116 sc = setProperties(); 00117 if (sc.isFailure()) return sc; 00118 00119 #ifdef _WIN32 00120 m_color = false; 00121 #endif 00122 00123 m_colMap["black"] = MSG::BLACK; 00124 m_colMap["red"] = MSG::RED; 00125 m_colMap["green"] = MSG::GREEN; 00126 m_colMap["yellow"] = MSG::YELLOW; 00127 m_colMap["blue"] = MSG::BLUE; 00128 m_colMap["purple"] = MSG::PURPLE; 00129 m_colMap["cyan"] = MSG::CYAN; 00130 m_colMap["white"] = MSG::WHITE; 00131 00132 // make sure the map of logged stream names is initialized 00133 setupLogStreams(); 00134 00135 return StatusCode::SUCCESS; 00136 }
| StatusCode MessageSvc::finalize | ( | ) | [virtual] |
Finalize Service.
Reimplemented from Service.
Definition at line 319 of file MessageSvc.cpp.
References cout, endl(), levelNames, m_msgLimit, m_sourceMap, m_statLevel, m_stats, m_suppress, MSG::NUM_LEVELS, std::basic_ostringstream< _CharT, _Traits, _Alloc >::setf(), std::basic_ostringstream< _CharT, _Traits, _Alloc >::str(), StatusCode::SUCCESS, PropertyWithValue< TYPE >::value(), and std::basic_ostringstream< _CharT, _Traits, _Alloc >::width().
00319 { 00320 00321 m_suppress = false; 00322 00323 std::ostringstream os; 00324 00325 if (m_stats) { 00326 os << "Summarizing all message counts" << endl; 00327 } else { 00328 os << "Listing sources of suppressed message: " << endl; 00329 } 00330 00331 os << "=====================================================" << endl; 00332 os << " Message Source | Level | Count" << endl; 00333 os << "-----------------------------+---------+-------------" << endl; 00334 00335 00336 bool found(false); 00337 00338 std::map<std::string,msgAry>::const_iterator itr; 00339 for (itr=m_sourceMap.begin(); itr!=m_sourceMap.end(); ++itr) { 00340 for (unsigned int ic = 0; ic < MSG::NUM_LEVELS; ++ic) { 00341 if ( (itr->second.msg[ic] >= m_msgLimit[ic] && m_msgLimit[ic] != 0 ) || 00342 (m_stats && itr->second.msg[ic] > 0 && ic >= m_statLevel.value()) ) { 00343 os << " "; 00344 os.width(28); 00345 os.setf(ios_base::left,ios_base::adjustfield); 00346 os << itr->first; 00347 00348 os << "|"; 00349 00350 os.width(8); 00351 os.setf(ios_base::right,ios_base::adjustfield); 00352 os << levelNames[ic]; 00353 00354 os << " |"; 00355 00356 os.width(9); 00357 os << itr->second.msg[ic]; 00358 00359 os << endl; 00360 00361 found = true; 00362 } 00363 } 00364 } 00365 os << "=====================================================" << endl; 00366 00367 if (found || m_stats) { 00368 cout << os.str(); 00369 } 00370 00371 return StatusCode::SUCCESS; 00372 }
| void MessageSvc::reportMessage | ( | const Message & | message | ) | [virtual] |
Report a message by sending a Message object to the message serivice.
| message | Reference to a message object |
Implements IMessageSvc.
Definition at line 398 of file MessageSvc.cpp.
References _itoa(), std::multimap< _Key, _Tp, _Compare, _Alloc >::end(), std::endl(), std::flush(), Message::getFormat(), Message::getSource(), Message::getType(), levelNames, std::multimap< _Key, _Tp, _Compare, _Alloc >::lower_bound(), m_color, m_defaultFormat, m_defaultTimeFormat, m_logColorCodes, m_loggedStreams, m_msgCount, m_msgLimit, m_reportMutex, m_sourceMap, m_stats, m_streamMap, m_suppress, MessageSvc::msgAry::msg, MSG::NUM_LEVELS, outputLevel(), Message::setFormat(), Message::setTimeFormat(), std::multimap< _Key, _Tp, _Compare, _Alloc >::upper_bound(), PropertyWithValue< TYPE >::value(), and MSG::WARNING.
Referenced by reportMessage().
00398 { 00399 boost::mutex::scoped_lock lock(m_reportMutex); 00400 00401 int key = msg.getType(); 00402 int nmsg; 00403 00404 m_msgCount[key] ++; 00405 00406 const Message *cmsg = &msg; 00407 00408 // processing logged streams 00409 if ( !m_loggedStreams.empty() ) { 00410 const LoggedStreamsMap_t::iterator iLog = m_loggedStreams.find( msg.getSource() ); 00411 if ( m_loggedStreams.end() != iLog ) { 00412 (*iLog->second) << *cmsg << std::endl; 00413 } 00414 } 00415 00416 if ( m_suppress.value() || m_stats.value() ) { 00417 00418 std::map<std::string,msgAry>::iterator itr = 00419 m_sourceMap.find(msg.getSource()); 00420 if (itr != m_sourceMap.end()) { 00421 itr->second.msg[key] += 1; 00422 nmsg = itr->second.msg[key]; 00423 } else { 00424 msgAry A; 00425 for (int i=0; i<MSG::NUM_LEVELS; ++i) { 00426 A.msg[i] = 0; 00427 } 00428 A.msg[key] = 1; 00429 m_sourceMap[msg.getSource()] = A; 00430 nmsg = 1; 00431 } 00432 00433 if (m_suppress.value()) { 00434 00435 if ( m_msgLimit[key] != 0 ) { 00436 if (nmsg == m_msgLimit[key]) { 00437 char lim[16]; 00438 std::string str = levelNames[key] + " message limit ("; 00439 str += ::_itoa(m_msgLimit[key].value(),lim,10); 00440 str += ") reached for "; 00441 str += msg.getSource() + ". Suppressing further output."; 00442 cmsg = new Message(msg.getSource(),MSG::WARNING,str); 00443 cmsg->setFormat(msg.getFormat()); 00444 } else if (nmsg > m_msgLimit[key]) { 00445 return; 00446 } 00447 } 00448 } 00449 00450 } 00451 00452 StreamMap::const_iterator first = m_streamMap.lower_bound( key ); 00453 if ( first != m_streamMap.end() ) { 00454 StreamMap::const_iterator last = m_streamMap.upper_bound( key ); 00455 while( first != last ) { 00456 std::ostream& stream = *( (*first).second.second ); 00457 stream << *cmsg << std::endl; 00458 first++; 00459 } 00460 } 00461 else if ( key >= outputLevel(msg.getSource()) ) { 00462 msg.setFormat(m_defaultFormat); 00463 msg.setTimeFormat(m_defaultTimeFormat); 00464 if (!m_color) { 00465 (*m_defaultStream) << *cmsg << std::endl << std::flush; 00466 } else { 00467 (*m_defaultStream) << m_logColorCodes[key] << *cmsg << "\033[m" 00468 << std::endl << std::flush; 00469 } 00470 } 00471 00472 if (cmsg != &msg) { delete cmsg; } 00473 00474 }
| void MessageSvc::reportMessage | ( | const StatusCode & | code, | |
| const std::string & | source = "" | |||
| ) | [virtual] |
Report an error to the message service.
The service will use the error code number for formating a human readible message
| code | Error code number | |
| source | Message source. Typically the alg/svc name |
Implements IMessageSvc.
Definition at line 509 of file MessageSvc.cpp.
References std::multimap< _Key, _Tp, _Compare, _Alloc >::end(), std::ends(), StatusCode::getCode(), Message::getType(), std::multimap< _Key, _Tp, _Compare, _Alloc >::lower_bound(), m_defaultMessage, m_messageMap, m_messageMapMutex, reportMessage(), Message::setSource(), std::basic_ostringstream< _CharT, _Traits, _Alloc >::str(), and std::multimap< _Key, _Tp, _Compare, _Alloc >::upper_bound().
00511 { 00512 boost::mutex::scoped_lock lock(m_messageMapMutex); 00513 00514 MessageMap::const_iterator first = m_messageMap.lower_bound( key ); 00515 if ( first != m_messageMap.end() ) { 00516 MessageMap::const_iterator last = m_messageMap.upper_bound( key ); 00517 while( first != last ) { 00518 Message msg = (*first).second; 00519 msg.setSource( source ); 00520 std::ostringstream os1; 00521 os1 << "Status Code " << key.getCode() << std::ends; 00522 Message stat_code1( source, msg.getType(), os1.str() ); 00523 reportMessage( stat_code1 ); 00524 reportMessage( msg ); 00525 first++; 00526 } 00527 } 00528 else { 00529 Message mesg = m_defaultMessage; 00530 mesg.setSource( source ); 00531 std::ostringstream os2; 00532 os2 << "Status Code " << key.getCode() << std::ends; 00533 Message stat_code2( source, mesg.getType(), os2.str() ); 00534 reportMessage( stat_code2 ); 00535 reportMessage( mesg ); 00536 } 00537 }
| void MessageSvc::reportMessage | ( | const char * | source, | |
| int | type, | |||
| const char * | message | |||
| ) | [virtual] |
Report a message by specifying the source, severity level and text.
The text is passed as C like character string to avoid extra copying.
| source | Message source. Typically the alg/svc name | |
| type | Severity level | |
| message | Text message |
Implements IMessageSvc.
Definition at line 482 of file MessageSvc.cpp.
References reportMessage().
00484 { 00485 Message msg( source, type, message); 00486 reportMessage( msg ); 00487 }
| void MessageSvc::reportMessage | ( | const std::string & | source, | |
| int | type, | |||
| const std::string & | message | |||
| ) | [virtual] |
Report a message by specifying the source, severity level and text.
| source | Message source. Typically the alg/svc name | |
| type | Severity level | |
| message | Text message |
Implements IMessageSvc.
Definition at line 495 of file MessageSvc.cpp.
References reportMessage().
00497 { 00498 Message msg( source, type, message); 00499 reportMessage( msg ); 00500 }
| void MessageSvc::insertMessage | ( | const StatusCode & | code, | |
| const Message & | message | |||
| ) | [virtual] |
Insert a message to be sent for a given status code into the error code repository.
| code | Status error code | |
| message | Message associated |
Implements IMessageSvc.
Definition at line 635 of file MessageSvc.cpp.
References std::multimap< _Key, _Tp, _Compare, _Alloc >::insert(), m_messageMap, and m_messageMapMutex.
00636 { 00637 boost::mutex::scoped_lock lock(m_messageMapMutex); 00638 00639 typedef MessageMap::value_type value_type; 00640 m_messageMap.insert( value_type( key, msg ) ); 00641 }
| void MessageSvc::eraseMessage | ( | ) | [virtual] |
Erase all messages associated to all status codes.
Implements IMessageSvc.
Definition at line 650 of file MessageSvc.cpp.
References std::multimap< _Key, _Tp, _Compare, _Alloc >::begin(), std::multimap< _Key, _Tp, _Compare, _Alloc >::end(), std::multimap< _Key, _Tp, _Compare, _Alloc >::erase(), m_messageMap, and m_messageMapMutex.
00651 { 00652 boost::mutex::scoped_lock lock(m_messageMapMutex); 00653 00654 m_messageMap.erase( m_messageMap.begin(), m_messageMap.end() ); 00655 }
| void MessageSvc::eraseMessage | ( | const StatusCode & | code | ) | [virtual] |
Erase message associated to a given status code.
Implements IMessageSvc.
Definition at line 664 of file MessageSvc.cpp.
References std::multimap< _Key, _Tp, _Compare, _Alloc >::erase(), m_messageMap, and m_messageMapMutex.
00665 { 00666 boost::mutex::scoped_lock lock(m_messageMapMutex); 00667 00668 m_messageMap.erase( key ); 00669 }
| void MessageSvc::eraseMessage | ( | const StatusCode & | code, | |
| const Message & | message | |||
| ) | [virtual] |
Erase a given message associated to a given status code.
| code | Status error code | |
| message | Message associated |
Implements IMessageSvc.
Definition at line 678 of file MessageSvc.cpp.
References std::multimap< _Key, _Tp, _Compare, _Alloc >::erase(), std::multimap< _Key, _Tp, _Compare, _Alloc >::lower_bound(), m_messageMap, m_messageMapMutex, and std::multimap< _Key, _Tp, _Compare, _Alloc >::upper_bound().
00679 { 00680 boost::mutex::scoped_lock lock(m_messageMapMutex); 00681 00682 bool changed = true; 00683 while( changed ) { 00684 changed = false; 00685 MessageMap::iterator first = m_messageMap.lower_bound( key ); 00686 MessageMap::iterator last = m_messageMap.upper_bound( key ); 00687 while( first != last ) { 00688 const Message& message = (*first).second; 00689 if ( message == msg ) { 00690 m_messageMap.erase( first ); 00691 changed = true; 00692 break; 00693 } 00694 } 00695 } 00696 }
| void MessageSvc::insertStream | ( | int | message_type, | |
| const std::string & | name, | |||
| std::ostream * | stream | |||
| ) | [virtual] |
Add a new stream for a message type (severity level).
| type | Severity level | |
| name | Stream name | |
| stream | Pointer to a C++ stream |
Implements IMessageSvc.
Definition at line 546 of file MessageSvc.cpp.
References std::multimap< _Key, _Tp, _Compare, _Alloc >::insert(), m_streamMap, and Service::name().
00549 { 00550 typedef StreamMap::value_type value_type; 00551 m_streamMap.insert( value_type( key, NamedStream(name,stream) ) ); 00552 }
| void MessageSvc::eraseStream | ( | ) | [virtual] |
Delete all the streams.
Implements IMessageSvc.
Definition at line 561 of file MessageSvc.cpp.
References std::multimap< _Key, _Tp, _Compare, _Alloc >::begin(), std::multimap< _Key, _Tp, _Compare, _Alloc >::end(), std::multimap< _Key, _Tp, _Compare, _Alloc >::erase(), and m_streamMap.
00562 { 00563 m_streamMap.erase( m_streamMap.begin(), m_streamMap.end() ); 00564 }
| void MessageSvc::eraseStream | ( | int | message_type | ) | [virtual] |
Delete all the streams for a given message type (severity level).
Implements IMessageSvc.
Definition at line 573 of file MessageSvc.cpp.
References std::multimap< _Key, _Tp, _Compare, _Alloc >::erase(), and m_streamMap.
00574 { 00575 m_streamMap.erase( message_type ); 00576 }
| void MessageSvc::eraseStream | ( | int | message_type, | |
| std::ostream * | stream | |||
| ) | [virtual] |
Delete a single stream for a given message type (severity level).
| type | Severity level | |
| stream | Pointer to a C++ stream |
Implements IMessageSvc.
Definition at line 585 of file MessageSvc.cpp.
References std::multimap< _Key, _Tp, _Compare, _Alloc >::erase(), std::multimap< _Key, _Tp, _Compare, _Alloc >::lower_bound(), m_streamMap, and std::multimap< _Key, _Tp, _Compare, _Alloc >::upper_bound().
00585 { 00586 if ( 0 != stream ) { 00587 bool changed = true; 00588 while( changed ) { 00589 changed = false; 00590 StreamMap::iterator first = m_streamMap.lower_bound( key ); 00591 StreamMap::iterator last = m_streamMap.upper_bound( key ); 00592 while( first != last ) { 00593 if ( (*first).second.second == stream ) { 00594 m_streamMap.erase( first ); 00595 changed = true; 00596 break; 00597 } 00598 } 00599 } 00600 } 00601 }
| void MessageSvc::eraseStream | ( | std::ostream * | stream | ) | [virtual] |
Delete all occurrences of a stream.
| stream | Pointer to a C++ stream |
Implements IMessageSvc.
Definition at line 610 of file MessageSvc.cpp.
References std::multimap< _Key, _Tp, _Compare, _Alloc >::begin(), std::multimap< _Key, _Tp, _Compare, _Alloc >::end(), std::multimap< _Key, _Tp, _Compare, _Alloc >::erase(), and m_streamMap.
00610 { 00611 if ( 0 != stream ) { 00612 bool changed = true; 00613 while( changed ) { 00614 changed = false; 00615 StreamMap::iterator first = m_streamMap.begin(); 00616 while( first != m_streamMap.end() ) { 00617 if ( (*first).second.second == stream ) { 00618 m_streamMap.erase( first ); 00619 changed = true; 00620 break; 00621 } 00622 } 00623 } 00624 } 00625 }
| virtual std::ostream* MessageSvc::defaultStream | ( | ) | const [inline, virtual] |
Get the default stream.
Implements IMessageSvc.
Definition at line 91 of file MessageSvc.h.
References m_defaultStream.
00091 { 00092 return m_defaultStream; 00093 }
| virtual void MessageSvc::setDefaultStream | ( | std::ostream * | stream | ) | [inline, virtual] |
Set the default stream.
| stream | Pointer to a C++ stream |
Implements IMessageSvc.
Definition at line 96 of file MessageSvc.h.
References m_defaultStream, and m_reportMutex.
00096 { 00097 boost::mutex::scoped_lock lock(m_reportMutex); 00098 m_defaultStream = stream; 00099 }
| int MessageSvc::outputLevel | ( | ) | const [virtual] |
Retrieve the current output level threshold.
Implements IMessageSvc.
Definition at line 712 of file MessageSvc.cpp.
References Service::m_outputLevel.
Referenced by reportMessage().
00712 { 00713 // --------------------------------------------------------------------------- 00714 return m_outputLevel; 00715 }
| int MessageSvc::outputLevel | ( | const std::string & | source | ) | const [virtual] |
Retrieve the current output level threshold for a given message source.
| source | Message source. Typically the alg/svc name |
Implements IMessageSvc.
Definition at line 717 of file MessageSvc.cpp.
References Service::m_outputLevel, m_thresholdMap, and m_thresholdMapMutex.
00717 { 00718 // --------------------------------------------------------------------------- 00719 boost::mutex::scoped_lock lock(m_thresholdMapMutex); 00720 00721 ThresholdMap::const_iterator it; 00722 00723 it = m_thresholdMap.find( source ); 00724 if( it != m_thresholdMap.end() ) { 00725 return (*it).second; 00726 } 00727 else { 00728 return m_outputLevel; 00729 } 00730 }
| void MessageSvc::setOutputLevel | ( | int | new_level | ) | [virtual] |
Set new global output level threshold.
Implements IMessageSvc.
Definition at line 733 of file MessageSvc.cpp.
References Service::m_outputLevel.
Referenced by setupThreshold().
00733 { 00734 // --------------------------------------------------------------------------- 00735 m_outputLevel = new_level; 00736 }
| void MessageSvc::setOutputLevel | ( | const std::string & | source, | |
| int | new_level | |||
| ) | [virtual] |
Set new output level threshold for a given message source.
| source | Message source | |
| new_level | Severity level |
Implements IMessageSvc.
Definition at line 739 of file MessageSvc.cpp.
References m_thresholdMap, and m_thresholdMapMutex.
00739 { 00740 // --------------------------------------------------------------------------- 00741 boost::mutex::scoped_lock lock(m_thresholdMapMutex); 00742 00743 /* 00744 std::pair<ThresholdMap::iterator, bool> p; 00745 p = m_thresholdMap.insert(ThresholdMap::value_type( source, level) ); 00746 if( p.second == false ) { 00747 // Already esisting an output level for that source. Erase and enter it again 00748 m_thresholdMap.erase ( p.first ); 00749 m_thresholdMap.insert(ThresholdMap::value_type( source, level) ); 00750 } 00751 */ 00752 m_thresholdMap[source] = level; 00753 }
| StatusCode MessageSvc::queryInterface | ( | const InterfaceID & | riid, | |
| void ** | ppvUnknown | |||
| ) | [virtual] |
Query interfaces of Interface.
| riid | ID of Interface to be retrieved | |
| ppvUnknown | Pointer to Location for interface pointer |
Reimplemented from Service.
Definition at line 699 of file MessageSvc.cpp.
References Service::addRef(), IID_IMessageSvc, Service::queryInterface(), and StatusCode::SUCCESS.
00699 { 00700 // --------------------------------------------------------------------------- 00701 if ( IID_IMessageSvc == riid ) { 00702 *ppvInterface = (IMessageSvc*)this; 00703 } 00704 else { 00705 return Service::queryInterface(riid, ppvInterface); 00706 } 00707 addRef(); 00708 return StatusCode::SUCCESS; 00709 }
| virtual bool MessageSvc::useColor | ( | ) | const [inline, virtual] |
Show whether colrs are used.
Implements IMessageSvc.
Definition at line 117 of file MessageSvc.h.
References m_color.
00117 { return m_color; }
| std::string MessageSvc::getLogColor | ( | int | logLevel | ) | const [virtual] |
Get the color codes for various log levels.
| logLevel | Logging level |
Implements IMessageSvc.
Definition at line 756 of file MessageSvc.cpp.
References m_logColorCodes, and MSG::NUM_LEVELS.
00756 { 00757 // --------------------------------------------------------------------------- 00758 if (logLevel < MSG::NUM_LEVELS) { 00759 return m_logColorCodes[logLevel]; 00760 } else { 00761 return ""; 00762 } 00763 }
| int MessageSvc::messageCount | ( | MSG::Level | logLevel | ) | const [virtual] |
Get the number of messages issued at a particular level.
Implements IMessageSvc.
Definition at line 766 of file MessageSvc.cpp.
References m_msgCount.
00766 { 00767 00768 return m_msgCount[level]; 00769 00770 }
| std::string MessageSvc::colTrans | ( | std::string | , | |
| int | ||||
| ) | [private] |
Definition at line 375 of file MessageSvc.cpp.
References m_colMap, and std::basic_ostringstream< _CharT, _Traits, _Alloc >::str().
Referenced by setupColors().
00375 { 00376 ColorMap::const_iterator itr = m_colMap.find(col); 00377 int icol; 00378 if (itr != m_colMap.end()) { 00379 icol = offset + itr->second; 00380 } else { 00381 icol = offset + 8; 00382 } 00383 std::ostringstream os1; 00384 00385 os1 << icol; 00386 00387 return os1.str(); 00388 00389 }
| void MessageSvc::initColors | ( | Property & | prop | ) | [private] |
Definition at line 148 of file MessageSvc.cpp.
References MSG::ERROR, MSG::FATAL, m_color, m_logColors, MSG::NUM_LEVELS, std::vector< _Tp, _Alloc >::push_back(), PropertyWithVerifier< TYPE, VERIFIER >::set(), setupColors(), and MSG::WARNING.
Referenced by MessageSvc().
00148 { 00149 00150 if (m_color == true) { 00151 00152 if (m_logColors[MSG::FATAL].value().size() == 0) { 00153 vector<string> fatDef; 00154 fatDef.push_back( "[94;101;1m" ); 00155 m_logColors[MSG::FATAL].set( fatDef ); 00156 } else { 00157 MessageSvc::setupColors( m_logColors[MSG::FATAL] ); 00158 } 00159 00160 if (m_logColors[MSG::ERROR].value().size() == 0) { 00161 vector<string> errDef; 00162 errDef.push_back( "[97;101;1m" ); 00163 m_logColors[MSG::ERROR].set( errDef ); 00164 } else { 00165 MessageSvc::setupColors( m_logColors[MSG::ERROR] ); 00166 } 00167 00168 if (m_logColors[MSG::WARNING].value().size() == 0) { 00169 vector<string> warDef; 00170 warDef.push_back( "[93;1m" ); 00171 m_logColors[MSG::WARNING].set( warDef ); 00172 } else { 00173 MessageSvc::setupColors( m_logColors[MSG::WARNING] ); 00174 } 00175 00176 } else { 00177 00178 // reset all color codes; 00179 for (int ic=0; ic<MSG::NUM_LEVELS; ++ic) { 00180 vector<string> def; 00181 m_logColors[ic].set( def ); 00182 } 00183 00184 } 00185 00186 }
| void MessageSvc::setupColors | ( | Property & | prop | ) | [private] |
Definition at line 190 of file MessageSvc.cpp.
References MSG::ALWAYS, colTrans(), cout, MSG::DEBUG, endl(), MSG::ERROR, MSG::FATAL, MSG::INFO, m_color, m_logColorCodes, m_logColors, Property::name(), PropertyWithValue< TYPE >::value(), MSG::VERBOSE, and MSG::WARNING.
Referenced by initColors(), and MessageSvc().
00190 { 00191 00192 if (! m_color) return; 00193 00194 int ic; 00195 if (prop.name() == "fatalColorCode") { 00196 ic = MSG::FATAL; 00197 } else if (prop.name() == "errorColorCode") { 00198 ic = MSG::ERROR; 00199 } else if (prop.name() == "warningColorCode") { 00200 ic = MSG::WARNING; 00201 } else if (prop.name() == "infoColorCode") { 00202 ic = MSG::INFO; 00203 } else if (prop.name() == "debugColorCode") { 00204 ic = MSG::DEBUG; 00205 } else if (prop.name() == "verboseColorCode") { 00206 ic = MSG::VERBOSE; 00207 } else if (prop.name() == "alwaysColorCode") { 00208 ic = MSG::ALWAYS; 00209 } else { 00210 cout << "ERROR: Unknown message color parameter: " << prop.name() 00211 << endl; 00212 return; 00213 } 00214 00215 string code; 00216 vector<string>::const_iterator itr; 00217 itr = m_logColors[ic].value().begin(); 00218 00219 if ( m_logColors[ic].value().size() == 1 ) { 00220 00221 if (*itr == "") { 00222 code = ""; 00223 } else if (itr->substr(0,1) == "[") { 00224 code = "\033" + *itr; 00225 } else { 00226 code = "\033[" + colTrans(*itr, 90) + ";1m"; 00227 } 00228 00229 } else if (m_logColors[ic].value().size() == 2) { 00230 vector<string>::const_iterator itr2 = itr + 1; 00231 00232 code = "\033[" + colTrans(*itr, 90) + ";" 00233 + colTrans(*itr2, 100) + ";1m"; 00234 00235 } 00236 00237 m_logColorCodes[ic] = code; 00238 00239 }
| void MessageSvc::setupLimits | ( | Property & | prop | ) | [private] |
Definition at line 242 of file MessageSvc.cpp.
References MSG::ALWAYS, cout, MSG::DEBUG, endl(), MSG::ERROR, MSG::FATAL, MSG::INFO, m_msgLimit, Property::name(), MSG::NIL, MSG::NUM_LEVELS, MSG::VERBOSE, and MSG::WARNING.
Referenced by MessageSvc().
00242 { 00243 00244 int ic = 0; 00245 if (prop.name() == "fatalLimit") { 00246 ic = MSG::FATAL; 00247 } else if (prop.name() == "errorLimit") { 00248 ic = MSG::ERROR; 00249 } else if (prop.name() == "warningLimit") { 00250 ic = MSG::WARNING; 00251 } else if (prop.name() == "infoLimit") { 00252 ic = MSG::INFO; 00253 } else if (prop.name() == "debugLimit") { 00254 ic = MSG::DEBUG; 00255 } else if (prop.name() == "verboseLimit") { 00256 ic = MSG::VERBOSE; 00257 } else if (prop.name() == "alwaysLimit") { 00258 IntegerProperty *p = dynamic_cast<IntegerProperty*>(&prop); 00259 if (p && p->value() != 0) { 00260 cout << "MessageSvc ERROR: cannot suppress ALWAYS messages" << endl; 00261 p->setValue(0); 00262 } 00263 ic = MSG::ALWAYS; 00264 } else if (prop.name() == "defaultLimit") { 00265 for (int i = MSG::VERBOSE; i< MSG::NUM_LEVELS; ++i) { 00266 if (i != MSG::ALWAYS) { 00267 m_msgLimit[i] = m_msgLimit[MSG::NIL].value(); 00268 } 00269 } 00270 } else { 00271 cout << "MessageSvc ERROR: Unknown message limit parameter: " 00272 << prop.name() << endl; 00273 return; 00274 } 00275 00276 }
| void MessageSvc::setupThreshold | ( | Property & | prop | ) | [private] |
Definition at line 279 of file MessageSvc.cpp.
References MSG::ALWAYS, std::cerr, cerr, MSG::DEBUG, endl(), MSG::ERROR, MSG::FATAL, MSG::INFO, Property::name(), setOutputLevel(), PropertyWithValue< TYPE >::value(), MSG::VERBOSE, and MSG::WARNING.
Referenced by MessageSvc().
00279 { 00280 00281 int ic = 0; 00282 if (prop.name() == "setFatal") { 00283 ic = MSG::FATAL; 00284 } else if (prop.name() == "setError") { 00285 ic = MSG::ERROR; 00286 } else if (prop.name() == "setWarning") { 00287 ic = MSG::WARNING; 00288 } else if (prop.name() == "setInfo") { 00289 ic = MSG::INFO; 00290 } else if (prop.name() == "setDebug") { 00291 ic = MSG::DEBUG; 00292 } else if (prop.name() == "setVerbose") { 00293 ic = MSG::VERBOSE; 00294 } else if (prop.name() == "setAlways") { 00295 ic = MSG::ALWAYS; 00296 } else { 00297 cerr << "MessageSvc ERROR: Unknown message theshold parameter: " 00298 << prop.name() << endl; 00299 return; 00300 } 00301 00302 StringArrayProperty *sap = dynamic_cast<StringArrayProperty*>( &prop); 00303 if (sap == 0) { 00304 std::cerr << "could not dcast " << prop.name() 00305 << " to a StringArrayProperty (which it should be!)" << endl; 00306 return; 00307 } else { 00308 std::vector<std::string>::const_iterator itr; 00309 for ( itr = sap->value().begin(); 00310 itr != sap->value().end(); 00311 ++itr) { 00312 setOutputLevel( *itr, ic ); 00313 } 00314 } 00315 00316 }
| void MessageSvc::setupLogStreams | ( | ) | [private] |
Definition at line 773 of file MessageSvc.cpp.
References m_loggedStreams, m_loggedStreamsName, and tee().
Referenced by initialize().
00774 { 00775 // reset state 00776 for ( LoggedStreamsMap_t::iterator iLog = m_loggedStreams.begin(); 00777 iLog != m_loggedStreams.end(); 00778 ++iLog ) { 00779 delete iLog->second; 00780 } 00781 m_loggedStreams.clear(); 00782 00783 typedef std::map<std::string,std::string> StreamMap_t; 00784 const StreamMap_t& streamMap = m_loggedStreamsName; 00785 typedef StreamMap_t::const_iterator StreamMapIter; 00786 00787 for ( StreamMapIter iProp = streamMap.begin(), iEnd = streamMap.end(); 00788 iProp != iEnd; 00789 ++iProp ) { 00790 00791 const std::string sourceName = iProp->first; 00792 const std::string outFileName = iProp->second; 00793 00794 std::set<std::string> outFileNames; 00795 for ( StreamMapIter jProp = streamMap.begin(); 00796 jProp != iEnd; 00797 ++jProp ) { 00798 if ( jProp->first != iProp->first ) { 00799 outFileNames.insert( jProp->second ); 00800 } 00801 } 00802 00803 tee( sourceName, outFileName, outFileNames ); 00804 00805 }//> loop over property entries 00806 00807 return; 00808 }
| void MessageSvc::tee | ( | const std::string & | sourceName, | |
| const std::string & | logFileName, | |||
| const std::set< std::string > & | declaredOutFileNames | |||
| ) | [private] |
Definition at line 811 of file MessageSvc.cpp.
References std::basic_string< _CharT, _Traits, _Alloc >::c_str(), std::basic_ofstream< _CharT, _Traits >::close(), std::set< _Key, _Compare, _Alloc >::end(), std::set< _Key, _Compare, _Alloc >::find(), std::basic_ofstream< _CharT, _Traits >::good(), m_loggedStreams, std::ios_base::out, and std::ios_base::trunc.
Referenced by setupLogStreams().
00814 { 00815 const std::ios_base::openmode openMode = std::ios_base::out | 00816 std::ios_base::trunc; 00817 00818 LoggedStreamsMap_t::iterator iEnd = m_loggedStreams.end(); 00819 LoggedStreamsMap_t::iterator iStream = m_loggedStreams.find( sourceName ); 00820 if ( iStream != iEnd ) { 00821 delete iStream->second; 00822 iStream->second = 0; 00823 m_loggedStreams.erase( iStream ); 00824 } 00825 00826 // before creating a new ofstream, make sure there is no already existing 00827 // one with the same file name... 00828 iEnd = m_loggedStreams.end(); 00829 for ( iStream = m_loggedStreams.begin(); iStream != iEnd; ++iStream ) { 00830 if ( outFileNames.find( outFileName ) != outFileNames.end() ) { 00831 m_loggedStreams[sourceName] = m_loggedStreams[iStream->first]; 00832 return; 00833 } 00834 } 00835 00836 std::ofstream * out = new std::ofstream( outFileName.c_str(), openMode ); 00837 00838 if ( !out->good() ) { 00839 out->close(); 00840 delete out; 00841 return; 00842 } 00843 00844 m_loggedStreams[sourceName] = out; 00845 00846 return; 00847 }
std::ostream* MessageSvc::m_defaultStream [private] |
Pointer to the output stream.
Definition at line 126 of file MessageSvc.h.
Referenced by defaultStream(), and setDefaultStream().
Message MessageSvc::m_defaultMessage [private] |
StreamMap MessageSvc::m_streamMap [private] |
Stream map.
Definition at line 128 of file MessageSvc.h.
Referenced by eraseStream(), insertStream(), and reportMessage().
MessageMap MessageSvc::m_messageMap [private] |
Message map.
Definition at line 129 of file MessageSvc.h.
Referenced by eraseMessage(), insertMessage(), and reportMessage().
ThresholdMap MessageSvc::m_thresholdMap [private] |
Output level threshold map.
Definition at line 130 of file MessageSvc.h.
Referenced by outputLevel(), and setOutputLevel().
std::string MessageSvc::m_defaultFormat [private] |
Default format for the messages.
Definition at line 131 of file MessageSvc.h.
Referenced by reportMessage().
std::string MessageSvc::m_defaultTimeFormat [private] |
Default format for timestamps in the messages.
Definition at line 132 of file MessageSvc.h.
Referenced by reportMessage().
StringArrayProperty MessageSvc::m_thresholdProp[MSG::NUM_LEVELS] [private] |
BooleanProperty MessageSvc::m_color [private] |
Definition at line 134 of file MessageSvc.h.
Referenced by initColors(), initialize(), reportMessage(), setupColors(), and useColor().
BooleanProperty MessageSvc::m_stats [private] |
StringArrayProperty MessageSvc::m_logColors[MSG::NUM_LEVELS] [private] |
IntegerProperty MessageSvc::m_msgLimit[MSG::NUM_LEVELS] [private] |
Definition at line 138 of file MessageSvc.h.
Referenced by finalize(), reportMessage(), and setupLimits().
std::string MessageSvc::m_logColorCodes[MSG::NUM_LEVELS] [private] |
Definition at line 140 of file MessageSvc.h.
Referenced by getLogColor(), reportMessage(), and setupColors().
std::map<std::string,msgAry> MessageSvc::m_sourceMap [private] |
BooleanProperty MessageSvc::m_suppress [private] |
ColorMap MessageSvc::m_colMap [private] |
int MessageSvc::m_msgCount[MSG::NUM_LEVELS] [private] |
Definition at line 156 of file MessageSvc.h.
Referenced by reportMessage(), setupLogStreams(), tee(), and ~MessageSvc().
boost::mutex MessageSvc::m_reportMutex [mutable, private] |
Mutex to synchronize multiple threads printing.
Definition at line 169 of file MessageSvc.h.
Referenced by reportMessage(), and setDefaultStream().
boost::mutex MessageSvc::m_messageMapMutex [mutable, private] |
Mutex to synchronize multiple access to m_messageMap.
Definition at line 172 of file MessageSvc.h.
Referenced by eraseMessage(), insertMessage(), and reportMessage().
boost::mutex MessageSvc::m_thresholdMapMutex [mutable, private] |
Mutex to synchronize multiple access to m_thresholdMap (.
Definition at line 176 of file MessageSvc.h.
Referenced by outputLevel(), and setOutputLevel().