The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
MessageSvc Class Reference

#include </builds/gaudi/Gaudi/GaudiCoreSvc/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, std::less<> > ThresholdMap
 
- Public Types inherited from extends< Service, IMessageSvc, IInactiveMessageCounter >
using base_class
 Typedef to this class.
 
using extend_interfaces_base
 Typedef to the base of this class.
 
- Public Types inherited from Service
using Factory = Gaudi::PluginService::Factory<IService*( const std::string&, ISvcLocator* )>
 
- Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl
 Typedef used to refer to this class from derived classes, as in.
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids
 take union of the ext_iids of all Interfaces...
 

Public Member Functions

 MessageSvc (const std::string &name, ISvcLocator *svcloc)
 
StatusCode reinitialize () override
 
StatusCode initialize () override
 
StatusCode finalize () override
 
void reportMessage (const Message &message) override
 
void reportMessage (const Message &msg, int outputLevel) override
 
void reportMessage (const StatusCode &code, std::string_view source="") override
 
void reportMessage (std::string source, int type, std::string message) override
 
void insertMessage (const StatusCode &code, 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, 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 (std::string_view source) const override
 
void setOutputLevel (int new_level) override
 
void setOutputLevel (std::string_view 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, std::string_view src) override
 
- Public Member Functions inherited from extends< Service, IMessageSvc, IInactiveMessageCounter >
void const * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast.
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface.
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames.
 
- Public Member Functions inherited from Service
const std::string & name () const override
 Retrieve name of the service.
 
StatusCode configure () override
 
StatusCode initialize () override
 
StatusCode start () override
 
StatusCode stop () override
 
StatusCode finalize () override
 
StatusCode terminate () override
 
Gaudi::StateMachine::State FSMState () const override
 
Gaudi::StateMachine::State targetFSMState () const override
 
StatusCode reinitialize () override
 
StatusCode restart () override
 
StatusCode sysInitialize () override
 Initialize Service.
 
StatusCode sysStart () override
 Initialize Service.
 
StatusCode sysStop () override
 Initialize Service.
 
StatusCode sysFinalize () override
 Finalize Service.
 
StatusCode sysReinitialize () override
 Re-initialize the Service.
 
StatusCode sysRestart () override
 Re-initialize the Service.
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor.
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator.
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
template<class T>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
 
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, bool createIf=true)
 
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, const std::string &toolTypeAndName, bool createIf=true)
 Declare used tool.
 
template<class T>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandleArray< T > &hndlArr, const std::string &doc="none")
 
template<class T>
void addToolsArray (ToolHandleArray< T > &hndlArr)
 
const std::vector< IAlgTool * > & tools () const
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked.
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property.
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Helper to wrap a regular data member and use it as a regular property.
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
 Declare a PropertyBase instance setting name and documentation.
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property.
 
StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p) override
 set the property from another property with a different name
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property
 
const Gaudi::Details::PropertyBasegetProperty (std::string_view name) const override
 get the property by name
 
StatusCode getProperty (std::string_view n, std::string &v) const override
 convert the property to the string
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties
 
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name.
 
Gaudi::Details::PropertyBaseproperty (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected
 
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 
- Public Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream)
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor.
 
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream.
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS)
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL)
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING)
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO)
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG)
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO)
 

Protected Member Functions

virtual void i_reportMessage (const Message &msg, int outputLevel)
 Internal implementation of reportMessage(const Message&,int) without lock.
 
virtual void i_reportMessage (const StatusCode &code, std::string_view source)
 Internal implementation of reportMessage(const StatusCode&,const std::string&) without lock.
 
- Protected Member Functions inherited from Service
std::vector< IAlgTool * > & tools ()
 
 ~Service () override
 
int outputLevel () const
 get the Service's output level
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches.
 
MSG::Level resetMessaging ()
 Reinitialize internal states.
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream.
 

Private Member Functions

void setupColors (Gaudi::Details::PropertyBase &prop)
 
void setupLimits (Gaudi::Details::PropertyBase &prop)
 
void setupThreshold (Gaudi::Details::PropertyBase &prop)
 
void setupInactCount (Gaudi::Details::PropertyBase &prop)
 
void setupLogStreams ()
 

Private Attributes

Gaudi::Property< std::string > m_defaultFormat { this, "Format", Message::getDefaultFormat(), "" }
 
Gaudi::Property< std::string > m_defaultTimeFormat { this, "timeFormat", Message::getDefaultTimeFormat(), "" }
 
Gaudi::Property< bool > m_stats { this, "showStats", false, "" }
 
Gaudi::Property< unsigned int > m_statLevel { this, "statLevel", 0, "" }
 
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELSm_thresholdProp
 
Gaudi::Property< bool > m_color { this, "useColors", false, "" }
 
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELSm_logColors
 
std::array< Gaudi::Property< int >, MSG::NUM_LEVELSm_msgLimit
 
Gaudi::Property< bool > m_suppress { this, "enableSuppression", false, "" }
 
Gaudi::Property< bool > m_inactCount { this, "countInactive", false, &MessageSvc::setupInactCount, "" }
 
Gaudi::Property< std::vector< std::string > > m_tracedInactiveSources
 
Gaudi::Property< std::map< std::string, std::string, std::less<> > > m_loggedStreamsName
 
std::ostream * m_defaultStream = &std::cout
 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_logColorCodes [MSG::NUM_LEVELS]
 
std::map< std::string, MsgAry, std::less<> > m_sourceMap
 
std::map< std::string, MsgAry, std::less<> > m_inactiveMap
 
std::array< int, MSG::NUM_LEVELSm_msgCount
 
std::map< std::string, std::shared_ptr< std::ostream >, std::less<> > m_loggedStreams
 
std::recursive_mutex m_reportMutex
 Mutex to synchronize multiple threads printing.
 
std::recursive_mutex m_messageMapMutex
 Mutex to synchronize multiple access to m_messageMap.
 
std::recursive_mutex m_thresholdMapMutex
 Mutex to synchronize multiple access to m_thresholdMap (.
 

Additional Inherited Members

- Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state.
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state.
 
Gaudi::Property< int > m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
 flag indicating whether ToolHandle tools have been added to m_tools
 
Gaudi::Property< bool > m_auditorInitialize { this, "AuditInitialize", false, "trigger auditor on initialize()" }
 
Gaudi::Property< bool > m_auditorStart { this, "AuditStart", false, "trigger auditor on start()" }
 
Gaudi::Property< bool > m_auditorStop { this, "AuditStop", false, "trigger auditor on stop()" }
 
Gaudi::Property< bool > m_auditorFinalize { this, "AuditFinalize", false, "trigger auditor on finalize()" }
 
Gaudi::Property< bool > m_auditorReinitialize { this, "AuditReinitialize", false, "trigger auditor on reinitialize()" }
 
Gaudi::Property< bool > m_auditorRestart { this, "AuditRestart", false, "trigger auditor on restart()" }
 
Gaudi::Property< bool > m_autoRetrieveTools
 
Gaudi::Property< bool > m_checkToolDeps
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service.
 

Detailed Description

Definition at line 35 of file MessageSvc.h.

Member Typedef Documentation

◆ MessageMap

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

Definition at line 39 of file MessageSvc.h.

◆ NamedStream

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

Definition at line 37 of file MessageSvc.h.

◆ StreamMap

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

Definition at line 38 of file MessageSvc.h.

◆ ThresholdMap

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

Definition at line 40 of file MessageSvc.h.

Constructor & Destructor Documentation

◆ MessageSvc()

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

Definition at line 64 of file MessageSvc.cpp.

64 : base_class( name, svcloc ) {
65
66 m_outputLevel.declareUpdateHandler( [svcloc]( Gaudi::Details::PropertyBase& ) {
67 SmartIF<IAppMgrUI> app = svcloc;
68 if ( app ) app->outputLevelUpdate();
69 } );
70
71#ifndef NDEBUG
72 // initialize the MsgStream static flag.
74#endif
75
76 for ( int ic = 0; ic < MSG::NUM_LEVELS; ++ic ) {
77 m_logColors[ic].declareUpdateHandler( &MessageSvc::setupColors, this );
78 m_msgLimit[ic].declareUpdateHandler( &MessageSvc::setupLimits, this );
79 m_thresholdProp[ic].declareUpdateHandler( &MessageSvc::setupThreshold, this );
80 }
81
82 m_logColors[MSG::FATAL].set( { "blue", "red" } );
83 m_logColors[MSG::ERROR].set( { "white", "red" } );
84 m_logColors[MSG::WARNING].set( { "yellow" } );
85
86 std::fill( std::begin( m_msgCount ), std::end( m_msgCount ), 0 );
87}
Gaudi::Property< bool > m_inactCount
Definition MessageSvc.h:167
std::array< Gaudi::Property< int >, MSG::NUM_LEVELS > m_msgLimit
Definition MessageSvc.h:157
void setupThreshold(Gaudi::Details::PropertyBase &prop)
std::array< int, MSG::NUM_LEVELS > m_msgCount
Definition MessageSvc.h:196
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_logColors
Definition MessageSvc.h:148
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_thresholdProp
Definition MessageSvc.h:137
void setupLimits(Gaudi::Details::PropertyBase &prop)
void setupColors(Gaudi::Details::PropertyBase &prop)
static GAUDI_API bool enableCountInactive(bool value=true)
Enable/disable the count of inactive messages.
Definition MsgStream.cpp:21
Gaudi::Property< int > m_outputLevel
flag indicating whether ToolHandle tools have been added to m_tools
Definition Service.h:184
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333
@ NUM_LEVELS
Definition IMessageSvc.h:22
@ WARNING
Definition IMessageSvc.h:22
@ FATAL
Definition IMessageSvc.h:22
@ ERROR
Definition IMessageSvc.h:22
app
Definition Read.py:36

Member Function Documentation

◆ defaultStream()

std::ostream * MessageSvc::defaultStream ( ) const
inlineoverride

Definition at line 92 of file MessageSvc.h.

92{ return m_defaultStream; }
std::ostream * m_defaultStream
Pointer to the output stream.
Definition MessageSvc.h:178

◆ eraseMessage() [1/3]

void MessageSvc::eraseMessage ( )
override

Definition at line 411 of file MessageSvc.cpp.

411 {
412 auto lock = std::scoped_lock{ m_messageMapMutex };
413 m_messageMap.clear();
414}
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
Definition MessageSvc.h:211
MessageMap m_messageMap
Message map.
Definition MessageSvc.h:181

◆ eraseMessage() [2/3]

void MessageSvc::eraseMessage ( const StatusCode & code)
override

Definition at line 416 of file MessageSvc.cpp.

416 {
417 auto lock = std::scoped_lock{ m_messageMapMutex };
418 m_messageMap.erase( key );
419}

◆ eraseMessage() [3/3]

void MessageSvc::eraseMessage ( const StatusCode & code,
const Message & message )
override

Definition at line 421 of file MessageSvc.cpp.

421 {
422 auto lock = std::scoped_lock{ m_messageMapMutex };
423
424 erase_if( m_messageMap, m_messageMap.equal_range( key ),
425 [&]( MessageMap::const_reference j ) { return j.second == msg; } );
426}

◆ eraseStream() [1/4]

void MessageSvc::eraseStream ( )
override

Definition at line 389 of file MessageSvc.cpp.

389{ m_streamMap.clear(); }
StreamMap m_streamMap
Stream map.
Definition MessageSvc.h:180

◆ eraseStream() [2/4]

void MessageSvc::eraseStream ( int message_type)
override

Definition at line 391 of file MessageSvc.cpp.

391{ m_streamMap.erase( message_type ); }

◆ eraseStream() [3/4]

void MessageSvc::eraseStream ( int message_type,
std::ostream * stream )
override

Definition at line 393 of file MessageSvc.cpp.

393 {
394 if ( stream ) {
395 erase_if( m_streamMap, m_streamMap.equal_range( key ),
396 [&]( StreamMap::const_reference j ) { return j.second.second == stream; } );
397 }
398}

◆ eraseStream() [4/4]

void MessageSvc::eraseStream ( std::ostream * stream)
override

Definition at line 400 of file MessageSvc.cpp.

400 {
401 if ( stream ) {
402 erase_if( m_streamMap, [&]( StreamMap::const_reference j ) { return j.second.second == stream; } );
403 }
404}
stream
Definition Write.py:32

◆ finalize()

StatusCode MessageSvc::finalize ( )
override

Definition at line 198 of file MessageSvc.cpp.

198 {
199 m_suppress = false;
200
201 {
202 std::ostringstream os;
203
204 if ( m_stats ) {
205 os << "Summarizing all message counts" << std::endl;
206 } else {
207 os << "Listing sources of suppressed message: " << std::endl;
208 }
209
210 os << "=====================================================" << std::endl;
211 os << " Message Source | Level | Count" << std::endl;
212 os << "-----------------------------+---------+-------------" << std::endl;
213
214 bool found( false );
215
216 for ( auto itr = m_sourceMap.begin(); itr != m_sourceMap.end(); ++itr ) {
217 for ( unsigned int ic = 0; ic < MSG::NUM_LEVELS; ++ic ) {
218 if ( ( itr->second.msg[ic] >= m_msgLimit[ic] && m_msgLimit[ic] != 0 ) ||
219 ( m_stats && itr->second.msg[ic] > 0 && ic >= m_statLevel.value() ) ) {
220 os << " ";
221 os.width( 28 );
222 os.setf( std::ios_base::left, std::ios_base::adjustfield );
223 os << itr->first;
224 os << "|";
225
226 os.width( 8 );
227 os.setf( std::ios_base::right, std::ios_base::adjustfield );
228 os << levelNames[ic];
229 os << " |";
230
231 os.width( 9 );
232 os << itr->second.msg[ic];
233 os << std::endl;
234
235 found = true;
236 }
237 }
238 }
239 os << "=====================================================" << std::endl;
240 if ( found || m_stats ) std::cout << os.str() << std::flush;
241 }
242
243#ifndef NDEBUG
244 if ( m_inactCount.value() ) {
245
246 std::ostringstream os;
247 os << "Listing sources of Unprotected and Unseen messages\n";
248
249 bool found( false );
250
251 unsigned int ml( 0 );
252 for ( const auto& itr : m_inactiveMap ) {
253 for ( unsigned int ic = 0; ic < MSG::NUM_LEVELS; ++ic ) {
254 if ( itr.second.msg[ic] != 0 && itr.first.length() > ml ) { ml = itr.first.length(); }
255 }
256 }
257
258 for ( unsigned int i = 0; i < ml + 25; ++i ) os << "=";
259
260 os << std::endl << " ";
261 os.width( ml + 2 );
262 os.setf( std::ios_base::left, std::ios_base::adjustfield );
263 os << "Message Source";
264 os.width( 1 );
265 os << "| Level | Count" << std::endl;
266
267 for ( unsigned int i = 0; i < ml + 3; ++i ) os << "-";
268 os << "+---------+-----------" << std::endl;
269
270 for ( auto itr = m_inactiveMap.begin(); itr != m_inactiveMap.end(); ++itr ) {
271 for ( unsigned int ic = 0; ic < MSG::NUM_LEVELS; ++ic ) {
272 if ( itr->second.msg[ic] != 0 ) {
273 os << " ";
274 os.width( ml + 2 );
275 os.setf( std::ios_base::left, std::ios_base::adjustfield );
276 os << itr->first;
277
278 os << "|";
279
280 os.width( 8 );
281 os.setf( std::ios_base::right, std::ios_base::adjustfield );
282 os << levelNames[ic];
283
284 os << " |";
285
286 os.width( 9 );
287 os << itr->second.msg[ic];
288
289 os << std::endl;
290
291 found = true;
292 }
293 }
294 }
295 for ( unsigned int i = 0; i < ml + 25; ++i ) os << "=";
296 os << std::endl;
297
298 if ( found ) std::cout << os.str() << std::flush;
299 }
300#endif
301
302 return StatusCode::SUCCESS;
303}
std::map< std::string, MsgAry, std::less<> > m_sourceMap
Definition MessageSvc.h:194
std::map< std::string, MsgAry, std::less<> > m_inactiveMap
Definition MessageSvc.h:194
Gaudi::Property< unsigned int > m_statLevel
Definition MessageSvc.h:135
Gaudi::Property< bool > m_suppress
Definition MessageSvc.h:166
Gaudi::Property< bool > m_stats
Definition MessageSvc.h:134
constexpr static const auto SUCCESS
Definition StatusCode.h:99

◆ getLogColor()

std::string MessageSvc::getLogColor ( int logLevel) const
override

Definition at line 450 of file MessageSvc.cpp.

450 {
451 return ( logLevel < MSG::NUM_LEVELS ) ? m_logColorCodes[logLevel] : "";
452}
std::string m_logColorCodes[MSG::NUM_LEVELS]
Definition MessageSvc.h:184

◆ i_reportMessage() [1/2]

void MessageSvc::i_reportMessage ( const Message & msg,
int outputLevel )
protectedvirtual

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

Definition at line 310 of file MessageSvc.cpp.

310 {
311 int key = msg.getType();
312
313 ++m_msgCount[key];
314
315 const Message* cmsg = &msg;
316
317 // processing logged streams
318 if ( !m_loggedStreams.empty() ) {
319 auto iLog = m_loggedStreams.find( msg.getSource() );
320 if ( m_loggedStreams.end() != iLog ) { ( *iLog->second ) << *cmsg << std::endl; }
321 }
322
323 if ( m_suppress.value() || m_stats.value() ) {
324
325 // Increase the counter of 'key' type of messages for the source and
326 // get the new value.
327 const int nmsg = ++( m_sourceMap[msg.getSource()].msg[key] );
328
329 if ( m_suppress.value() && m_msgLimit[key] != 0 ) {
330 if ( nmsg > m_msgLimit[key] ) return;
331 if ( nmsg == m_msgLimit[key] ) {
332 std::string txt = levelNames[key] + " message limit (" + std::to_string( m_msgLimit[key].value() ) +
333 ") reached for " + msg.getSource() + ". Suppressing further output.";
334 cmsg = new Message( msg.getSource(), MSG::WARNING, std::move( txt ) );
335 cmsg->setFormat( msg.getFormat() );
336 }
337 }
338 }
339
340 auto range = m_streamMap.equal_range( key );
341 if ( range.first != m_streamMap.end() ) {
342 std::for_each( range.first, range.second,
343 [&]( StreamMap::const_reference sm ) { *sm.second.second << *cmsg << std::endl; } );
344 } else if ( key >= outputLevel ) {
345 msg.setFormat( m_defaultFormat );
346 msg.setTimeFormat( m_defaultTimeFormat );
347 if ( !m_color ) {
348 ( *m_defaultStream ) << *cmsg << std::endl << std::flush;
349 } else {
350 ( *m_defaultStream ) << m_logColorCodes[key] << *cmsg << "\033[m" << std::endl << std::flush;
351 }
352 }
353
354 if ( cmsg != &msg ) { delete cmsg; } // cppcheck-suppress autovarInvalidDeallocation; false positive
355}
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
void setFormat(std::string msg) const
Set the format string.
Definition Message.cpp:97
Gaudi::Property< bool > m_color
Definition MessageSvc.h:146
Gaudi::Property< std::string > m_defaultTimeFormat
Definition MessageSvc.h:133
std::map< std::string, std::shared_ptr< std::ostream >, std::less<> > m_loggedStreams
Definition MessageSvc.h:198
int outputLevel() const override
Gaudi::Property< std::string > m_defaultFormat
Definition MessageSvc.h:132
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
Definition details.h:86

◆ i_reportMessage() [2/2]

void MessageSvc::i_reportMessage ( const StatusCode & code,
std::string_view source )
protectedvirtual

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

Definition at line 368 of file MessageSvc.cpp.

368 {
369 int level = outputLevel( source );
370 auto report = [&]( Message mesg ) {
371 mesg.setSource( source );
372 Message stat_code( std::string{ source }, mesg.getType(), "Status Code " + std::to_string( code.getCode() ) );
373 i_reportMessage( std::move( stat_code ), level );
374 i_reportMessage( std::move( mesg ), level );
375 };
376
377 auto range = m_messageMap.equal_range( code );
378 if ( range.first != m_messageMap.end() ) {
379 std::for_each( range.first, range.second, [&]( MessageMap::const_reference sm ) { report( sm.second ); } );
380 } else {
381 report( m_defaultMessage );
382 }
383}
Message m_defaultMessage
Default Message.
Definition MessageSvc.h:179
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
code_t getCode() const
Retrieve value.
Definition StatusCode.h:136

◆ incrInactiveCount()

void MessageSvc::incrInactiveCount ( MSG::Level level,
std::string_view src )
override

Definition at line 456 of file MessageSvc.cpp.

456 {
457 auto entry = m_inactiveMap.find( source );
458 if ( entry == m_inactiveMap.end() ) { entry = m_inactiveMap.emplace( source, MsgAry{} ).first; }
459 ++entry->second.msg[level];
460
461 if ( std::find( begin( m_tracedInactiveSources ), end( m_tracedInactiveSources ), source ) !=
463 std::cout << "== inactive message detected from " << source << " ==\n";
464 std::string t;
465 System::backTrace( t, 25, 0 );
466 std::cout << t << std::endl;
467 }
468}
Gaudi::Property< std::vector< std::string > > m_tracedInactiveSources
Definition MessageSvc.h:169
AttribStringParser::Iterator begin(const AttribStringParser &parser)
GAUDI_API int backTrace(void **addresses, const int depth)
Definition System.cpp:372
Private helper class to keep the count of messages of a type (MSG::LEVEL).
Definition MessageSvc.h:187

◆ initialize()

StatusCode MessageSvc::initialize ( )
override

Definition at line 89 of file MessageSvc.cpp.

89 {
90 StatusCode sc = Service::initialize();
91 if ( sc.isFailure() ) return sc;
92
93 // make sure the map of logged stream names is initialized
95
97}
void setupLogStreams()
StatusCode initialize() override
Definition Service.cpp:118
bool isFailure() const
Definition StatusCode.h:129

◆ insertMessage()

void MessageSvc::insertMessage ( const StatusCode & code,
Message message )
override

Definition at line 406 of file MessageSvc.cpp.

406 {
407 auto lock = std::scoped_lock{ m_messageMapMutex };
408 m_messageMap.emplace( key, std::move( msg ) );
409}

◆ insertStream()

void MessageSvc::insertStream ( int message_type,
std::string name,
std::ostream * stream )
override

Definition at line 385 of file MessageSvc.cpp.

385 {
386 m_streamMap.emplace( key, NamedStream( std::move( name ), stream ) );
387}
std::pair< std::string, std::ostream * > NamedStream
Definition MessageSvc.h:37

◆ messageCount()

int MessageSvc::messageCount ( MSG::Level logLevel) const
override

Definition at line 454 of file MessageSvc.cpp.

454{ return m_msgCount[level]; }

◆ outputLevel() [1/2]

int MessageSvc::outputLevel ( ) const
override

Definition at line 428 of file MessageSvc.cpp.

428{ return m_outputLevel; }

◆ outputLevel() [2/2]

int MessageSvc::outputLevel ( std::string_view source) const
override

Definition at line 430 of file MessageSvc.cpp.

430 {
431 auto lock = std::scoped_lock{ m_thresholdMapMutex };
432 auto it = m_thresholdMap.find( source );
433 return it != m_thresholdMap.end() ? it->second : m_outputLevel.value();
434}
ThresholdMap m_thresholdMap
Output level threshold map.
Definition MessageSvc.h:182
std::recursive_mutex m_thresholdMapMutex
Mutex to synchronize multiple access to m_thresholdMap (.
Definition MessageSvc.h:215

◆ reinitialize()

StatusCode MessageSvc::reinitialize ( )
override

Definition at line 99 of file MessageSvc.cpp.

99 {
101 StatusCode sc = initialize();
103
104 return sc;
105}
StatusCode initialize() override
Gaudi::StateMachine::State m_state
Service state.
Definition Service.h:155
bool isSuccess() const
Definition StatusCode.h:314

◆ reportMessage() [1/4]

void MessageSvc::reportMessage ( const Message & message)
override

Definition at line 357 of file MessageSvc.cpp.

357{ reportMessage( msg, outputLevel( msg.getSource() ) ); }
void reportMessage(const Message &message) override

◆ reportMessage() [2/4]

void MessageSvc::reportMessage ( const Message & msg,
int outputLevel )
override

Definition at line 305 of file MessageSvc.cpp.

305 {
306 auto lock = std::scoped_lock{ m_reportMutex };
308}
std::recursive_mutex m_reportMutex
Mutex to synchronize multiple threads printing.
Definition MessageSvc.h:208

◆ reportMessage() [3/4]

void MessageSvc::reportMessage ( const StatusCode & code,
std::string_view source = "" )
override

Definition at line 363 of file MessageSvc.cpp.

363 {
364 auto lock = std::scoped_lock{ m_messageMapMutex };
365 i_reportMessage( code, source );
366}

◆ reportMessage() [4/4]

void MessageSvc::reportMessage ( std::string source,
int type,
std::string message )
override

Definition at line 359 of file MessageSvc.cpp.

359 {
360 reportMessage( Message{ std::move( source ), type, std::move( message ) } );
361}

◆ setDefaultStream()

void MessageSvc::setDefaultStream ( std::ostream * stream)
inlineoverride

Definition at line 95 of file MessageSvc.h.

95 {
96 auto lock = std::scoped_lock{ m_reportMutex };
98 }

◆ setOutputLevel() [1/2]

void MessageSvc::setOutputLevel ( int new_level)
override

Definition at line 436 of file MessageSvc.cpp.

436{ m_outputLevel = new_level; }

◆ setOutputLevel() [2/2]

void MessageSvc::setOutputLevel ( std::string_view source,
int new_level )
override

Definition at line 438 of file MessageSvc.cpp.

438 {
439 auto lock = std::scoped_lock{ m_thresholdMapMutex };
440
441 // only write if we really have to...
442 auto i = m_thresholdMap.find( source );
443 if ( i == m_thresholdMap.end() ) {
444 m_thresholdMap.emplace( source, level );
445 } else if ( i->second != level ) {
446 i->second = level;
447 }
448}

◆ setupColors()

void MessageSvc::setupColors ( Gaudi::Details::PropertyBase & prop)
private

Definition at line 107 of file MessageSvc.cpp.

107 {
108 const auto& pname = prop.name();
109 int level =
110 ( pname == "fatalColorCode" ? MSG::FATAL
111 : pname == "errorColorCode" ? MSG::ERROR
112 : pname == "warningColorCode" ? MSG::WARNING
113 : pname == "infoColorCode" ? MSG::INFO
114 : pname == "debugColorCode" ? MSG::DEBUG
115 : pname == "verboseColorCode" ? MSG::VERBOSE
116 : pname == "alwaysColorCode"
118 : ( throw GaudiException( "ERROR: Unknown message color parameter: " + pname, name(), StatusCode::FAILURE ),
119 -1 ) );
120
121 auto& code = m_logColorCodes[level];
122
123 const auto& col_desc = m_logColors[level].value();
124
125 if ( col_desc.size() == 1 ) {
126 const std::string& desc = col_desc[0];
127 if ( desc.empty() ) {
128 code = "";
129 } else if ( desc[0] == '[' ) {
130 code = "\033" + desc;
131 } else {
132 code = "\033[" + colTrans( desc, 90 ) + ";1m";
133 }
134 } else if ( col_desc.size() == 2 ) {
135 code = "\033[" + colTrans( col_desc[0], 90 ) + ";" + colTrans( col_desc[1], 100 ) + ";1m";
136 } else { // empty desc: no color
137 code = "";
138 }
139}
const std::string name() const
property name
constexpr static const auto FAILURE
Definition StatusCode.h:100
@ DEBUG
Definition IMessageSvc.h:22
@ ALWAYS
Definition IMessageSvc.h:22
@ INFO
Definition IMessageSvc.h:22
@ VERBOSE
Definition IMessageSvc.h:22

◆ setupInactCount()

void MessageSvc::setupInactCount ( Gaudi::Details::PropertyBase & prop)
private

Definition at line 190 of file MessageSvc.cpp.

190 {
191 if ( prop.name() == "countInactive" ) {
192 Gaudi::Property<bool>* p = dynamic_cast<Gaudi::Property<bool>*>( &prop );
193 if ( p ) MsgStream::enableCountInactive( p->value() );
194 }
195}
const ValueType & value() const
Definition Property.h:229

◆ setupLimits()

void MessageSvc::setupLimits ( Gaudi::Details::PropertyBase & prop)
private

Definition at line 141 of file MessageSvc.cpp.

141 {
142 // Just report problems in the settings of the limits and unknown limit parameters
143 if ( prop.name() == "alwaysLimit" ) {
144 Gaudi::Property<int>* p = dynamic_cast<Gaudi::Property<int>*>( &prop );
145 if ( p && p->value() != 0 ) {
146 std::cout << "MessageSvc ERROR: cannot suppress ALWAYS messages" << std::endl;
147 p->setValue( 0 );
148 }
149 } else if ( prop.name() == "defaultLimit" ) {
150 for ( int i = MSG::VERBOSE; i < MSG::NUM_LEVELS; ++i ) {
151 if ( i != MSG::ALWAYS ) { m_msgLimit[i] = m_msgLimit[MSG::NIL].value(); }
152 }
153 } else if ( prop.name() != "fatalLimit" && prop.name() != "errorLimit" && prop.name() != "warningLimit" &&
154 prop.name() == "infoLimit" && prop.name() == "debugLimit" && prop.name() == "verboseLimit" ) {
155 std::cout << "MessageSvc ERROR: Unknown message limit parameter: " << prop.name() << std::endl;
156 return;
157 }
158}
bool setValue(const ValueType &v)
Definition Property.h:231
@ NIL
Definition IMessageSvc.h:22

◆ setupLogStreams()

void MessageSvc::setupLogStreams ( )
private

Definition at line 470 of file MessageSvc.cpp.

470 {
471 // reset state
472 m_loggedStreams.clear();
473
474 // make the unique set of output filenames
475 std::set<std::string_view> outFileNames;
476 std::transform( m_loggedStreamsName.begin(), m_loggedStreamsName.end(),
477 std::inserter( outFileNames, outFileNames.end() ),
478 []( const auto& p ) -> std::string_view { return p.second; } );
479 // map each unique filename to an ofstream
480 std::map<std::string_view, std::shared_ptr<std::ofstream>> outStreams;
481 std::transform( outFileNames.begin(), outFileNames.end(), std::inserter( outStreams, outStreams.end() ),
482 []( std::string_view fname ) {
483 return std::pair{ fname, std::make_shared<std::ofstream>(
484 std::string{ fname }, std::ios_base::out | std::ios_base::trunc ) };
485 } );
486 // associate the stream to ofstream...
487 for ( auto& iProp : m_loggedStreamsName ) {
488 auto& stream = outStreams.at( iProp.second );
489 if ( stream->good() ) m_loggedStreams.emplace( iProp.first, stream );
490 }
491}
Gaudi::Property< std::map< std::string, std::string, std::less<> > > m_loggedStreamsName
Definition MessageSvc.h:175

◆ setupThreshold()

void MessageSvc::setupThreshold ( Gaudi::Details::PropertyBase & prop)
private

Definition at line 160 of file MessageSvc.cpp.

160 {
161
162 static const std::array<std::pair<const char*, MSG::Level>, 7> tbl{ { { "setFatal", MSG::FATAL },
163 { "setError", MSG::ERROR },
164 { "setWarning", MSG::WARNING },
165 { "setInfo", MSG::INFO },
166 { "setDebug", MSG::DEBUG },
167 { "setVerbose", MSG::VERBOSE },
168 { "setAlways", MSG::ALWAYS } } };
169
170 auto i = std::find_if( std::begin( tbl ), std::end( tbl ),
171 [&]( const std::pair<const char*, MSG::Level>& t ) { return prop.name() == t.first; } );
172 if ( i == std::end( tbl ) ) {
173 std::cerr << "MessageSvc ERROR: Unknown message threshold parameter: " << prop.name() << std::endl;
174 return;
175 }
176 int ic = i->second;
177
178 Gaudi::Property<std::vector<std::string>>* sap = dynamic_cast<Gaudi::Property<std::vector<std::string>>*>( &prop );
179 if ( !sap ) {
180 std::cerr << "could not dcast " << prop.name()
181 << " to a Gaudi::Property<std::vector<std::string>> (which it should be!)" << std::endl;
182 } else {
183 for ( auto& i : sap->value() ) setOutputLevel( i, ic );
184 }
185}
void setOutputLevel(int new_level) override

◆ useColor()

bool MessageSvc::useColor ( ) const
inlineoverride

Definition at line 113 of file MessageSvc.h.

113{ return m_color; }

Member Data Documentation

◆ m_color

Gaudi::Property<bool> MessageSvc::m_color { this, "useColors", false, "" }
private

Definition at line 146 of file MessageSvc.h.

146{ this, "useColors", false, "" };

◆ m_defaultFormat

Gaudi::Property<std::string> MessageSvc::m_defaultFormat { this, "Format", Message::getDefaultFormat(), "" }
private

Definition at line 132 of file MessageSvc.h.

132{ this, "Format", Message::getDefaultFormat(), "" };
static const std::string getDefaultFormat()
Get the default format string.
Definition Message.h:68

◆ m_defaultMessage

Message MessageSvc::m_defaultMessage
private

Default Message.

Definition at line 179 of file MessageSvc.h.

◆ m_defaultStream

std::ostream* MessageSvc::m_defaultStream = &std::cout
private

Pointer to the output stream.

Definition at line 178 of file MessageSvc.h.

◆ m_defaultTimeFormat

Gaudi::Property<std::string> MessageSvc::m_defaultTimeFormat { this, "timeFormat", Message::getDefaultTimeFormat(), "" }
private

Definition at line 133 of file MessageSvc.h.

133{ this, "timeFormat", Message::getDefaultTimeFormat(), "" };
static const std::string getDefaultTimeFormat()
Get the default time format string.
Definition Message.h:77

◆ m_inactCount

Gaudi::Property<bool> MessageSvc::m_inactCount { this, "countInactive", false, &MessageSvc::setupInactCount, "" }
private

Definition at line 167 of file MessageSvc.h.

167{ this, "countInactive", false, &MessageSvc::setupInactCount, "" };
void setupInactCount(Gaudi::Details::PropertyBase &prop)

◆ m_inactiveMap

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

Definition at line 194 of file MessageSvc.h.

◆ m_logColorCodes

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

Definition at line 184 of file MessageSvc.h.

◆ m_logColors

std::array<Gaudi::Property<std::vector<std::string> >, MSG::NUM_LEVELS> MessageSvc::m_logColors
private
Initial value:
{ { { },
{ this, "verboseColorCode" },
{ this, "debugColorCode" },
{ this, "infoColorCode" },
{ this, "warningColorCode" },
{ this, "errorColorCode" },
{ this, "fatalColorCode" },
{ this, "alwaysColorCode" } } }

Definition at line 148 of file MessageSvc.h.

148 { { { /*ignored*/ },
149 { this, "verboseColorCode" },
150 { this, "debugColorCode" },
151 { this, "infoColorCode" },
152 { this, "warningColorCode" },
153 { this, "errorColorCode" },
154 { this, "fatalColorCode" },
155 { this, "alwaysColorCode" } } };

◆ m_loggedStreams

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

Definition at line 198 of file MessageSvc.h.

◆ m_loggedStreamsName

Gaudi::Property<std::map<std::string, std::string, std::less<> > > MessageSvc::m_loggedStreamsName
private
Initial value:
{
this, "loggedStreams", {}, "MessageStream sources we want to dump into a logfile" }

Definition at line 175 of file MessageSvc.h.

175 {
176 this, "loggedStreams", {}, "MessageStream sources we want to dump into a logfile" };

◆ m_messageMap

MessageMap MessageSvc::m_messageMap
private

Message map.

Definition at line 181 of file MessageSvc.h.

◆ m_messageMapMutex

std::recursive_mutex MessageSvc::m_messageMapMutex
mutableprivate

Mutex to synchronize multiple access to m_messageMap.

Definition at line 211 of file MessageSvc.h.

◆ m_msgCount

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

Definition at line 196 of file MessageSvc.h.

◆ m_msgLimit

std::array<Gaudi::Property<int>, MSG::NUM_LEVELS> MessageSvc::m_msgLimit
private
Initial value:
{ { { this, "defaultLimit", 500 },
{ this, "verboseLimit", 500 },
{ this, "debugLimit", 500 },
{ this, "infoLimit", 500 },
{ this, "warningLimit", 500 },
{ this, "errorLimit", 500 },
{ this, "fatalLimit", 500 },
{ this, "alwaysLimit", 0 } } }

Definition at line 157 of file MessageSvc.h.

157 { { { this, "defaultLimit", 500 },
158 { this, "verboseLimit", 500 },
159 { this, "debugLimit", 500 },
160 { this, "infoLimit", 500 },
161 { this, "warningLimit", 500 },
162 { this, "errorLimit", 500 },
163 { this, "fatalLimit", 500 },
164 { this, "alwaysLimit", 0 } } };

◆ m_reportMutex

std::recursive_mutex MessageSvc::m_reportMutex
mutableprivate

Mutex to synchronize multiple threads printing.

Definition at line 208 of file MessageSvc.h.

◆ m_sourceMap

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

Definition at line 194 of file MessageSvc.h.

◆ m_statLevel

Gaudi::Property<unsigned int> MessageSvc::m_statLevel { this, "statLevel", 0, "" }
private

Definition at line 135 of file MessageSvc.h.

135{ this, "statLevel", 0, "" };

◆ m_stats

Gaudi::Property<bool> MessageSvc::m_stats { this, "showStats", false, "" }
private

Definition at line 134 of file MessageSvc.h.

134{ this, "showStats", false, "" };

◆ m_streamMap

StreamMap MessageSvc::m_streamMap
private

Stream map.

Definition at line 180 of file MessageSvc.h.

◆ m_suppress

Gaudi::Property<bool> MessageSvc::m_suppress { this, "enableSuppression", false, "" }
private

Definition at line 166 of file MessageSvc.h.

166{ this, "enableSuppression", false, "" };

◆ m_thresholdMap

ThresholdMap MessageSvc::m_thresholdMap
private

Output level threshold map.

Definition at line 182 of file MessageSvc.h.

◆ m_thresholdMapMutex

std::recursive_mutex MessageSvc::m_thresholdMapMutex
mutableprivate

Mutex to synchronize multiple access to m_thresholdMap (.

See also
MsgStream::doOutput).

Definition at line 215 of file MessageSvc.h.

◆ m_thresholdProp

std::array<Gaudi::Property<std::vector<std::string> >, MSG::NUM_LEVELS> MessageSvc::m_thresholdProp
private
Initial value:
{ { { },
{ this, "setVerbose" },
{ this, "setDebug" },
{ this, "setInfo" },
{ this, "setWarning" },
{ this, "setError" },
{ this, "setFatal" },
{ this, "setAlways" } } }

Definition at line 137 of file MessageSvc.h.

137 { { { /*ignored*/ },
138 { this, "setVerbose" },
139 { this, "setDebug" },
140 { this, "setInfo" },
141 { this, "setWarning" },
142 { this, "setError" },
143 { this, "setFatal" },
144 { this, "setAlways" } } };

◆ m_tracedInactiveSources

Gaudi::Property<std::vector<std::string> > MessageSvc::m_tracedInactiveSources
private
Initial value:
{
this,
"tracedInactiveSources",
{},
"for each message source specified, print a stack trace for the unprotected and unseen messages" }

Definition at line 169 of file MessageSvc.h.

169 {
170 this,
171 "tracedInactiveSources",
172 {},
173 "for each message source specified, print a stack trace for the unprotected and unseen messages" };

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