| # Gaudi Framework, version v21r9 |

Home |  | Generated: 3 May 2010

# MessageSvc Class Reference

`#include <MessageSvc.h>`

Inheritance diagram for MessageSvc:

[legend]
Collaboration diagram for MessageSvc:

[legend]

List of all members.

## 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 service.
virtual void | reportMessage (const Message &msg, int outputLevel)
| Report a message by sending a Message object to the message service.
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
| get the `Service's` output level
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 bool | useColor () const
| Show whether colors 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::recursive_mutex | m_reportMutex
| Mutex to synchronize multiple threads printing.
boost::recursive_mutex | m_messageMapMutex
| Mutex to synchronize multiple access to m_messageMap.
boost::recursive_mutex | m_thresholdMapMutex
| Mutex to synchronize multiple access to m_thresholdMap (.
## Classes
struct | MsgAry
| Private helper class to keep the count of messages of a type (MSG::LEVEL). More...

## Detailed Description

Definition at line 32 of file MessageSvc.h.

## Member Typedef Documentation

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 162 of file MessageSvc.h.

typedef std::map<std::string, std::ostream*> MessageSvc::LoggedStreamsMap_t`[private]`

Definition at line 168 of file MessageSvc.h.

## Constructor & Destructor Documentation

MessageSvc::MessageSvc | ( | const std::string & | name,
|  | ISvcLocator * | svcloc |
| ) |  |  |

Definition at line 28 of file MessageSvc.cpp.

    00029   : base_class( name, svcloc ) {
    00030   m_defaultStream = &std::cout;
    00031   m_outputLevel   = MSG::NIL;
    00032   declareProperty( "Format",      m_defaultFormat = Message::getDefaultFormat() );
    00033   declareProperty( "timeFormat",  m_defaultTimeFormat = Message::getDefaultTimeFormat() );
    00034   declareProperty( "showStats",   m_stats = false );
    00035   declareProperty( "statLevel",   m_statLevel = 0 );
    00036
    00037   // Special properties to control output level of individual sources
    00038   declareProperty( "setVerbose",  m_thresholdProp[MSG::VERBOSE] );
    00039   declareProperty( "setDebug",    m_thresholdProp[MSG::DEBUG] );
    00040   declareProperty( "setInfo",     m_thresholdProp[MSG::INFO] );
    00041   declareProperty( "setWarning",  m_thresholdProp[MSG::WARNING] );
    00042   declareProperty( "setError",    m_thresholdProp[MSG::ERROR] );
    00043   declareProperty( "setFatal",    m_thresholdProp[MSG::FATAL] );
    00044   declareProperty( "setAlways",   m_thresholdProp[MSG::ALWAYS] );
    00045
    00046   declareProperty( "useColors",        m_color=false);
    00047   m_color.declareUpdateHandler(&MessageSvc::initColors, this);
    00048
    00049   declareProperty( "fatalColorCode",   m_logColors[MSG::FATAL] );
    00050   declareProperty( "errorColorCode",   m_logColors[MSG::ERROR] );
    00051   declareProperty( "warningColorCode", m_logColors[MSG::WARNING] );
    00052   declareProperty( "infoColorCode",    m_logColors[MSG::INFO] );
    00053   declareProperty( "debugColorCode",   m_logColors[MSG::DEBUG] );
    00054   declareProperty( "verboseColorCode", m_logColors[MSG::VERBOSE] );
    00055   declareProperty( "alwaysColorCode",  m_logColors[MSG::ALWAYS] );
    00056
    00057   const int defaultLimit = 500;
    00058   declareProperty( "fatalLimit",    m_msgLimit[MSG::FATAL]   = defaultLimit );
    00059   declareProperty( "errorLimit",    m_msgLimit[MSG::ERROR]   = defaultLimit );
    00060   declareProperty( "warningLimit",  m_msgLimit[MSG::WARNING] = defaultLimit );
    00061   declareProperty( "infoLimit",     m_msgLimit[MSG::INFO]    = defaultLimit );
    00062   declareProperty( "debugLimit",    m_msgLimit[MSG::DEBUG]   = defaultLimit );
    00063   declareProperty( "verboseLimit",  m_msgLimit[MSG::VERBOSE] = defaultLimit );
    00064   declareProperty( "alwaysLimit",   m_msgLimit[MSG::ALWAYS]  = 0 );
    00065
    00066   declareProperty( "defaultLimit",  m_msgLimit[MSG::NIL]     = defaultLimit );
    00067
    00068   declareProperty( "enableSuppression", m_suppress = false );
    00069
    00070   declareProperty( "loggedStreams",
    00071                    m_loggedStreamsName,
    00072                    "MessageStream sources we want to dump into a logfile" );
    00073
    00074   for (int ic=0; ic<MSG::NUM_LEVELS; ++ic) {
    00075     m_logColors[ic].declareUpdateHandler(&MessageSvc::setupColors, this);
    00076     m_msgLimit[ic].declareUpdateHandler(&MessageSvc::setupLimits, this);
    00077     m_thresholdProp[ic].declareUpdateHandler(&MessageSvc::setupThreshold, this);
    00078   }
    00079
    00080   levelNames[0] = "NIL";
    00081   levelNames[1] = "VERBOSE";
    00082   levelNames[2] = "DEBUG";
    00083   levelNames[3] = "INFO";
    00084   levelNames[4] = "WARNING";
    00085   levelNames[5] = "ERROR";
    00086   levelNames[6] = "FATAL";
    00087   levelNames[7] = "ALWAYS";
    00088
    00089   for (int i=0; i<MSG::NUM_LEVELS; ++i) {
    00090       m_msgCount[i] = 0;
    00091   }
    00092
    00093 }

MessageSvc::~MessageSvc | ( |  | ) | `[virtual]`

Definition at line 97 of file MessageSvc.cpp.

    00098 {
    00099   // closing log-files, if any
    00100   LoggedStreamsMap_t::iterator iStream   = m_loggedStreams.begin();
    00101   LoggedStreamsMap_t::iterator endStream = m_loggedStreams.end();
    00102   for ( ; iStream != endStream; ++iStream ) {
    00103     delete iStream->second;
    00104     iStream->second = 0;
    00105   }
    00106 }

## Member Function Documentation

StatusCode MessageSvc::reinitialize | ( |  | ) | `[virtual]`

Reinitialize Service.

Reimplemented from Service.

Definition at line 145 of file MessageSvc.cpp.

    00145                                     {
    00146   m_state = Gaudi::StateMachine::OFFLINE;
    00147   return initialize();
    00148 }

StatusCode MessageSvc::initialize | ( |  | ) | `[virtual]`

Initialize Service.

Reimplemented from Service.

Definition at line 111 of file MessageSvc.cpp.

    00111                                   {
    00112   StatusCode sc;
    00113   sc = Service::initialize();
    00114   if( sc.isFailure() ) return sc;
    00115   // Release pointer to myself done in Service base class
    00116   //if( m_msgsvc.isValid() ) {
    00117   //  m_msgsvc = 0;
    00118   //}
    00119   // Set my own properties
    00120   sc = setProperties();
    00121   if (sc.isFailure()) return sc;
    00122
    00123 #ifdef _WIN32
    00124   m_color = false;
    00125 #endif
    00126
    00127   m_colMap["black"]  = MSG::BLACK;
    00128   m_colMap["red"]    = MSG::RED;
    00129   m_colMap["green"]  = MSG::GREEN;
    00130   m_colMap["yellow"] = MSG::YELLOW;
    00131   m_colMap["blue"]   = MSG::BLUE;
    00132   m_colMap["purple"] = MSG::PURPLE;
    00133   m_colMap["cyan"]   = MSG::CYAN;
    00134   m_colMap["white"]  = MSG::WHITE;
    00135
    00136   // make sure the map of logged stream names is initialized
    00137   setupLogStreams();
    00138
    00139   return StatusCode::SUCCESS;
    00140 }

StatusCode MessageSvc::finalize | ( | void |  | ) | `[virtual]`

Finalize Service.

Reimplemented from Service.

Definition at line 313 of file MessageSvc.cpp.

    00313                                 {
    00314
    00315   m_suppress = false;
    00316
    00317   std::ostringstream os;
    00318
    00319   if (m_stats) {
    00320     os << "Summarizing all message counts" << endl;
    00321   } else {
    00322     os << "Listing sources of suppressed message: " << endl;
    00323   }
    00324
    00325   os << "=====================================================" << endl;
    00326   os << " Message Source              |   Level |    Count" << endl;
    00327   os << "-----------------------------+---------+-------------" << endl;
    00328
    00329
    00330   bool found(false);
    00331
    00332   std::map<std::string,MsgAry>::const_iterator itr;
    00333   for (itr=m_sourceMap.begin(); itr!=m_sourceMap.end(); ++itr) {
    00334     for (unsigned int ic = 0; ic < MSG::NUM_LEVELS; ++ic) {
    00335       if ( (itr->second.msg[ic] >= m_msgLimit[ic] && m_msgLimit[ic] != 0 ) ||
    00336            (m_stats && itr->second.msg[ic] > 0 && ic >= m_statLevel.value()) ) {
    00337         os << " ";
    00338         os.width(28);
    00339         os.setf(ios_base::left,ios_base::adjustfield);
    00340         os << itr->first;
    00341
    00342         os << "|";
    00343
    00344         os.width(8);
    00345         os.setf(ios_base::right,ios_base::adjustfield);
    00346         os << levelNames[ic];
    00347
    00348         os << " |";
    00349
    00350         os.width(9);
    00351         os << itr->second.msg[ic];
    00352
    00353         os << endl;
    00354
    00355         found = true;
    00356       }
    00357     }
    00358   }
    00359   os << "=====================================================" << endl;
    00360
    00361   if (found || m_stats) {
    00362     cout << os.str();
    00363   }
    00364
    00365   return StatusCode::SUCCESS;
    00366 }

void MessageSvc::reportMessage | ( | const Message & | message | ) | `[virtual]`

Report a message by sending a Message object to the message service.

Parameters:

  | message | Reference to a message object

Implements IMessageSvc.

Definition at line 464 of file MessageSvc.cpp.

    00464                                                       {
    00465   reportMessage(msg, outputLevel(msg.getSource()));
    00466 }

void MessageSvc::reportMessage | ( | const Message & | msg,
|  | int | outputLevel |
| ) |  |  | `[virtual]`

Report a message by sending a Message object to the message service.

Parameters:

  | message | Reference to a message object
  | outputLevel | Output level of the message source for this message

Implements IMessageSvc.

Definition at line 392 of file MessageSvc.cpp.

    00392                                                                        {
    00393   boost::recursive_mutex::scoped_lock lock(m_reportMutex);
    00394
    00395   int key = msg.getType();
    00396
    00397   m_msgCount[key] ++;
    00398
    00399   const Message *cmsg = &msg;
    00400
    00401   // processing logged streams
    00402   if ( !m_loggedStreams.empty() ) {
    00403     const LoggedStreamsMap_t::iterator iLog = m_loggedStreams.find( msg.getSource() );
    00404     if ( m_loggedStreams.end() != iLog ) {
    00405       (*iLog->second) << *cmsg << std::endl;
    00406     }
    00407   }
    00408
    00409   if ( m_suppress.value() || m_stats.value() ) {
    00410
    00411     // Increase the counter of 'key' type of messages for the source and
    00412     // get the new value.
    00413     const int nmsg = ++(m_sourceMap[msg.getSource()].msg[key]);
    00414
    00415     if (m_suppress.value()) {
    00416
    00417       if ( m_msgLimit[key] != 0 ) {
    00418         if (nmsg == m_msgLimit[key]) {
    00419           char lim[16];
    00420           std::string str = levelNames[key] + " message limit (";
    00421           str += ::_itoa(m_msgLimit[key].value(),lim,10);
    00422           str += ") reached for ";
    00423           str += msg.getSource() + ". Suppressing further output.";
    00424           cmsg = new Message(msg.getSource(),MSG::WARNING,str);
    00425           cmsg->setFormat(msg.getFormat());
    00426         } else if (nmsg > m_msgLimit[key]) {
    00427           return;
    00428         }
    00429       }
    00430     }
    00431
    00432   }
    00433
    00434   StreamMap::const_iterator first = m_streamMap.lower_bound( key );
    00435   if ( first != m_streamMap.end() ) {
    00436     StreamMap::const_iterator last = m_streamMap.upper_bound( key );
    00437     while( first != last ) {
    00438       std::ostream& stream = *( (*first).second.second );
    00439       stream << *cmsg << std::endl;
    00440       first++;
    00441     }
    00442   }
    00443   else if ( key >= outputLevel )   {
    00444     msg.setFormat(m_defaultFormat);
    00445     msg.setTimeFormat(m_defaultTimeFormat);
    00446     if (!m_color) {
    00447       (*m_defaultStream) << *cmsg << std::endl << std::flush;
    00448     } else {
    00449       (*m_defaultStream) <<  m_logColorCodes[key] << *cmsg << "\033[m"
    00450                          << std::endl << std::flush;
    00451     }
    00452   }
    00453
    00454   if (cmsg != &msg) { delete cmsg; }
    00455
    00456 }

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 readable message

Parameters:

  | code | Error code number
  | source | Message source. Typically the alg/svc name

Implements IMessageSvc.

Definition at line 501 of file MessageSvc.cpp.

    00503 {
    00504   boost::recursive_mutex::scoped_lock lock(m_messageMapMutex);
    00505
    00506   MessageMap::const_iterator first = m_messageMap.lower_bound( key );
    00507   if ( first != m_messageMap.end() ) {
    00508     MessageMap::const_iterator last = m_messageMap.upper_bound( key );
    00509     while( first != last ) {
    00510       Message msg = (*first).second;
    00511       msg.setSource( source );
    00512       std::ostringstream os1;
    00513       os1 << "Status Code " << key.getCode() << std::ends;
    00514       Message stat_code1( source, msg.getType(), os1.str() );
    00515       reportMessage( stat_code1 );
    00516       reportMessage( msg );
    00517       first++;
    00518     }
    00519   }
    00520   else {
    00521     Message mesg = m_defaultMessage;
    00522     mesg.setSource( source );
    00523       std::ostringstream os2;
    00524     os2 << "Status Code " << key.getCode() << std::ends;
    00525     Message stat_code2( source,  mesg.getType(), os2.str() );
    00526     reportMessage( stat_code2 );
    00527     reportMessage( mesg );
    00528   }
    00529 }

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.

Parameters:

  | source | Message source. Typically the alg/svc name
  | type | Severity level
  | message | Text message

Implements IMessageSvc.

Definition at line 474 of file MessageSvc.cpp.

    00476                                                      {
    00477   Message msg( source, type, message);
    00478   reportMessage( msg );
    00479 }

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.

Parameters:

  | source | Message source. Typically the alg/svc name
  | type | Severity level
  | message | Text message

Implements IMessageSvc.

Definition at line 487 of file MessageSvc.cpp.

    00489                                                           {
    00490   Message msg( source, type, message);
    00491   reportMessage( msg );
    00492 }

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.

Parameters:

  | code | Status error code
  | message | Message associated

Implements IMessageSvc.

Definition at line 627 of file MessageSvc.cpp.

    00628 {
    00629   boost::recursive_mutex::scoped_lock lock(m_messageMapMutex);
    00630
    00631   typedef MessageMap::value_type value_type;
    00632   m_messageMap.insert( value_type( key, msg ) );
    00633 }

void MessageSvc::eraseMessage | ( |  | ) | `[virtual]`

Erase all messages associated to all status codes.

Implements IMessageSvc.

Definition at line 642 of file MessageSvc.cpp.

    00643 {
    00644   boost::recursive_mutex::scoped_lock lock(m_messageMapMutex);
    00645
    00646   m_messageMap.erase( m_messageMap.begin(), m_messageMap.end() );
    00647 }

void MessageSvc::eraseMessage | ( | const StatusCode & | code | ) | `[virtual]`

Erase message associated to a given status code.

Implements IMessageSvc.

Definition at line 656 of file MessageSvc.cpp.

    00657 {
    00658   boost::recursive_mutex::scoped_lock lock(m_messageMapMutex);
    00659
    00660   m_messageMap.erase( key );
    00661 }

void MessageSvc::eraseMessage | ( | const StatusCode & | code,
|  | const Message & | message |
| ) |  |  | `[virtual]`

Erase a given message associated to a given status code.

Parameters:

  | code | Status error code
  | message | Message associated

Implements IMessageSvc.

Definition at line 670 of file MessageSvc.cpp.

    00671 {
    00672   boost::recursive_mutex::scoped_lock lock(m_messageMapMutex);
    00673
    00674   bool changed = true;
    00675   while( changed ) {
    00676     changed = false;
    00677     MessageMap::iterator first = m_messageMap.lower_bound( key );
    00678     MessageMap::iterator last = m_messageMap.upper_bound( key );
    00679     while( first != last ) {
    00680       const Message& message = (*first).second;
    00681       if ( message == msg ) {
    00682         m_messageMap.erase( first );
    00683         changed = true;
    00684         break;
    00685       }
    00686     }
    00687   }
    00688 }

void MessageSvc::insertStream | ( | int | type,
|  | const std::string & | name,
|  | std::ostream * | stream |
| ) |  |  | `[virtual]`

Add a new stream for a message type (severity level).

Parameters:

  | type | Severity level
  | name | Stream name
  | stream | Pointer to a C++ stream

Implements IMessageSvc.

Definition at line 538 of file MessageSvc.cpp.

    00541 {
    00542   typedef StreamMap::value_type value_type;
    00543   m_streamMap.insert( value_type( key, NamedStream(name,stream) ) );
    00544 }

void MessageSvc::eraseStream | ( |  | ) | `[virtual]`

Delete all the streams.

Implements IMessageSvc.

Definition at line 553 of file MessageSvc.cpp.

    00554 {
    00555   m_streamMap.erase( m_streamMap.begin(), m_streamMap.end() );
    00556 }

void MessageSvc::eraseStream | ( | int | message_type | ) | `[virtual]`

Delete all the streams for a given message type (severity level).

Implements IMessageSvc.

Definition at line 565 of file MessageSvc.cpp.

    00566 {
    00567   m_streamMap.erase( message_type );
    00568 }

void MessageSvc::eraseStream | ( | int | type,
|  | std::ostream * | stream |
| ) |  |  | `[virtual]`

Delete a single stream for a given message type (severity level).

Parameters:

  | type | Severity level
  | stream | Pointer to a C++ stream

Implements IMessageSvc.

Definition at line 577 of file MessageSvc.cpp.

    00577                                                             {
    00578   if ( 0 != stream )    {
    00579     bool changed = true;
    00580     while( changed ) {
    00581       changed = false;
    00582       StreamMap::iterator first = m_streamMap.lower_bound( key );
    00583       StreamMap::iterator last = m_streamMap.upper_bound( key );
    00584       while( first != last ) {
    00585         if ( (*first).second.second == stream ) {
    00586           m_streamMap.erase( first );
    00587           changed = true;
    00588           break;
    00589         }
    00590       }
    00591     }
    00592   }
    00593 }

void MessageSvc::eraseStream | ( | std::ostream * | stream | ) | `[virtual]`

Delete all occurrences of a stream.

Parameters:

  | stream | Pointer to a C++ stream

Implements IMessageSvc.

Definition at line 602 of file MessageSvc.cpp.

    00602                                                     {
    00603   if ( 0 != stream )    {
    00604     bool changed = true;
    00605     while( changed ) {
    00606       changed = false;
    00607       StreamMap::iterator first = m_streamMap.begin();
    00608       while( first != m_streamMap.end() ) {
    00609         if ( (*first).second.second == stream ) {
    00610           m_streamMap.erase( first );
    00611           changed = true;
    00612           break;
    00613         }
    00614       }
    00615     }
    00616   }
    00617 }

virtual std::ostream* MessageSvc::defaultStream | ( |  | ) | const`[inline, virtual]`

Get the default stream.

Implements IMessageSvc.

Definition at line 94 of file MessageSvc.h.

    00094                                             {
    00095     return m_defaultStream;
    00096   }

virtual void MessageSvc::setDefaultStream | ( | std::ostream * | stream | ) | `[inline, virtual]`

Set the default stream.

Parameters:

  | stream | Pointer to a C++ stream

Implements IMessageSvc.

Definition at line 99 of file MessageSvc.h.

    00099                                                       {
    00100     boost::recursive_mutex::scoped_lock lock(m_reportMutex);
    00101     m_defaultStream = stream;
    00102   }

int MessageSvc::outputLevel | ( |  | ) | const`[virtual]`

get the `Service's` output level

Reimplemented from Service.

Definition at line 691 of file MessageSvc.cpp.

    00691                                     {
    00692 // ---------------------------------------------------------------------------
    00693   return m_outputLevel;
    00694 }

int MessageSvc::outputLevel | ( | const std::string & | source | ) | const`[virtual]`

Retrieve the current output level threshold for a given message source.

Parameters:

  | source | Message source. Typically the alg/svc name

Implements IMessageSvc.

Definition at line 697 of file MessageSvc.cpp.

    00697                                                              {
    00698 // ---------------------------------------------------------------------------
    00699   boost::recursive_mutex::scoped_lock lock(m_thresholdMapMutex);
    00700
    00701   ThresholdMap::const_iterator it;
    00702
    00703   it = m_thresholdMap.find( source );
    00704   if( it != m_thresholdMap.end() ) {
    00705     return (*it).second;
    00706   }
    00707   else {
    00708     return m_outputLevel;
    00709   }
    00710 }

void MessageSvc::setOutputLevel | ( | int | new_level | ) | `[virtual]`

Set new global output level threshold.

Implements IMessageSvc.

Definition at line 713 of file MessageSvc.cpp.

    00713                                                 {
    00714 // ---------------------------------------------------------------------------
    00715   m_outputLevel = new_level;
    00716 }

void MessageSvc::setOutputLevel | ( | const std::string & | source,
|  | int | new_level |
| ) |  |  | `[virtual]`

Set new output level threshold for a given message source.

Parameters:

  | source | Message source
  | new_level | Severity level

Implements IMessageSvc.

Definition at line 719 of file MessageSvc.cpp.

    00719                                                                      {
    00720 // ---------------------------------------------------------------------------
    00721   boost::recursive_mutex::scoped_lock lock(m_thresholdMapMutex);
    00722
    00723   /*
    00724   std::pair<ThresholdMap::iterator, bool> p;
    00725   p = m_thresholdMap.insert(ThresholdMap::value_type( source, level) );
    00726   if( p.second == false ) {
    00727     // Already esisting an output level for that source. Erase and enter it again
    00728     m_thresholdMap.erase ( p.first );
    00729     m_thresholdMap.insert(ThresholdMap::value_type( source, level) );
    00730   }
    00731   */
    00732   m_thresholdMap[source] = level;
    00733 }

virtual bool MessageSvc::useColor | ( |  | ) | const`[inline, virtual]`

Show whether colors are used.

Implements IMessageSvc.

Definition at line 117 of file MessageSvc.h.

    00117 { return m_color; }

std::string MessageSvc::getLogColor | ( | int | logLevel | ) | const`[virtual]`

Get the color codes for various log levels.

Parameters:

  | logLevel | Logging level

Implements IMessageSvc.

Definition at line 736 of file MessageSvc.cpp.

    00736                                                       {
    00737 // ---------------------------------------------------------------------------
    00738   if (logLevel < MSG::NUM_LEVELS) {
    00739     return m_logColorCodes[logLevel];
    00740   } else {
    00741     return "";
    00742   }
    00743 }

int MessageSvc::messageCount | ( | MSG::Level | level | ) | const`[virtual]`

Get the number of messages issued at a particular level.

Implements IMessageSvc.

Definition at line 746 of file MessageSvc.cpp.

    00746                                                     {
    00747
    00748   return m_msgCount[level];
    00749
    00750 }

std::string MessageSvc::colTrans | ( | std::string | col,
|  | int | offset |
| ) |  |  | `[private]`

Definition at line 369 of file MessageSvc.cpp.

    00369                                                         {
    00370   ColorMap::const_iterator itr = m_colMap.find(col);
    00371   int icol;
    00372   if (itr != m_colMap.end()) {
    00373     icol = offset + itr->second;
    00374   } else {
    00375     icol = offset + 8;
    00376   }
    00377   std::ostringstream os1;
    00378
    00379   os1 << icol;
    00380
    00381   return os1.str();
    00382
    00383 }

void MessageSvc::initColors | ( | Property & | prop | ) | `[private]`

Definition at line 152 of file MessageSvc.cpp.

    00152                                               {
    00153
    00154   if (m_color == true) {
    00155
    00156     if (m_logColors[MSG::FATAL].value().size() == 0) {
    00157       vector<string> fatDef;
    00158       fatDef.push_back( "[94;101;1m" );
    00159       m_logColors[MSG::FATAL].set( fatDef );
    00160     } else {
    00161       MessageSvc::setupColors( m_logColors[MSG::FATAL] );
    00162     }
    00163
    00164     if (m_logColors[MSG::ERROR].value().size() == 0) {
    00165       vector<string> errDef;
    00166       errDef.push_back( "[97;101;1m" );
    00167       m_logColors[MSG::ERROR].set( errDef );
    00168     } else {
    00169       MessageSvc::setupColors( m_logColors[MSG::ERROR] );
    00170     }
    00171
    00172     if (m_logColors[MSG::WARNING].value().size() == 0) {
    00173       vector<string> warDef;
    00174       warDef.push_back( "[93;1m" );
    00175       m_logColors[MSG::WARNING].set( warDef );
    00176     } else {
    00177       MessageSvc::setupColors( m_logColors[MSG::WARNING] );
    00178     }
    00179
    00180   } else {
    00181
    00182     // reset all color codes;
    00183     for (int ic=0; ic<MSG::NUM_LEVELS; ++ic) {
    00184       vector<string> def;
    00185       m_logColors[ic].set( def );
    00186     }
    00187
    00188   }
    00189
    00190 }

void MessageSvc::setupColors | ( | Property & | prop | ) | `[private]`

Definition at line 194 of file MessageSvc.cpp.

    00194                                            {
    00195
    00196   if (! m_color) return;
    00197
    00198   int ic;
    00199   if (prop.name() == "fatalColorCode") {
    00200     ic = MSG::FATAL;
    00201   } else if (prop.name() == "errorColorCode") {
    00202     ic = MSG::ERROR;
    00203   } else if (prop.name() == "warningColorCode") {
    00204     ic = MSG::WARNING;
    00205   } else if (prop.name() == "infoColorCode") {
    00206     ic = MSG::INFO;
    00207   } else if (prop.name() == "debugColorCode") {
    00208     ic = MSG::DEBUG;
    00209   } else if (prop.name() == "verboseColorCode") {
    00210     ic = MSG::VERBOSE;
    00211   } else if (prop.name() == "alwaysColorCode") {
    00212     ic = MSG::ALWAYS;
    00213   } else {
    00214     cout << "ERROR: Unknown message color parameter: " << prop.name()
    00215          << endl;
    00216     return;
    00217   }
    00218
    00219   string code;
    00220   vector<string>::const_iterator itr;
    00221   itr = m_logColors[ic].value().begin();
    00222
    00223   if ( m_logColors[ic].value().size() == 1 ) {
    00224
    00225     if (*itr == "") {
    00226       code = "";
    00227     } else if (itr->substr(0,1) == "[") {
    00228       code = "\033" + *itr;
    00229     } else {
    00230       code = "\033[" + colTrans(*itr, 90) + ";1m";
    00231     }
    00232
    00233   } else if (m_logColors[ic].value().size() == 2) {
    00234     vector<string>::const_iterator itr2 = itr + 1;
    00235
    00236     code =  "\033[" + colTrans(*itr, 90) + ";"
    00237       + colTrans(*itr2, 100) + ";1m";
    00238
    00239   }
    00240
    00241   m_logColorCodes[ic] = code;
    00242
    00243 }

void MessageSvc::setupLimits | ( | Property & | prop | ) | `[private]`

Definition at line 246 of file MessageSvc.cpp.

    00246                                            {
    00247   // Just report problems in the settings of the limits and unknown limit parameters
    00248   if (prop.name() == "alwaysLimit") {
    00249     IntegerProperty *p = dynamic_cast<IntegerProperty*>(&prop);
    00250     if (p && p->value() != 0) {
    00251       cout << "MessageSvc ERROR: cannot suppress ALWAYS messages" << endl;
    00252       p->setValue(0);
    00253     }
    00254   } else if (prop.name() == "defaultLimit") {
    00255     for (int i = MSG::VERBOSE; i< MSG::NUM_LEVELS; ++i) {
    00256       if (i != MSG::ALWAYS) {
    00257         m_msgLimit[i] = m_msgLimit[MSG::NIL].value();
    00258       }
    00259     }
    00260   } else if (prop.name() != "fatalLimit" &&
    00261              prop.name() != "errorLimit" &&
    00262              prop.name() != "warningLimit" &&
    00263              prop.name() == "infoLimit" &&
    00264              prop.name() == "debugLimit" &&
    00265              prop.name() == "verboseLimit") {
    00266     cout << "MessageSvc ERROR: Unknown message limit parameter: "
    00267          << prop.name() << endl;
    00268     return;
    00269   }
    00270 }

void MessageSvc::setupThreshold | ( | Property & | prop | ) | `[private]`

Definition at line 273 of file MessageSvc.cpp.

    00273                                               {
    00274
    00275   int ic = 0;
    00276   if (prop.name() == "setFatal") {
    00277     ic = MSG::FATAL;
    00278   } else if (prop.name() == "setError") {
    00279     ic = MSG::ERROR;
    00280   } else if (prop.name() == "setWarning") {
    00281     ic = MSG::WARNING;
    00282   } else if (prop.name() == "setInfo") {
    00283     ic = MSG::INFO;
    00284   } else if (prop.name() == "setDebug") {
    00285     ic = MSG::DEBUG;
    00286   } else if (prop.name() == "setVerbose") {
    00287     ic = MSG::VERBOSE;
    00288   } else if (prop.name() == "setAlways") {
    00289     ic = MSG::ALWAYS;
    00290   } else {
    00291     cerr << "MessageSvc ERROR: Unknown message threshold parameter: "
    00292          << prop.name() << endl;
    00293     return;
    00294   }
    00295
    00296   StringArrayProperty *sap = dynamic_cast<StringArrayProperty*>( &prop);
    00297   if (sap == 0) {
    00298     std::cerr << "could not dcast " << prop.name()
    00299               << " to a StringArrayProperty (which it should be!)" << endl;
    00300     return;
    00301   } else {
    00302     std::vector<std::string>::const_iterator itr;
    00303     for ( itr =  sap->value().begin();
    00304           itr != sap->value().end();
    00305           ++itr) {
    00306       setOutputLevel( *itr, ic );
    00307     }
    00308   }
    00309
    00310 }

void MessageSvc::setupLogStreams | ( |  | ) | `[private]`

Definition at line 753 of file MessageSvc.cpp.

    00754 {
    00755   // reset state
    00756   for ( LoggedStreamsMap_t::iterator iLog = m_loggedStreams.begin();
    00757         iLog != m_loggedStreams.end();
    00758         ++iLog ) {
    00759     delete iLog->second;
    00760   }
    00761   m_loggedStreams.clear();
    00762
    00763   typedef std::map<std::string,std::string> StreamMap_t;
    00764   const StreamMap_t& streamMap = m_loggedStreamsName;
    00765   typedef StreamMap_t::const_iterator StreamMapIter;
    00766
    00767   for ( StreamMapIter iProp = streamMap.begin(), iEnd = streamMap.end();
    00768         iProp != iEnd;
    00769         ++iProp ) {
    00770
    00771     const std::string sourceName  = iProp->first;
    00772     const std::string outFileName = iProp->second;
    00773
    00774     std::set<std::string> outFileNames;
    00775     for ( StreamMapIter jProp = streamMap.begin();
    00776           jProp != iEnd;
    00777           ++jProp ) {
    00778       if ( jProp->first != iProp->first ) {
    00779         outFileNames.insert( jProp->second );
    00780       }
    00781     }
    00782
    00783     tee( sourceName, outFileName, outFileNames );
    00784
    00785   }//> loop over property entries
    00786
    00787   return;
    00788 }

void MessageSvc::tee | ( | const std::string & | sourceName,
|  | const std::string & | logFileName,
|  | const std::set< std::string > & | declaredOutFileNames |
| ) |  |  | `[private]`

Definition at line 791 of file MessageSvc.cpp.

    00794 {
    00795   const std::ios_base::openmode openMode = std::ios_base::out |
    00796                                            std::ios_base::trunc;
    00797
    00798   LoggedStreamsMap_t::iterator iEnd    = m_loggedStreams.end();
    00799   LoggedStreamsMap_t::iterator iStream = m_loggedStreams.find( sourceName );
    00800   if ( iStream != iEnd ) {
    00801     delete iStream->second;
    00802     iStream->second = 0;
    00803     m_loggedStreams.erase( iStream );
    00804   }
    00805
    00806   // before creating a new ofstream, make sure there is no already existing
    00807   // one with the same file name...
    00808   iEnd = m_loggedStreams.end();
    00809   for ( iStream = m_loggedStreams.begin(); iStream != iEnd; ++iStream ) {
    00810     if ( outFileNames.find( outFileName ) != outFileNames.end() ) {
    00811       m_loggedStreams[sourceName] = m_loggedStreams[iStream->first];
    00812       return;
    00813     }
    00814   }
    00815
    00816   std::ofstream * out =  new std::ofstream( outFileName.c_str(), openMode );
    00817
    00818   if ( !out->good() ) {
    00819     out->close();
    00820     delete out;
    00821     return;
    00822   }
    00823
    00824   m_loggedStreams[sourceName] = out;
    00825
    00826   return;
    00827 }

## Member Data Documentation

std::ostream* MessageSvc::m_defaultStream`[private]`

Pointer to the output stream.

Definition at line 126 of file MessageSvc.h.

Message MessageSvc::m_defaultMessage`[private]`

Default Message.

Definition at line 127 of file MessageSvc.h.

StreamMap MessageSvc::m_streamMap`[private]`

Stream map.

Definition at line 128 of file MessageSvc.h.

MessageMap MessageSvc::m_messageMap`[private]`

Message map.

Definition at line 129 of file MessageSvc.h.

ThresholdMap MessageSvc::m_thresholdMap`[private]`

Output level threshold map.

Definition at line 130 of file MessageSvc.h.

std::string MessageSvc::m_defaultFormat`[private]`

Default format for the messages.

Definition at line 131 of file MessageSvc.h.

std::string MessageSvc::m_defaultTimeFormat`[private]`

Default format for timestamps in the messages.

Definition at line 132 of file MessageSvc.h.

StringArrayProperty MessageSvc::m_thresholdProp[MSG::NUM_LEVELS]`[private]`

Properties controling.

Definition at line 133 of file MessageSvc.h.

BooleanProperty MessageSvc::m_color`[private]`

Definition at line 134 of file MessageSvc.h.

BooleanProperty MessageSvc::m_stats`[private]`

Definition at line 135 of file MessageSvc.h.

UnsignedIntegerProperty MessageSvc::m_statLevel`[private]`

Definition at line 136 of file MessageSvc.h.

StringArrayProperty MessageSvc::m_logColors[MSG::NUM_LEVELS]`[private]`

Definition at line 137 of file MessageSvc.h.

IntegerProperty MessageSvc::m_msgLimit[MSG::NUM_LEVELS]`[private]`

Definition at line 138 of file MessageSvc.h.

std::string MessageSvc::m_logColorCodes[MSG::NUM_LEVELS]`[private]`

Definition at line 140 of file MessageSvc.h.

std::map<std::string,MsgAry> MessageSvc::m_sourceMap`[private]`

Definition at line 158 of file MessageSvc.h.

BooleanProperty MessageSvc::m_suppress`[private]`

Definition at line 159 of file MessageSvc.h.

ColorMap MessageSvc::m_colMap`[private]`

Definition at line 163 of file MessageSvc.h.

int MessageSvc::m_msgCount[MSG::NUM_LEVELS]`[private]`

Definition at line 165 of file MessageSvc.h.

std::map<std::string, std::string> MessageSvc::m_loggedStreamsName`[private]`

Definition at line 167 of file MessageSvc.h.

LoggedStreamsMap_t MessageSvc::m_loggedStreams`[private]`

Definition at line 169 of file MessageSvc.h.

boost::recursive_mutex MessageSvc::m_reportMutex`[mutable, private]`

Mutex to synchronize multiple threads printing.

Definition at line 182 of file MessageSvc.h.

boost::recursive_mutex MessageSvc::m_messageMapMutex`[mutable, private]`

Mutex to synchronize multiple access to m_messageMap.

Definition at line 185 of file MessageSvc.h.

boost::recursive_mutex MessageSvc::m_thresholdMapMutex`[mutable, private]`

Mutex to synchronize multiple access to m_thresholdMap (.

See also:
  MsgStream::doOutput).

Definition at line 189 of file MessageSvc.h.

The documentation for this class was generated from the following files:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v21r9/GaudiSvc/src/MessageSvc/MessageSvc.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v21r9/GaudiSvc/src/MessageSvc/MessageSvc.cpp