MessageSvc Class Reference

#include <src/MessageSvc/MessageSvc.h>

Inheritance diagram for MessageSvc:
Collaboration diagram for MessageSvc:

Classes

struct  MsgAry
 Private helper class to keep the count of messages of a type (MSG::LEVEL). More...
 

Public Types

typedef std::pair< std::string, std::ostream * > NamedStream
 
typedef std::multimap< int, NamedStreamStreamMap
 
typedef std::multimap< StatusCode, MessageMessageMap
 
typedef std::map< std::string, int > ThresholdMap
 
- Public Types inherited from extends< BASE, Interfaces >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 

Public Member Functions

 MessageSvc (const std::string &name, ISvcLocator *svcloc)
 
 ~MessageSvc () override=default
 
StatusCode reinitialize () override
 Reinitialize Service. More...
 
StatusCode initialize () override
 Initialize Service. More...
 
StatusCode finalize () override
 Finalize Service. More...
 
void reportMessage (const Message &message) override
 
void reportMessage (const Message &msg, int outputLevel) override
 
void reportMessage (const StatusCode &code, const std::string &source="") override
 
void reportMessage (const char *source, int type, const char *message) override
 
void reportMessage (const std::string &source, int type, const std::string &message) override
 
void insertMessage (const StatusCode &code, const Message &message) override
 
void eraseMessage () override
 
void eraseMessage (const StatusCode &code) override
 
void eraseMessage (const StatusCode &code, const Message &message) override
 
void insertStream (int message_type, const std::string &name, std::ostream *stream) override
 
void eraseStream () override
 
void eraseStream (int message_type) override
 
void eraseStream (int message_type, std::ostream *stream) override
 
void eraseStream (std::ostream *stream) override
 
std::ostream * defaultStream () const override
 
void setDefaultStream (std::ostream *stream) override
 
int outputLevel () const override
 
int outputLevel (const std::string &source) const override
 
void setOutputLevel (int new_level) override
 
void setOutputLevel (const std::string &source, int new_level) override
 
bool useColor () const override
 
std::string getLogColor (int logLevel) const override
 
int messageCount (MSG::Level logLevel) const override
 
void incrInactiveCount (MSG::Level level, const std::string &src) override
 
- Public Member Functions inherited from extends< BASE, Interfaces >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Protected Member Functions

virtual void i_reportMessage (const Message &msg, int outputLevel)
 Internal implementation of reportMessage(const Message&,int) without lock. More...
 
virtual void i_reportMessage (const StatusCode &code, const std::string &source)
 Internal implementation of reportMessage(const StatusCode&,const std::string&) without lock. More...
 

Private Types

typedef std::map< std::string, MSG::ColorColorMap
 

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 setupInactCount (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. More...
 
Message m_defaultMessage
 Default Message. More...
 
StreamMap m_streamMap
 Stream map. More...
 
MessageMap m_messageMap
 Message map. More...
 
ThresholdMap m_thresholdMap
 Output level threshold map. More...
 
std::string m_defaultFormat
 Default format for the messages. More...
 
std::string m_defaultTimeFormat
 Default format for timestamps in the messages. More...
 
StringArrayProperty m_thresholdProp [MSG::NUM_LEVELS]
 Properties controlling. More...
 
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, MsgArym_sourceMap
 
std::map< std::string, MsgArym_inactiveMap
 
BooleanProperty m_suppress
 
BooleanProperty m_inactCount
 
ColorMap m_colMap
 
std::array< int, MSG::NUM_LEVELSm_msgCount
 
std::map< std::string, std::string > m_loggedStreamsName
 
std::map< std::string, std::shared_ptr< std::ostream > > m_loggedStreams
 
std::recursive_mutex m_reportMutex
 Mutex to synchronize multiple threads printing. More...
 
std::recursive_mutex m_messageMapMutex
 Mutex to synchronize multiple access to m_messageMap. More...
 
std::recursive_mutex m_thresholdMapMutex
 Mutex to synchronize multiple access to m_thresholdMap (. More...
 

Detailed Description

Definition at line 30 of file MessageSvc.h.

Member Typedef Documentation

typedef std::map<std::string, MSG::Color> MessageSvc::ColorMap
private

Definition at line 164 of file MessageSvc.h.

typedef std::multimap< StatusCode, Message > MessageSvc::MessageMap

Definition at line 34 of file MessageSvc.h.

typedef std::pair< std::string, std::ostream* > MessageSvc::NamedStream

Definition at line 32 of file MessageSvc.h.

typedef std::multimap< int, NamedStream > MessageSvc::StreamMap

Definition at line 33 of file MessageSvc.h.

typedef std::map< std::string, int > MessageSvc::ThresholdMap

Definition at line 35 of file MessageSvc.h.

Constructor & Destructor Documentation

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

Definition at line 57 of file MessageSvc.cpp.

58  : base_class( name, svcloc ) {
59  m_defaultStream = &std::cout;
60  declareProperty( "Format", m_defaultFormat = Message::getDefaultFormat() );
61  declareProperty( "timeFormat", m_defaultTimeFormat = Message::getDefaultTimeFormat() );
62  declareProperty( "showStats", m_stats = false );
63  declareProperty( "statLevel", m_statLevel = 0 );
64 
65  // Special properties to control output level of individual sources
66  declareProperty( "setVerbose", m_thresholdProp[MSG::VERBOSE] );
67  declareProperty( "setDebug", m_thresholdProp[MSG::DEBUG] );
68  declareProperty( "setInfo", m_thresholdProp[MSG::INFO] );
69  declareProperty( "setWarning", m_thresholdProp[MSG::WARNING] );
70  declareProperty( "setError", m_thresholdProp[MSG::ERROR] );
71  declareProperty( "setFatal", m_thresholdProp[MSG::FATAL] );
72  declareProperty( "setAlways", m_thresholdProp[MSG::ALWAYS] );
73 
74  declareProperty( "useColors", m_color=false)->declareUpdateHandler(&MessageSvc::initColors, this);
75 
76  declareProperty( "fatalColorCode", m_logColors[MSG::FATAL] );
77  declareProperty( "errorColorCode", m_logColors[MSG::ERROR] );
78  declareProperty( "warningColorCode", m_logColors[MSG::WARNING] );
79  declareProperty( "infoColorCode", m_logColors[MSG::INFO] );
80  declareProperty( "debugColorCode", m_logColors[MSG::DEBUG] );
81  declareProperty( "verboseColorCode", m_logColors[MSG::VERBOSE] );
82  declareProperty( "alwaysColorCode", m_logColors[MSG::ALWAYS] );
83 
84  const int defaultLimit = 500;
85  declareProperty( "fatalLimit", m_msgLimit[MSG::FATAL] = defaultLimit );
86  declareProperty( "errorLimit", m_msgLimit[MSG::ERROR] = defaultLimit );
87  declareProperty( "warningLimit", m_msgLimit[MSG::WARNING] = defaultLimit );
88  declareProperty( "infoLimit", m_msgLimit[MSG::INFO] = defaultLimit );
89  declareProperty( "debugLimit", m_msgLimit[MSG::DEBUG] = defaultLimit );
90  declareProperty( "verboseLimit", m_msgLimit[MSG::VERBOSE] = defaultLimit );
91  declareProperty( "alwaysLimit", m_msgLimit[MSG::ALWAYS] = 0 );
92 
93  declareProperty( "defaultLimit", m_msgLimit[MSG::NIL] = defaultLimit );
94 
95  declareProperty( "enableSuppression", m_suppress = false );
96  declareProperty( "countInactive", m_inactCount = false )->declareUpdateHandler( &MessageSvc::setupInactCount, this );
97 #ifndef NDEBUG
98  // initialize the MsgStream static flag.
100 #endif
101 
102  declareProperty( "loggedStreams",
104  "MessageStream sources we want to dump into a logfile" );
105 
106  for (int ic=0; ic<MSG::NUM_LEVELS; ++ic) {
110  }
111 
113 }
IntegerProperty m_msgLimit[MSG::NUM_LEVELS]
Definition: MessageSvc.h:148
GAUDI_API void fill(AIDA::IHistogram1D *histo, const double value, const double weight=1.0)
simple function to fill AIDA::IHistogram1D objects
Definition: Fill.cpp:36
std::ostream * m_defaultStream
Pointer to the output stream.
Definition: MessageSvc.h:136
std::array< int, MSG::NUM_LEVELS > m_msgCount
Definition: MessageSvc.h:167
virtual Property & declareUpdateHandler(std::function< void(Property &)> fun)
set new callback for update
Definition: Property.cpp:72
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
void setupLimits(Property &prop)
Definition: MessageSvc.cpp:241
void setupInactCount(Property &prop)
Definition: MessageSvc.cpp:305
extends base_class
Typedef to this class.
Definition: extends.h:14
UnsignedIntegerProperty m_statLevel
Definition: MessageSvc.h:146
static const std::string getDefaultTimeFormat()
Get the default time format string.
Definition: Message.cpp:226
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
static const std::string getDefaultFormat()
Get the default format string.
Definition: Message.cpp:187
StringArrayProperty m_thresholdProp[MSG::NUM_LEVELS]
Properties controlling.
Definition: MessageSvc.h:143
std::string m_defaultFormat
Default format for the messages.
Definition: MessageSvc.h:141
void setupColors(Property &prop)
Definition: MessageSvc.cpp:191
void initColors(Property &prop)
Definition: MessageSvc.cpp:161
BooleanProperty m_color
Definition: MessageSvc.h:144
BooleanProperty m_inactCount
Definition: MessageSvc.h:161
BooleanProperty m_stats
Definition: MessageSvc.h:145
std::map< std::string, std::string > m_loggedStreamsName
Definition: MessageSvc.h:169
BooleanProperty m_suppress
Definition: MessageSvc.h:161
void setupThreshold(Property &prop)
Definition: MessageSvc.cpp:268
static GAUDI_API bool enableCountInactive(bool value=true)
Enable/disable the count of inactive messages.
Definition: MsgStream.cpp:32
std::string m_defaultTimeFormat
Default format for timestamps in the messages.
Definition: MessageSvc.h:142
StringArrayProperty m_logColors[MSG::NUM_LEVELS]
Definition: MessageSvc.h:147
MessageSvc::~MessageSvc ( )
overridedefault

Member Function Documentation

std::string MessageSvc::colTrans ( std::string  col,
int  offset 
)
private

Definition at line 430 of file MessageSvc.cpp.

430  {
431  auto itr = m_colMap.find(col);
432  int icol = offset + ( (itr != m_colMap.end()) ? itr->second : 8 );
433  return std::to_string( icol );
434 }
string to_string(const T &value)
Definition: mergesort.cpp:40
ColorMap m_colMap
Definition: MessageSvc.h:165
std::ostream* MessageSvc::defaultStream ( ) const
inlineoverride

Definition at line 92 of file MessageSvc.h.

92  {
93  return m_defaultStream;
94  }
std::ostream * m_defaultStream
Pointer to the output stream.
Definition: MessageSvc.h:136
void MessageSvc::eraseMessage ( )
override

Definition at line 654 of file MessageSvc.cpp.

655 {
656  std::unique_lock<std::recursive_mutex> lock(m_messageMapMutex);
657  m_messageMap.clear();
658 }
MessageMap m_messageMap
Message map.
Definition: MessageSvc.h:139
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
Definition: MessageSvc.h:187
def lock(file)
Definition: locker.py:16
void MessageSvc::eraseMessage ( const StatusCode code)
override

Definition at line 667 of file MessageSvc.cpp.

668 {
669  std::unique_lock<std::recursive_mutex> lock(m_messageMapMutex);
670  m_messageMap.erase( key );
671 }
MessageMap m_messageMap
Message map.
Definition: MessageSvc.h:139
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
Definition: MessageSvc.h:187
def lock(file)
Definition: locker.py:16
void MessageSvc::eraseMessage ( const StatusCode code,
const Message message 
)
override

Definition at line 680 of file MessageSvc.cpp.

681 {
682  std::unique_lock<std::recursive_mutex> lock(m_messageMapMutex);
683 
684  erase_if( m_messageMap, m_messageMap.equal_range(key),
685  [&](MessageMap::const_reference j) { return j.second==msg; } ) ;
686 }
MessageMap m_messageMap
Message map.
Definition: MessageSvc.h:139
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
Definition: MessageSvc.h:187
def lock(file)
Definition: locker.py:16
void MessageSvc::eraseStream ( )
override

Definition at line 588 of file MessageSvc.cpp.

589 {
590  m_streamMap.clear();
591 }
StreamMap m_streamMap
Stream map.
Definition: MessageSvc.h:138
void MessageSvc::eraseStream ( int  message_type)
override

Definition at line 600 of file MessageSvc.cpp.

601 {
602  m_streamMap.erase( message_type );
603 }
StreamMap m_streamMap
Stream map.
Definition: MessageSvc.h:138
void MessageSvc::eraseStream ( int  message_type,
std::ostream *  stream 
)
override

Definition at line 612 of file MessageSvc.cpp.

612  {
613  if ( stream ) {
614  erase_if( m_streamMap, m_streamMap.equal_range(key),
615  [&](StreamMap::const_reference j)
616  { return j.second.second == stream; } );
617  }
618 }
StreamMap m_streamMap
Stream map.
Definition: MessageSvc.h:138
void MessageSvc::eraseStream ( std::ostream *  stream)
override

Definition at line 627 of file MessageSvc.cpp.

627  {
628  if ( stream ) {
629  erase_if( m_streamMap, [&](StreamMap::const_reference j)
630  { return j.second.second == stream; } );
631  }
632 }
StreamMap m_streamMap
Stream map.
Definition: MessageSvc.h:138
StatusCode MessageSvc::finalize ( )
override

Finalize Service.

Definition at line 317 of file MessageSvc.cpp.

317  {
318 
319  m_suppress = false;
320 
321  {
322  std::ostringstream os;
323 
324  if (m_stats) {
325  os << "Summarizing all message counts" << std::endl;
326  } else {
327  os << "Listing sources of suppressed message: " << std::endl;
328  }
329 
330  os << "=====================================================" << std::endl;
331  os << " Message Source | Level | Count" << std::endl;
332  os << "-----------------------------+---------+-------------" << std::endl;
333 
334 
335  bool found(false);
336 
337  for (auto itr=m_sourceMap.begin(); itr!=m_sourceMap.end(); ++itr) {
338  for (unsigned int ic = 0; ic < MSG::NUM_LEVELS; ++ic) {
339  if ( (itr->second.msg[ic] >= m_msgLimit[ic] && m_msgLimit[ic] != 0 ) ||
340  (m_stats && itr->second.msg[ic] > 0 && ic >= m_statLevel.value()) ) {
341  os << " ";
342  os.width(28);
343  os.setf(std::ios_base::left,std::ios_base::adjustfield);
344  os << itr->first;
345  os << "|";
346 
347  os.width(8);
348  os.setf(std::ios_base::right,std::ios_base::adjustfield);
349  os << levelNames[ic];
350  os << " |";
351 
352  os.width(9);
353  os << itr->second.msg[ic];
354  os << std::endl;
355 
356  found = true;
357  }
358  }
359  }
360  os << "=====================================================" << std::endl;
361  if (found || m_stats) std::cout << os.str();
362  }
363 
364 #ifndef NDEBUG
365  if (m_inactCount.value()) {
366 
367  std::ostringstream os;
368  os << "Listing sources of Unprotected and Unseen messages\n";
369 
370  bool found(false);
371 
372  unsigned int ml(0);
373  for (const auto& itr : m_inactiveMap) {
374  for (unsigned int ic = 0; ic < MSG::NUM_LEVELS; ++ic) {
375  if (itr.second.msg[ic] != 0 && itr.first.length() > ml) {
376  ml = itr.first.length();
377  }
378  }
379  }
380 
381  for (unsigned int i=0; i<ml+25; ++i) os << "=";
382 
383  os << std::endl << " ";
384  os.width(ml+2);
385  os.setf(std::ios_base::left,std::ios_base::adjustfield);
386  os << "Message Source";
387  os.width(1);
388  os << "| Level | Count" << std::endl;
389 
390  for (unsigned int i=0; i<ml+3; ++i) os << "-";
391  os << "+---------+-----------" << std::endl;
392 
393 
394  for (auto itr=m_inactiveMap.begin(); itr!=m_inactiveMap.end(); ++itr) {
395  for (unsigned int ic = 0; ic < MSG::NUM_LEVELS; ++ic) {
396  if (itr->second.msg[ic] != 0) {
397  os << " ";
398  os.width(ml+2);
399  os.setf(std::ios_base::left,std::ios_base::adjustfield);
400  os << itr->first;
401 
402  os << "|";
403 
404  os.width(8);
405  os.setf(std::ios_base::right,std::ios_base::adjustfield);
406  os << levelNames[ic];
407 
408  os << " |";
409 
410  os.width(9);
411  os << itr->second.msg[ic];
412 
413  os << std::endl;
414 
415  found = true;
416  }
417  }
418  }
419  for (unsigned int i=0; i<ml+25; ++i) os << "=";
420  os << std::endl;
421 
422  if (found) std::cout << os.str();
423  }
424 #endif
425 
426  return StatusCode::SUCCESS;
427 }
IntegerProperty m_msgLimit[MSG::NUM_LEVELS]
Definition: MessageSvc.h:148
UnsignedIntegerProperty m_statLevel
Definition: MessageSvc.h:146
std::map< std::string, MsgAry > m_sourceMap
Definition: MessageSvc.h:160
const TYPE & value() const
explicit conversion
Definition: Property.h:341
std::map< std::string, MsgAry > m_inactiveMap
Definition: MessageSvc.h:160
BooleanProperty m_inactCount
Definition: MessageSvc.h:161
BooleanProperty m_stats
Definition: MessageSvc.h:145
list i
Definition: ana.py:128
BooleanProperty m_suppress
Definition: MessageSvc.h:161
std::string MessageSvc::getLogColor ( int  logLevel) const
override

Definition at line 717 of file MessageSvc.cpp.

717  {
718 // ---------------------------------------------------------------------------
719  return (logLevel < MSG::NUM_LEVELS) ? m_logColorCodes[logLevel] : "" ;
720 }
std::string m_logColorCodes[MSG::NUM_LEVELS]
Definition: MessageSvc.h:150
void MessageSvc::i_reportMessage ( const Message msg,
int  outputLevel 
)
protectedvirtual

Internal implementation of reportMessage(const Message&,int) without lock.

Definition at line 447 of file MessageSvc.cpp.

447  {
448  int key = msg.getType();
449 
450  ++m_msgCount[key];
451 
452  const Message *cmsg = &msg;
453 
454  // processing logged streams
455  if ( !m_loggedStreams.empty() ) {
456  auto iLog = m_loggedStreams.find( msg.getSource() );
457  if ( m_loggedStreams.end() != iLog ) {
458  (*iLog->second) << *cmsg << std::endl;
459  }
460  }
461 
462  if ( m_suppress.value() || m_stats.value() ) {
463 
464  // Increase the counter of 'key' type of messages for the source and
465  // get the new value.
466  const int nmsg = ++(m_sourceMap[msg.getSource()].msg[key]);
467 
468  if (m_suppress.value() && m_msgLimit[key] != 0 ) {
469  if (nmsg > m_msgLimit[key]) return;
470  if (nmsg == m_msgLimit[key]) {
471  std::string txt = levelNames[key] + " message limit ("
472  + std::to_string( m_msgLimit[key].value() )
473  + ") reached for " + msg.getSource() + ". Suppressing further output.";
474  cmsg = new Message(msg.getSource(), MSG::WARNING, std::move(txt));
475  cmsg->setFormat(msg.getFormat());
476  }
477  }
478  }
479 
480  auto range = m_streamMap.equal_range( key );
481  if ( range.first != m_streamMap.end() ) {
482  std::for_each( range.first,range.second, [&](StreamMap::const_reference sm) {
483  *sm.second.second << *cmsg << std::endl;
484  });
485  } else if ( key >= outputLevel ) {
488  if (!m_color) {
489  (*m_defaultStream) << *cmsg << std::endl << std::flush;
490  } else {
491  (*m_defaultStream) << m_logColorCodes[key] << *cmsg << "\033[m"
492  << std::endl << std::flush;
493  }
494  }
495 
496  if (cmsg != &msg) { delete cmsg; }
497 
498 }
IntegerProperty m_msgLimit[MSG::NUM_LEVELS]
Definition: MessageSvc.h:148
const std::string & getFormat() const
Get the format string.
Definition: Message.cpp:176
string to_string(const T &value)
Definition: mergesort.cpp:40
StreamMap m_streamMap
Stream map.
Definition: MessageSvc.h:138
std::array< int, MSG::NUM_LEVELS > m_msgCount
Definition: MessageSvc.h:167
int getType() const
Get the message type.
Definition: Message.cpp:93
std::map< std::string, std::shared_ptr< std::ostream > > m_loggedStreams
Definition: MessageSvc.h:170
std::map< std::string, MsgAry > m_sourceMap
Definition: MessageSvc.h:160
NamedRange_< CONTAINER > range(const CONTAINER &cnt, std::string name)
simple function to create the named range form arbitrary container
Definition: NamedRange.h:130
const TYPE & value() const
explicit conversion
Definition: Property.h:341
void setFormat(std::string msg) const
Set the format string.
Definition: Message.cpp:200
The Message class.
Definition: Message.h:14
std::string m_defaultFormat
Default format for the messages.
Definition: MessageSvc.h:141
void setTimeFormat(std::string timeFormat) const
Set the time format string.
Definition: Message.cpp:239
std::string m_logColorCodes[MSG::NUM_LEVELS]
Definition: MessageSvc.h:150
const std::string & getSource() const
Get the message source.
Definition: Message.cpp:115
BooleanProperty m_color
Definition: MessageSvc.h:144
int outputLevel() const override
Definition: MessageSvc.cpp:689
BooleanProperty m_stats
Definition: MessageSvc.h:145
BooleanProperty m_suppress
Definition: MessageSvc.h:161
std::string m_defaultTimeFormat
Default format for timestamps in the messages.
Definition: MessageSvc.h:142
void MessageSvc::i_reportMessage ( const StatusCode code,
const std::string &  source 
)
protectedvirtual

Internal implementation of reportMessage(const StatusCode&,const std::string&) without lock.

Definition at line 547 of file MessageSvc.cpp.

549 {
550  int level = outputLevel(source);
551  auto report = [&](Message mesg) {
552  mesg.setSource( source );
553  Message stat_code( source, mesg.getType(), "Status Code " + std::to_string( code.getCode() ) );
554  i_reportMessage( std::move(stat_code), level );
555  i_reportMessage( std::move(mesg), level );
556  };
557 
558  auto range = m_messageMap.equal_range( code );
559  if ( range.first != m_messageMap.end() ) {
560  std::for_each( range.first, range.second,
561  [&](MessageMap::const_reference sm) { report(sm.second); } );
562  } else {
563  report(m_defaultMessage);
564  }
565 }
string to_string(const T &value)
Definition: mergesort.cpp:40
unsigned long getCode() const
Get the status code by value.
Definition: StatusCode.h:93
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition: MessageSvc.cpp:447
Message m_defaultMessage
Default Message.
Definition: MessageSvc.h:137
MessageMap m_messageMap
Message map.
Definition: MessageSvc.h:139
NamedRange_< CONTAINER > range(const CONTAINER &cnt, std::string name)
simple function to create the named range form arbitrary container
Definition: NamedRange.h:130
The Message class.
Definition: Message.h:14
int outputLevel() const override
Definition: MessageSvc.cpp:689
void MessageSvc::incrInactiveCount ( MSG::Level  level,
const std::string &  src 
)
override

Definition at line 731 of file MessageSvc.cpp.

731  {
732 
733  ++(m_inactiveMap[source].msg[level]);
734 
735 }
std::map< std::string, MsgAry > m_inactiveMap
Definition: MessageSvc.h:160
void MessageSvc::initColors ( Property prop)
private

Definition at line 161 of file MessageSvc.cpp.

161  {
162 
163  if (m_color) {
164  static const std::array<std::pair<MSG::Level,std::vector<std::string>>,3> tbl{
165  { { MSG::FATAL, { { "[94;101;1m" } } },
166  { MSG::ERROR, { { "[97;101;1m" } } },
167  { MSG::WARNING, { { "[93;1m" } } } } };
168 
169  for (const auto& p : tbl ) {
170  auto &lC = m_logColors[p.first];
171  if (lC.value().empty()) {
172  lC.set(p.second);
173  } else {
175  }
176  }
177 
178  } else {
179 
180  // reset all color codes;
181  for (int ic=0; ic<MSG::NUM_LEVELS; ++ic) {
182  m_logColors[ic].set( { } );
183  }
184 
185  }
186 
187 }
bool set(const TYPE &value)
update the value of the property/check the verifier
Definition: Property.h:434
void setupColors(Property &prop)
Definition: MessageSvc.cpp:191
BooleanProperty m_color
Definition: MessageSvc.h:144
StringArrayProperty m_logColors[MSG::NUM_LEVELS]
Definition: MessageSvc.h:147
StatusCode MessageSvc::initialize ( )
override

Initialize Service.

Definition at line 119 of file MessageSvc.cpp.

119  {
120  StatusCode sc;
121  sc = Service::initialize();
122  if( sc.isFailure() ) return sc;
123  // Set my own properties
124  sc = setProperties();
125  if (sc.isFailure()) return sc;
126 
127 #ifdef _WIN32
128  m_color = false;
129 #endif
130 
131  //NOTE: m_colMap is used _before_ it is filled here,
132  // i.e. while it is still empty.
133  // Moving this initialization 'up' by eg. just
134  // having a 'static const' colMap does not leave
135  // the results invariant...
136  m_colMap["black"] = MSG::BLACK;
137  m_colMap["red"] = MSG::RED;
138  m_colMap["green"] = MSG::GREEN;
139  m_colMap["yellow"] = MSG::YELLOW;
140  m_colMap["blue"] = MSG::BLUE;
141  m_colMap["purple"] = MSG::PURPLE;
142  m_colMap["cyan"] = MSG::CYAN;
143  m_colMap["white"] = MSG::WHITE;
144 
145  // make sure the map of logged stream names is initialized
146  setupLogStreams();
147 
148  return StatusCode::SUCCESS;
149 }
StatusCode initialize() override
Definition: Service.cpp:63
ColorMap m_colMap
Definition: MessageSvc.h:165
void setupLogStreams()
Definition: MessageSvc.cpp:738
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
BooleanProperty m_color
Definition: MessageSvc.h:144
void MessageSvc::insertMessage ( const StatusCode code,
const Message message 
)
override

Definition at line 641 of file MessageSvc.cpp.

642 {
643  std::unique_lock<std::recursive_mutex> lock(m_messageMapMutex);
644  m_messageMap.emplace( key, msg );
645 }
MessageMap m_messageMap
Message map.
Definition: MessageSvc.h:139
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
Definition: MessageSvc.h:187
def lock(file)
Definition: locker.py:16
void MessageSvc::insertStream ( int  message_type,
const std::string &  name,
std::ostream *  stream 
)
override

Definition at line 574 of file MessageSvc.cpp.

577 {
578  m_streamMap.emplace( key, NamedStream(name,stream) );
579 }
StreamMap m_streamMap
Stream map.
Definition: MessageSvc.h:138
std::pair< std::string, std::ostream * > NamedStream
Definition: MessageSvc.h:32
int MessageSvc::messageCount ( MSG::Level  logLevel) const
override

Definition at line 723 of file MessageSvc.cpp.

723  {
724 
725  return m_msgCount[level];
726 
727 }
std::array< int, MSG::NUM_LEVELS > m_msgCount
Definition: MessageSvc.h:167
int MessageSvc::outputLevel ( ) const
override

Definition at line 689 of file MessageSvc.cpp.

689  {
690 // ---------------------------------------------------------------------------
691  return m_outputLevel;
692 }
int MessageSvc::outputLevel ( const std::string &  source) const
override

Definition at line 695 of file MessageSvc.cpp.

695  {
696 // ---------------------------------------------------------------------------
697  std::unique_lock<std::recursive_mutex> lock(m_thresholdMapMutex);
698  auto it = m_thresholdMap.find( source );
699  return ( it != m_thresholdMap.end() ) ? it->second : m_outputLevel.value();
700 }
ThresholdMap m_thresholdMap
Output level threshold map.
Definition: MessageSvc.h:140
def lock(file)
Definition: locker.py:16
std::recursive_mutex m_thresholdMapMutex
Mutex to synchronize multiple access to m_thresholdMap (.
Definition: MessageSvc.h:191
StatusCode MessageSvc::reinitialize ( )
override

Reinitialize Service.

Definition at line 154 of file MessageSvc.cpp.

154  {
156  return initialize();
157 }
StatusCode initialize() override
Initialize Service.
Definition: MessageSvc.cpp:119
void MessageSvc::reportMessage ( const Message message)
override

Definition at line 506 of file MessageSvc.cpp.

506  {
507  reportMessage(msg, outputLevel(msg.getSource()));
508 }
void reportMessage(const Message &message) override
Definition: MessageSvc.cpp:506
int outputLevel() const override
Definition: MessageSvc.cpp:689
void MessageSvc::reportMessage ( const Message msg,
int  outputLevel 
)
override

Definition at line 442 of file MessageSvc.cpp.

442  {
443  std::unique_lock<std::recursive_mutex> lock(m_reportMutex);
445 }
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition: MessageSvc.cpp:447
def lock(file)
Definition: locker.py:16
std::recursive_mutex m_reportMutex
Mutex to synchronize multiple threads printing.
Definition: MessageSvc.h:184
int outputLevel() const override
Definition: MessageSvc.cpp:689
void MessageSvc::reportMessage ( const StatusCode code,
const std::string &  source = "" 
)
override

Definition at line 540 of file MessageSvc.cpp.

542 {
543  std::unique_lock<std::recursive_mutex> lock(m_messageMapMutex);
544  i_reportMessage(code, source);
545 }
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition: MessageSvc.cpp:447
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
Definition: MessageSvc.h:187
def lock(file)
Definition: locker.py:16
void MessageSvc::reportMessage ( const char *  source,
int  type,
const char *  message 
)
override

Definition at line 516 of file MessageSvc.cpp.

518  {
519  reportMessage( Message{ source, type, message } );
520 }
void reportMessage(const Message &message) override
Definition: MessageSvc.cpp:506
The Message class.
Definition: Message.h:14
string type
Definition: gaudirun.py:151
void MessageSvc::reportMessage ( const std::string &  source,
int  type,
const std::string &  message 
)
override

Definition at line 528 of file MessageSvc.cpp.

530  {
531  reportMessage( Message{source, type, message} );
532 }
void reportMessage(const Message &message) override
Definition: MessageSvc.cpp:506
The Message class.
Definition: Message.h:14
string type
Definition: gaudirun.py:151
void MessageSvc::setDefaultStream ( std::ostream *  stream)
inlineoverride

Definition at line 97 of file MessageSvc.h.

97  {
98  std::unique_lock<std::recursive_mutex> lock(m_reportMutex);
99  m_defaultStream = stream;
100  }
std::ostream * m_defaultStream
Pointer to the output stream.
Definition: MessageSvc.h:136
def lock(file)
Definition: locker.py:16
std::recursive_mutex m_reportMutex
Mutex to synchronize multiple threads printing.
Definition: MessageSvc.h:184
void MessageSvc::setOutputLevel ( int  new_level)
override

Definition at line 703 of file MessageSvc.cpp.

703  {
704 // ---------------------------------------------------------------------------
705  m_outputLevel = new_level;
706 }
void MessageSvc::setOutputLevel ( const std::string &  source,
int  new_level 
)
override

Definition at line 709 of file MessageSvc.cpp.

709  {
710 // ---------------------------------------------------------------------------
711  std::unique_lock<std::recursive_mutex> lock(m_thresholdMapMutex);
712 
713  m_thresholdMap[source] = level;
714 }
ThresholdMap m_thresholdMap
Output level threshold map.
Definition: MessageSvc.h:140
def lock(file)
Definition: locker.py:16
std::recursive_mutex m_thresholdMapMutex
Mutex to synchronize multiple access to m_thresholdMap (.
Definition: MessageSvc.h:191
void MessageSvc::setupColors ( Property prop)
private

Definition at line 191 of file MessageSvc.cpp.

191  {
192 
193  if (! m_color) return;
194 
195  static const std::array<std::pair<const char*,MSG::Level>,7> tbl {
196  { {"fatalColorCode", MSG::FATAL },
197  {"errorColorCode", MSG::ERROR },
198  {"warningColorCode", MSG::WARNING },
199  {"infoColorCode", MSG::INFO },
200  {"debugColorCode", MSG::DEBUG },
201  {"verboseColorCode", MSG::VERBOSE },
202  {"alwaysColorCode", MSG::ALWAYS } } };
203 
204  auto i = std::find_if( std::begin(tbl),std::end(tbl),
205  [&](const std::pair<const char*,MSG::Level>& t) {
206  return prop.name() == t.first;
207  } );
208  if (i==std::end(tbl)) {
209  std::cout << "ERROR: Unknown message color parameter: " << prop.name()
210  << std::endl;
211  return;
212  }
213  int ic = i->second;
214 
215  std::string code;
216  auto itr = m_logColors[ic].value().begin();
217 
218  if ( m_logColors[ic].value().size() == 1 ) {
219 
220  if (itr->empty()) {
221  code = "";
222  } else if (itr->compare(0,1,"[") == 0) {
223  code = "\033" + *itr;
224  } else {
225  code = "\033[" + colTrans(*itr, 90) + ";1m";
226  }
227 
228  } else if (m_logColors[ic].value().size() == 2) {
229  auto itr2 = itr + 1;
230 
231  code = "\033[" + colTrans(*itr, 90) + ";"
232  + colTrans(*itr2, 100) + ";1m";
233 
234  }
235 
236  m_logColorCodes[ic] = code;
237 
238 }
std::string colTrans(std::string, int)
Definition: MessageSvc.cpp:430
const std::string & name() const
property name
Definition: Property.h:45
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
const TYPE & value() const
explicit conversion
Definition: Property.h:341
std::string m_logColorCodes[MSG::NUM_LEVELS]
Definition: MessageSvc.h:150
BooleanProperty m_color
Definition: MessageSvc.h:144
list i
Definition: ana.py:128
StringArrayProperty m_logColors[MSG::NUM_LEVELS]
Definition: MessageSvc.h:147
void MessageSvc::setupInactCount ( Property prop)
private

Definition at line 305 of file MessageSvc.cpp.

305  {
306  if (prop.name() == "countInactive") {
307  BooleanProperty *p = dynamic_cast<BooleanProperty*>(&prop);
308  if (p)
310  }
311 }
const std::string & name() const
property name
Definition: Property.h:45
const TYPE & value() const
explicit conversion
Definition: Property.h:341
static GAUDI_API bool enableCountInactive(bool value=true)
Enable/disable the count of inactive messages.
Definition: MsgStream.cpp:32
void MessageSvc::setupLimits ( Property prop)
private

Definition at line 241 of file MessageSvc.cpp.

241  {
242  // Just report problems in the settings of the limits and unknown limit parameters
243  if (prop.name() == "alwaysLimit") {
244  IntegerProperty *p = dynamic_cast<IntegerProperty*>(&prop);
245  if (p && p->value() != 0) {
246  std::cout << "MessageSvc ERROR: cannot suppress ALWAYS messages" << std::endl;
247  p->setValue(0);
248  }
249  } else if (prop.name() == "defaultLimit") {
250  for (int i = MSG::VERBOSE; i< MSG::NUM_LEVELS; ++i) {
251  if (i != MSG::ALWAYS) {
253  }
254  }
255  } else if (prop.name() != "fatalLimit" &&
256  prop.name() != "errorLimit" &&
257  prop.name() != "warningLimit" &&
258  prop.name() == "infoLimit" &&
259  prop.name() == "debugLimit" &&
260  prop.name() == "verboseLimit") {
261  std::cout << "MessageSvc ERROR: Unknown message limit parameter: "
262  << prop.name() << std::endl;
263  return;
264  }
265 }
IntegerProperty m_msgLimit[MSG::NUM_LEVELS]
Definition: MessageSvc.h:148
const std::string & name() const
property name
Definition: Property.h:45
bool setValue(const TYPE &value) override
implementation of PropertyWithValue::setValue
Definition: Property.h:406
const TYPE & value() const
explicit conversion
Definition: Property.h:341
list i
Definition: ana.py:128
void MessageSvc::setupLogStreams ( )
private

Definition at line 738 of file MessageSvc.cpp.

739 {
740  // reset state
741  m_loggedStreams.clear();
742 
743  for ( auto& iProp : m_loggedStreamsName ) {
744 
745  std::set<std::string> outFileNames;
746  for ( auto& jProp : m_loggedStreamsName ) {
747  if ( jProp.first != iProp.first ) {
748  outFileNames.insert( jProp.second );
749  }
750  }
751  tee( iProp.first, iProp.second, outFileNames );
752 
753  }//> loop over property entries
754 }
std::map< std::string, std::shared_ptr< std::ostream > > m_loggedStreams
Definition: MessageSvc.h:170
void tee(const std::string &sourceName, const std::string &logFileName, const std::set< std::string > &declaredOutFileNames)
Definition: MessageSvc.cpp:757
std::map< std::string, std::string > m_loggedStreamsName
Definition: MessageSvc.h:169
void MessageSvc::setupThreshold ( Property prop)
private

Definition at line 268 of file MessageSvc.cpp.

268  {
269 
270  static const std::array<std::pair<const char*,MSG::Level>,7> tbl{
271  { { "setFatal", MSG::FATAL },
272  { "setError", MSG::ERROR },
273  { "setWarning", MSG::WARNING },
274  { "setInfo", MSG::INFO },
275  { "setDebug", MSG::DEBUG },
276  { "setVerbose", MSG::VERBOSE },
277  { "setAlways", MSG::ALWAYS } } };
278 
279  auto i = std::find_if( std::begin(tbl),std::end(tbl),
280  [&](const std::pair<const char*,MSG::Level>& t) {
281  return prop.name() == t.first;
282  } );
283  if (i==std::end(tbl)) {
284  std::cerr << "MessageSvc ERROR: Unknown message threshold parameter: "
285  << prop.name() << std::endl;
286  return;
287  }
288  int ic = i->second;
289 
290  StringArrayProperty *sap = dynamic_cast<StringArrayProperty*>( &prop);
291  if (!sap) {
292  std::cerr << "could not dcast " << prop.name()
293  << " to a StringArrayProperty (which it should be!)" << std::endl;
294  } else {
295  for ( auto& i : sap->value() ) setOutputLevel( i, ic );
296  }
297 
298 }
const std::string & name() const
property name
Definition: Property.h:45
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
void setOutputLevel(int new_level) override
Definition: MessageSvc.cpp:703
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
const TYPE & value() const
explicit conversion
Definition: Property.h:341
list i
Definition: ana.py:128
void MessageSvc::tee ( const std::string &  sourceName,
const std::string &  logFileName,
const std::set< std::string > &  declaredOutFileNames 
)
private

Definition at line 757 of file MessageSvc.cpp.

760 {
761  const std::ios_base::openmode openMode = std::ios_base::out |
762  std::ios_base::trunc;
763 
764  auto iStream = m_loggedStreams.find( sourceName );
765  if ( iStream != std::end(m_loggedStreams) ) {
766  m_loggedStreams.erase( iStream );
767  }
768 
769  // before creating a new ofstream, make sure there is no already existing
770  // one with the same file name...
771  for (auto& iStream : m_loggedStreams ) {
772  if ( outFileNames.find( outFileName ) != outFileNames.end() ) {
773  m_loggedStreams[sourceName] = m_loggedStreams[iStream.first];
774  return;
775  }
776  }
777 
778  auto out = std::make_shared<std::ofstream>( outFileName, openMode );
779  if ( out->good() ) m_loggedStreams[sourceName] = std::move(out);
780 
781 }
std::map< std::string, std::shared_ptr< std::ostream > > m_loggedStreams
Definition: MessageSvc.h:170
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
bool MessageSvc::useColor ( ) const
inlineoverride

Definition at line 115 of file MessageSvc.h.

115 { return m_color; }
BooleanProperty m_color
Definition: MessageSvc.h:144

Member Data Documentation

ColorMap MessageSvc::m_colMap
private

Definition at line 165 of file MessageSvc.h.

BooleanProperty MessageSvc::m_color
private

Definition at line 144 of file MessageSvc.h.

std::string MessageSvc::m_defaultFormat
private

Default format for the messages.

Definition at line 141 of file MessageSvc.h.

Message MessageSvc::m_defaultMessage
private

Default Message.

Definition at line 137 of file MessageSvc.h.

std::ostream* MessageSvc::m_defaultStream
private

Pointer to the output stream.

Definition at line 136 of file MessageSvc.h.

std::string MessageSvc::m_defaultTimeFormat
private

Default format for timestamps in the messages.

Definition at line 142 of file MessageSvc.h.

BooleanProperty MessageSvc::m_inactCount
private

Definition at line 161 of file MessageSvc.h.

std::map<std::string,MsgAry> MessageSvc::m_inactiveMap
private

Definition at line 160 of file MessageSvc.h.

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

Definition at line 150 of file MessageSvc.h.

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

Definition at line 147 of file MessageSvc.h.

std::map<std::string, std::shared_ptr<std::ostream> > MessageSvc::m_loggedStreams
private

Definition at line 170 of file MessageSvc.h.

std::map<std::string, std::string> MessageSvc::m_loggedStreamsName
private

Definition at line 169 of file MessageSvc.h.

MessageMap MessageSvc::m_messageMap
private

Message map.

Definition at line 139 of file MessageSvc.h.

std::recursive_mutex MessageSvc::m_messageMapMutex
mutableprivate

Mutex to synchronize multiple access to m_messageMap.

Definition at line 187 of file MessageSvc.h.

std::array<int,MSG::NUM_LEVELS> MessageSvc::m_msgCount
private

Definition at line 167 of file MessageSvc.h.

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

Definition at line 148 of file MessageSvc.h.

std::recursive_mutex MessageSvc::m_reportMutex
mutableprivate

Mutex to synchronize multiple threads printing.

Definition at line 184 of file MessageSvc.h.

std::map<std::string,MsgAry> MessageSvc::m_sourceMap
private

Definition at line 160 of file MessageSvc.h.

UnsignedIntegerProperty MessageSvc::m_statLevel
private

Definition at line 146 of file MessageSvc.h.

BooleanProperty MessageSvc::m_stats
private

Definition at line 145 of file MessageSvc.h.

StreamMap MessageSvc::m_streamMap
private

Stream map.

Definition at line 138 of file MessageSvc.h.

BooleanProperty MessageSvc::m_suppress
private

Definition at line 161 of file MessageSvc.h.

ThresholdMap MessageSvc::m_thresholdMap
private

Output level threshold map.

Definition at line 140 of file MessageSvc.h.

std::recursive_mutex MessageSvc::m_thresholdMapMutex
mutableprivate

Mutex to synchronize multiple access to m_thresholdMap (.

See also
MsgStream::doOutput).

Definition at line 191 of file MessageSvc.h.

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

Properties controlling.

Definition at line 143 of file MessageSvc.h.


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