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 >
typedef extends base_class
 Typedef to this class. More...
 
typedef extend_interfaces< Interfaces...> extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef extends base_class
 Typedef to this class. More...
 
typedef extend_interfaces< Interfaces...> extend_interfaces_base
 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
 
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...
 

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 157 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 59 of file MessageSvc.cpp.

60  : base_class( name, svcloc ) {
61  m_defaultStream = &std::cout;
62  declareProperty( "Format", m_defaultFormat = Message::getDefaultFormat() );
63  declareProperty( "timeFormat", m_defaultTimeFormat = Message::getDefaultTimeFormat() );
64  declareProperty( "showStats", m_stats = false );
65  declareProperty( "statLevel", m_statLevel = 0 );
66 
67  // Special properties to control output level of individual sources
68  declareProperty( "setVerbose", m_thresholdProp[MSG::VERBOSE] );
69  declareProperty( "setDebug", m_thresholdProp[MSG::DEBUG] );
70  declareProperty( "setInfo", m_thresholdProp[MSG::INFO] );
71  declareProperty( "setWarning", m_thresholdProp[MSG::WARNING] );
72  declareProperty( "setError", m_thresholdProp[MSG::ERROR] );
73  declareProperty( "setFatal", m_thresholdProp[MSG::FATAL] );
74  declareProperty( "setAlways", m_thresholdProp[MSG::ALWAYS] );
75 
76  declareProperty( "useColors", m_color=false)->declareUpdateHandler(&MessageSvc::initColors, this);
77 
78  declareProperty( "fatalColorCode", m_logColors[MSG::FATAL] );
79  declareProperty( "errorColorCode", m_logColors[MSG::ERROR] );
80  declareProperty( "warningColorCode", m_logColors[MSG::WARNING] );
81  declareProperty( "infoColorCode", m_logColors[MSG::INFO] );
82  declareProperty( "debugColorCode", m_logColors[MSG::DEBUG] );
83  declareProperty( "verboseColorCode", m_logColors[MSG::VERBOSE] );
84  declareProperty( "alwaysColorCode", m_logColors[MSG::ALWAYS] );
85 
86  const int defaultLimit = 500;
87  declareProperty( "fatalLimit", m_msgLimit[MSG::FATAL] = defaultLimit );
88  declareProperty( "errorLimit", m_msgLimit[MSG::ERROR] = defaultLimit );
89  declareProperty( "warningLimit", m_msgLimit[MSG::WARNING] = defaultLimit );
90  declareProperty( "infoLimit", m_msgLimit[MSG::INFO] = defaultLimit );
91  declareProperty( "debugLimit", m_msgLimit[MSG::DEBUG] = defaultLimit );
92  declareProperty( "verboseLimit", m_msgLimit[MSG::VERBOSE] = defaultLimit );
93  declareProperty( "alwaysLimit", m_msgLimit[MSG::ALWAYS] = 0 );
94 
95  declareProperty( "defaultLimit", m_msgLimit[MSG::NIL] = defaultLimit );
96 
97  declareProperty( "enableSuppression", m_suppress = false );
98  declareProperty( "countInactive", m_inactCount = false )->declareUpdateHandler( &MessageSvc::setupInactCount, this );
99 #ifndef NDEBUG
100  // initialize the MsgStream static flag.
102 #endif
103 
104  declareProperty( "loggedStreams",
106  "MessageStream sources we want to dump into a logfile" );
107 
108  for (int ic=0; ic<MSG::NUM_LEVELS; ++ic) {
112  }
113 
115 }
IntegerProperty m_msgLimit[MSG::NUM_LEVELS]
Definition: MessageSvc.h:141
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:129
std::array< int, MSG::NUM_LEVELS > m_msgCount
Definition: MessageSvc.h:160
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
void setupLimits(Property &prop)
Definition: MessageSvc.cpp:247
void setupInactCount(Property &prop)
Definition: MessageSvc.cpp:311
UnsignedIntegerProperty m_statLevel
Definition: MessageSvc.h:139
extends base_class
Typedef to this class.
Definition: extends.h:14
static const std::string getDefaultTimeFormat()
Get the default time format string.
Definition: Message.cpp:206
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
static const std::string getDefaultFormat()
Get the default format string.
Definition: Message.cpp:167
StringArrayProperty m_thresholdProp[MSG::NUM_LEVELS]
Properties controlling.
Definition: MessageSvc.h:136
std::string m_defaultFormat
Default format for the messages.
Definition: MessageSvc.h:134
void setupColors(Property &prop)
Definition: MessageSvc.cpp:197
virtual void declareUpdateHandler(std::function< void(Property &)> fun)
set new callback for update
Definition: Property.cpp:71
void initColors(Property &prop)
Definition: MessageSvc.cpp:167
BooleanProperty m_color
Definition: MessageSvc.h:137
BooleanProperty m_inactCount
Definition: MessageSvc.h:154
BooleanProperty m_stats
Definition: MessageSvc.h:138
std::map< std::string, std::string > m_loggedStreamsName
Definition: MessageSvc.h:162
BooleanProperty m_suppress
Definition: MessageSvc.h:154
void setupThreshold(Property &prop)
Definition: MessageSvc.cpp:274
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:135
StringArrayProperty m_logColors[MSG::NUM_LEVELS]
Definition: MessageSvc.h:140
MessageSvc::~MessageSvc ( )
overridedefault

Member Function Documentation

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

Definition at line 436 of file MessageSvc.cpp.

436  {
437  auto itr = m_colMap.find(col);
438  int icol = offset + ( (itr != m_colMap.end()) ? itr->second : 8 );
439  return std::to_string( icol );
440 }
ColorMap m_colMap
Definition: MessageSvc.h:158
std::ostream* MessageSvc::defaultStream ( ) const
inline

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:129
void MessageSvc::eraseMessage ( )
override

Definition at line 653 of file MessageSvc.cpp.

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

Definition at line 666 of file MessageSvc.cpp.

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

Definition at line 679 of file MessageSvc.cpp.

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

Definition at line 587 of file MessageSvc.cpp.

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

Definition at line 599 of file MessageSvc.cpp.

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

Definition at line 611 of file MessageSvc.cpp.

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

Definition at line 626 of file MessageSvc.cpp.

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

Finalize Service.

Definition at line 323 of file MessageSvc.cpp.

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

Definition at line 716 of file MessageSvc.cpp.

716  {
717 // ---------------------------------------------------------------------------
718  return (logLevel < MSG::NUM_LEVELS) ? m_logColorCodes[logLevel] : "" ;
719 }
std::string m_logColorCodes[MSG::NUM_LEVELS]
Definition: MessageSvc.h:143
void MessageSvc::incrInactiveCount ( MSG::Level  level,
const std::string &  src 
)
override

Definition at line 730 of file MessageSvc.cpp.

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

Definition at line 167 of file MessageSvc.cpp.

167  {
168 
169  if (m_color) {
170  static const std::array<std::pair<MSG::Level,std::vector<std::string>>,3> tbl{
171  { { MSG::FATAL, { { "[94;101;1m" } } },
172  { MSG::ERROR, { { "[97;101;1m" } } },
173  { MSG::WARNING, { { "[93;1m" } } } } };
174 
175  for (const auto& p : tbl ) {
176  auto &lC = m_logColors[p.first];
177  if (lC.value().empty()) {
178  lC.set(p.second);
179  } else {
181  }
182  }
183 
184  } else {
185 
186  // reset all color codes;
187  for (int ic=0; ic<MSG::NUM_LEVELS; ++ic) {
188  m_logColors[ic].set( { } );
189  }
190 
191  }
192 
193 }
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:197
BooleanProperty m_color
Definition: MessageSvc.h:137
StringArrayProperty m_logColors[MSG::NUM_LEVELS]
Definition: MessageSvc.h:140
StatusCode MessageSvc::initialize ( )
override

Initialize Service.

Definition at line 121 of file MessageSvc.cpp.

121  {
122  StatusCode sc;
123  sc = Service::initialize();
124  if( sc.isFailure() ) return sc;
125  // Release pointer to myself done in Service base class
126  //if( m_msgsvc.isValid() ) {
127  // m_msgsvc = 0;
128  //}
129  // Set my own properties
130  sc = setProperties();
131  if (sc.isFailure()) return sc;
132 
133 #ifdef _WIN32
134  m_color = false;
135 #endif
136 
137  //NOTE: m_colMap is used _before_ it is filled here,
138  // i.e. while it is still empty.
139  // Moving this initialization 'up' by eg. just
140  // having a 'static const' colMap does not leave
141  // the results invariant...
142  m_colMap["black"] = MSG::BLACK;
143  m_colMap["red"] = MSG::RED;
144  m_colMap["green"] = MSG::GREEN;
145  m_colMap["yellow"] = MSG::YELLOW;
146  m_colMap["blue"] = MSG::BLUE;
147  m_colMap["purple"] = MSG::PURPLE;
148  m_colMap["cyan"] = MSG::CYAN;
149  m_colMap["white"] = MSG::WHITE;
150 
151  // make sure the map of logged stream names is initialized
152  setupLogStreams();
153 
154  return StatusCode::SUCCESS;
155 }
StatusCode initialize() override
Definition: Service.cpp:62
ColorMap m_colMap
Definition: MessageSvc.h:158
void setupLogStreams()
Definition: MessageSvc.cpp:737
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:137
void MessageSvc::insertMessage ( const StatusCode code,
const Message message 
)
override

Definition at line 640 of file MessageSvc.cpp.

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

Definition at line 573 of file MessageSvc.cpp.

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

Definition at line 722 of file MessageSvc.cpp.

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

Definition at line 688 of file MessageSvc.cpp.

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

Definition at line 694 of file MessageSvc.cpp.

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

Reinitialize Service.

Definition at line 160 of file MessageSvc.cpp.

160  {
162  return initialize();
163 }
StatusCode initialize() override
Initialize Service.
Definition: MessageSvc.cpp:121
void MessageSvc::reportMessage ( const Message message)
override

Definition at line 510 of file MessageSvc.cpp.

510  {
511  reportMessage(msg, outputLevel(msg.getSource()));
512 }
void reportMessage(const Message &message) override
Definition: MessageSvc.cpp:510
int outputLevel() const override
Definition: MessageSvc.cpp:688
void MessageSvc::reportMessage ( const Message msg,
int  outputLevel 
)
override

Definition at line 449 of file MessageSvc.cpp.

449  {
450  std::unique_lock<std::recursive_mutex> lock(m_reportMutex);
451 
452  int key = msg.getType();
453 
454  ++m_msgCount[key];
455 
456  const Message *cmsg = &msg;
457 
458  // processing logged streams
459  if ( !m_loggedStreams.empty() ) {
460  auto iLog = m_loggedStreams.find( msg.getSource() );
461  if ( m_loggedStreams.end() != iLog ) {
462  (*iLog->second) << *cmsg << std::endl;
463  }
464  }
465 
466  if ( m_suppress.value() || m_stats.value() ) {
467 
468  // Increase the counter of 'key' type of messages for the source and
469  // get the new value.
470  const int nmsg = ++(m_sourceMap[msg.getSource()].msg[key]);
471 
472  if (m_suppress.value() && m_msgLimit[key] != 0 ) {
473  if (nmsg > m_msgLimit[key]) return;
474  if (nmsg == m_msgLimit[key]) {
475  std::string txt = levelNames[key] + " message limit ("
476  + std::to_string( m_msgLimit[key].value() )
477  + ") reached for " + msg.getSource() + ". Suppressing further output.";
478  cmsg = new Message(msg.getSource(), MSG::WARNING, std::move(txt));
479  cmsg->setFormat(msg.getFormat());
480  }
481  }
482  }
483 
484  auto range = m_streamMap.equal_range( key );
485  if ( range.first != m_streamMap.end() ) {
486  std::for_each( range.first,range.second, [&](StreamMap::const_reference sm) {
487  *sm.second.second << *cmsg << std::endl;
488  });
489  } else if ( key >= outputLevel ) {
492  if (!m_color) {
493  (*m_defaultStream) << *cmsg << std::endl << std::flush;
494  } else {
495  (*m_defaultStream) << m_logColorCodes[key] << *cmsg << "\033[m"
496  << std::endl << std::flush;
497  }
498  }
499 
500  if (cmsg != &msg) { delete cmsg; }
501 
502 }
IntegerProperty m_msgLimit[MSG::NUM_LEVELS]
Definition: MessageSvc.h:141
const std::string & getFormat() const
Get the format string.
Definition: Message.cpp:156
StreamMap m_streamMap
Stream map.
Definition: MessageSvc.h:131
std::array< int, MSG::NUM_LEVELS > m_msgCount
Definition: MessageSvc.h:160
int getType() const
Get the message type.
Definition: Message.cpp:73
std::map< std::string, std::shared_ptr< std::ostream > > m_loggedStreams
Definition: MessageSvc.h:163
std::map< std::string, MsgAry > m_sourceMap
Definition: MessageSvc.h:153
NamedRange_< CONTAINER > range(const CONTAINER &cnt, std::string name)
simple function to create the named range form arbitrary container
Definition: NamedRange.h:130
def lock(file)
Definition: locker.py:16
std::recursive_mutex m_reportMutex
Mutex to synchronize multiple threads printing.
Definition: MessageSvc.h:177
const TYPE & value() const
explicit conversion
Definition: Property.h:341
void setFormat(std::string msg) const
Set the format string.
Definition: Message.cpp:180
The Message class.
Definition: Message.h:14
std::string m_defaultFormat
Default format for the messages.
Definition: MessageSvc.h:134
void setTimeFormat(std::string timeFormat) const
Set the time format string.
Definition: Message.cpp:219
std::string m_logColorCodes[MSG::NUM_LEVELS]
Definition: MessageSvc.h:143
const std::string & getSource() const
Get the message source.
Definition: Message.cpp:95
BooleanProperty m_color
Definition: MessageSvc.h:137
int outputLevel() const override
Definition: MessageSvc.cpp:688
BooleanProperty m_stats
Definition: MessageSvc.h:138
BooleanProperty m_suppress
Definition: MessageSvc.h:154
std::string m_defaultTimeFormat
Default format for timestamps in the messages.
Definition: MessageSvc.h:135
void MessageSvc::reportMessage ( const StatusCode code,
const std::string &  source = "" 
)
override

Definition at line 545 of file MessageSvc.cpp.

547 {
548  std::unique_lock<std::recursive_mutex> lock(m_messageMapMutex);
549 
550  auto report = [&](Message mesg) {
551  mesg.setSource( source );
552  Message stat_code( source, mesg.getType(), "Status Code " + std::to_string( key.getCode() ) );
553  reportMessage( std::move(stat_code) );
554  reportMessage( std::move(mesg) );
555  };
556 
557  auto range = m_messageMap.equal_range( key );
558  if ( range.first != m_messageMap.end() ) {
559  std::for_each( range.first, range.second,
560  [&](MessageMap::const_reference sm) { report(sm.second); } );
561  } else {
562  report(m_defaultMessage);
563  }
564 }
Message m_defaultMessage
Default Message.
Definition: MessageSvc.h:130
MessageMap m_messageMap
Message map.
Definition: MessageSvc.h:132
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
Definition: MessageSvc.h:180
NamedRange_< CONTAINER > range(const CONTAINER &cnt, std::string name)
simple function to create the named range form arbitrary container
Definition: NamedRange.h:130
void reportMessage(const Message &message) override
Definition: MessageSvc.cpp:510
def lock(file)
Definition: locker.py:16
The Message class.
Definition: Message.h:14
void MessageSvc::reportMessage ( const char *  source,
int  type,
const char *  message 
)
override

Definition at line 520 of file MessageSvc.cpp.

522  {
523  reportMessage( Message{ source, type, message } );
524 }
void reportMessage(const Message &message) override
Definition: MessageSvc.cpp:510
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 532 of file MessageSvc.cpp.

534  {
535  reportMessage( Message{source, type, message} );
536 }
void reportMessage(const Message &message) override
Definition: MessageSvc.cpp:510
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:129
def lock(file)
Definition: locker.py:16
std::recursive_mutex m_reportMutex
Mutex to synchronize multiple threads printing.
Definition: MessageSvc.h:177
void MessageSvc::setOutputLevel ( int  new_level)
override

Definition at line 702 of file MessageSvc.cpp.

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

Definition at line 708 of file MessageSvc.cpp.

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

Definition at line 197 of file MessageSvc.cpp.

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

Definition at line 311 of file MessageSvc.cpp.

311  {
312  if (prop.name() == "countInactive") {
313  BooleanProperty *p = dynamic_cast<BooleanProperty*>(&prop);
314  if (p)
316  }
317 }
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 247 of file MessageSvc.cpp.

247  {
248  // Just report problems in the settings of the limits and unknown limit parameters
249  if (prop.name() == "alwaysLimit") {
250  IntegerProperty *p = dynamic_cast<IntegerProperty*>(&prop);
251  if (p && p->value() != 0) {
252  cout << "MessageSvc ERROR: cannot suppress ALWAYS messages" << endl;
253  p->setValue(0);
254  }
255  } else if (prop.name() == "defaultLimit") {
256  for (int i = MSG::VERBOSE; i< MSG::NUM_LEVELS; ++i) {
257  if (i != MSG::ALWAYS) {
259  }
260  }
261  } else if (prop.name() != "fatalLimit" &&
262  prop.name() != "errorLimit" &&
263  prop.name() != "warningLimit" &&
264  prop.name() == "infoLimit" &&
265  prop.name() == "debugLimit" &&
266  prop.name() == "verboseLimit") {
267  cout << "MessageSvc ERROR: Unknown message limit parameter: "
268  << prop.name() << endl;
269  return;
270  }
271 }
IntegerProperty m_msgLimit[MSG::NUM_LEVELS]
Definition: MessageSvc.h:141
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 737 of file MessageSvc.cpp.

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

Definition at line 274 of file MessageSvc.cpp.

274  {
275 
276  static const std::array<std::pair<const char*,MSG::Level>,7> tbl{
277  { { "setFatal", MSG::FATAL },
278  { "setError", MSG::ERROR },
279  { "setWarning", MSG::WARNING },
280  { "setInfo", MSG::INFO },
281  { "setDebug", MSG::DEBUG },
282  { "setVerbose", MSG::VERBOSE },
283  { "setAlways", MSG::ALWAYS } } };
284 
285  auto i = std::find_if( std::begin(tbl),std::end(tbl),
286  [&](const std::pair<const char*,MSG::Level>& t) {
287  return prop.name() == t.first;
288  } );
289  if (i==std::end(tbl)) {
290  cerr << "MessageSvc ERROR: Unknown message threshold parameter: "
291  << prop.name() << endl;
292  return;
293  }
294  int ic = i->second;
295 
296  StringArrayProperty *sap = dynamic_cast<StringArrayProperty*>( &prop);
297  if (!sap) {
298  std::cerr << "could not dcast " << prop.name()
299  << " to a StringArrayProperty (which it should be!)" << endl;
300  } else {
301  for ( auto& i : sap->value() ) setOutputLevel( i, ic );
302  }
303 
304 }
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:702
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 756 of file MessageSvc.cpp.

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

Member Data Documentation

ColorMap MessageSvc::m_colMap
private

Definition at line 158 of file MessageSvc.h.

BooleanProperty MessageSvc::m_color
private

Definition at line 137 of file MessageSvc.h.

std::string MessageSvc::m_defaultFormat
private

Default format for the messages.

Definition at line 134 of file MessageSvc.h.

Message MessageSvc::m_defaultMessage
private

Default Message.

Definition at line 130 of file MessageSvc.h.

std::ostream* MessageSvc::m_defaultStream
private

Pointer to the output stream.

Definition at line 129 of file MessageSvc.h.

std::string MessageSvc::m_defaultTimeFormat
private

Default format for timestamps in the messages.

Definition at line 135 of file MessageSvc.h.

BooleanProperty MessageSvc::m_inactCount
private

Definition at line 154 of file MessageSvc.h.

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

Definition at line 153 of file MessageSvc.h.

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

Definition at line 143 of file MessageSvc.h.

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

Definition at line 140 of file MessageSvc.h.

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

Definition at line 163 of file MessageSvc.h.

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

Definition at line 162 of file MessageSvc.h.

MessageMap MessageSvc::m_messageMap
private

Message map.

Definition at line 132 of file MessageSvc.h.

std::recursive_mutex MessageSvc::m_messageMapMutex
mutableprivate

Mutex to synchronize multiple access to m_messageMap.

Definition at line 180 of file MessageSvc.h.

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

Definition at line 160 of file MessageSvc.h.

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

Definition at line 141 of file MessageSvc.h.

std::recursive_mutex MessageSvc::m_reportMutex
mutableprivate

Mutex to synchronize multiple threads printing.

Definition at line 177 of file MessageSvc.h.

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

Definition at line 153 of file MessageSvc.h.

UnsignedIntegerProperty MessageSvc::m_statLevel
private

Definition at line 139 of file MessageSvc.h.

BooleanProperty MessageSvc::m_stats
private

Definition at line 138 of file MessageSvc.h.

StreamMap MessageSvc::m_streamMap
private

Stream map.

Definition at line 131 of file MessageSvc.h.

BooleanProperty MessageSvc::m_suppress
private

Definition at line 154 of file MessageSvc.h.

ThresholdMap MessageSvc::m_thresholdMap
private

Output level threshold map.

Definition at line 133 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 184 of file MessageSvc.h.

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

Properties controlling.

Definition at line 136 of file MessageSvc.h.


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