ATLAS Offline Software
Loading...
Searching...
No Matches
LoggedMessageSvc Class Reference

#include <LoggedMessageSvc.h>

Inheritance diagram for LoggedMessageSvc:

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, NamedStream > StreamMap
typedef std::multimap< StatusCode, Message > MessageMap
typedef std::map< std::string, int, std::less<> > ThresholdMap

Public Member Functions

 LoggedMessageSvc (const std::string &name, ISvcLocator *svcloc)
virtual ~LoggedMessageSvc ()
virtual StatusCode reinitialize () override
 Reinitialize Service.
virtual StatusCode initialize () override
 Initialize Service.
virtual StatusCode finalize () override
 Finalize Service.
virtual void reportMessage (const Message &message) override
virtual void reportMessage (const Message &msg, int outputLevel) override
virtual void reportMessage (const StatusCode &code, std::string_view source="") override
virtual void reportMessage (std::string source, int type, std::string message) override
virtual void insertMessage (const StatusCode &code, Message message) override
virtual void eraseMessage () override
virtual void eraseMessage (const StatusCode &code) override
virtual void eraseMessage (const StatusCode &code, const Message &message) override
virtual void insertStream (int message_type, std::string name, std::ostream *stream) override
virtual void eraseStream () override
virtual void eraseStream (int message_type) override
virtual void eraseStream (int message_type, std::ostream *stream) override
virtual void eraseStream (std::ostream *stream) override
virtual std::ostream *defaultStream ATLAS_NOT_CONST_THREAD_SAFE () const override
virtual void setDefaultStream (std::ostream *stream) override
virtual int outputLevel () const override
virtual int outputLevel (std::string_view source) const override
virtual void setOutputLevel (int new_level) override
virtual void setOutputLevel (std::string_view source, int new_level) override
virtual bool useColor () const override
virtual std::string getLogColor (int logLevel) const override
virtual int messageCount (MSG::Level logLevel) const override
virtual void incrInactiveCount (MSG::Level level, std::string_view src) override
virtual std::vector< std::pair< std::string, std::string > > getMessages (MSG::Level level) const override
virtual std::vector< LoggedMessage > getKeyMessages () const override

Private Types

typedef std::map< std::string, MSG::Color > ColorMap
typedef std::map< std::string, std::ostream * > LoggedStreamsMap_t

Private Member Functions

std::string colTrans (const std::string &, int)
void initColors (Gaudi::Details::PropertyBase &prop)
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 ()
void tee (const std::string &sourceName, const std::string &logFileName, const std::set< std::string > &declaredOutFileNames)

Private Attributes

std::ostream * m_defaultStream
 Pointer to the output stream.
Message m_defaultMessage
 Default Message.
StreamMap m_streamMap
 Stream map.
MessageMap m_messageMap
 Message map.
ThresholdMap m_thresholdMap
 Output level threshold map.
std::string m_defaultFormat
 Default format for the messages.
std::string m_defaultTimeFormat
 Default format for timestamps in the messages.
StringArrayProperty m_thresholdProp [MSG::NUM_LEVELS]
 Properties controling.
BooleanProperty m_color
BooleanProperty m_stats
UnsignedIntegerProperty m_statLevel
StringArrayProperty m_logColors [MSG::NUM_LEVELS]
IntegerProperty m_msgLimit [MSG::NUM_LEVELS]
IntegerProperty m_logLevel
StringArrayProperty m_keywords
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
BooleanProperty m_suppress
BooleanProperty m_inactCount
ColorMap m_colMap
int m_msgCount [MSG::NUM_LEVELS]
std::map< std::string, std::string > m_loggedStreamsName
LoggedStreamsMap_t m_loggedStreams
std::mutex m_reportMutex
 Mutex to synchronize multiple threads printing.
std::recursive_mutex m_messageMapMutex
 Mutex to synchronize multiple access to m_messageMap.
std::mutex m_thresholdMapMutex
 Mutex to synchronize multiple access to m_thresholdMap (.
std::vector< std::pair< std::string, std::string > > m_msgLog [MSG::NUM_LEVELS]
std::vector< LoggedMessage > m_msgKeyLog
bool m_keysUsed

Detailed Description

Definition at line 37 of file LoggedMessageSvc.h.

Member Typedef Documentation

◆ ColorMap

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

Definition at line 169 of file LoggedMessageSvc.h.

◆ LoggedStreamsMap_t

typedef std::map<std::string, std::ostream*> LoggedMessageSvc::LoggedStreamsMap_t
private

Definition at line 175 of file LoggedMessageSvc.h.

◆ MessageMap

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

Definition at line 43 of file LoggedMessageSvc.h.

◆ NamedStream

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

Definition at line 41 of file LoggedMessageSvc.h.

◆ StreamMap

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

Definition at line 42 of file LoggedMessageSvc.h.

◆ ThresholdMap

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

Definition at line 44 of file LoggedMessageSvc.h.

Constructor & Destructor Documentation

◆ LoggedMessageSvc()

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

Definition at line 23 of file LoggedMessageSvc.cxx.

24 : base_class( name, svcloc ), m_keysUsed(false)
25 {
26 m_defaultStream = &std::cout;
27 m_outputLevel = MSG::INFO;
28 declareProperty( "Format", m_defaultFormat = Message::getDefaultFormat() );
29 declareProperty( "timeFormat", m_defaultTimeFormat = Message::getDefaultTimeFormat() );
30 declareProperty( "showStats", m_stats = false );
31 declareProperty( "statLevel", m_statLevel = 0 );
32
33 // Special properties to control output level of individual sources
34 declareProperty( "setVerbose", m_thresholdProp[MSG::VERBOSE] );
35 declareProperty( "setDebug", m_thresholdProp[MSG::DEBUG] );
36 declareProperty( "setInfo", m_thresholdProp[MSG::INFO] );
37 declareProperty( "setWarning", m_thresholdProp[MSG::WARNING] );
38 declareProperty( "setError", m_thresholdProp[MSG::ERROR] );
39 declareProperty( "setFatal", m_thresholdProp[MSG::FATAL] );
40 declareProperty( "setAlways", m_thresholdProp[MSG::ALWAYS] );
41
42 declareProperty( "useColors", m_color=false);
43 m_color.declareUpdateHandler(&LoggedMessageSvc::initColors, this);
44
45 declareProperty( "fatalColorCode", m_logColors[MSG::FATAL] );
46 declareProperty( "errorColorCode", m_logColors[MSG::ERROR] );
47 declareProperty( "warningColorCode", m_logColors[MSG::WARNING] );
48 declareProperty( "infoColorCode", m_logColors[MSG::INFO] );
49 declareProperty( "debugColorCode", m_logColors[MSG::DEBUG] );
50 declareProperty( "verboseColorCode", m_logColors[MSG::VERBOSE] );
51 declareProperty( "alwaysColorCode", m_logColors[MSG::ALWAYS] );
52
53 const int defaultLimit = 500;
54 declareProperty( "fatalLimit", m_msgLimit[MSG::FATAL] = defaultLimit );
55 declareProperty( "errorLimit", m_msgLimit[MSG::ERROR] = defaultLimit );
56 declareProperty( "warningLimit", m_msgLimit[MSG::WARNING] = defaultLimit );
57 declareProperty( "infoLimit", m_msgLimit[MSG::INFO] = defaultLimit );
58 declareProperty( "debugLimit", m_msgLimit[MSG::DEBUG] = defaultLimit );
59 declareProperty( "verboseLimit", m_msgLimit[MSG::VERBOSE] = defaultLimit );
60 declareProperty( "alwaysLimit", m_msgLimit[MSG::ALWAYS] = 0 );
61
62 declareProperty( "defaultLimit", m_msgLimit[MSG::NIL] = defaultLimit );
63
64 declareProperty( "enableSuppression", m_suppress = false );
65 declareProperty( "countInactive", m_inactCount = false )->declareUpdateHandler( &LoggedMessageSvc::setupInactCount, this );
66#ifndef NDEBUG
67 // initialize the MsgStream static flag.
68 MsgStream::enableCountInactive(m_inactCount);
69#endif
70
71 declareProperty( "loggingLevel", m_logLevel = MSG::FATAL, "Message level above which all messages are saved" );
72 m_logLevel.declareUpdateHandler(&LoggedMessageSvc::setupThreshold, this);
73
74 declareProperty( "keywords", m_keywords, "keywords to scan messages for and save");
75 m_keywords.declareUpdateHandler(&LoggedMessageSvc::setupThreshold, this);
76
77 declareProperty( "loggedStreams",
79 "MessageStream sources we want to dump into a logfile" );
80
81 for (int ic=0; ic<MSG::NUM_LEVELS; ++ic) {
82 m_logColors[ic].declareUpdateHandler(&LoggedMessageSvc::setupColors, this);
83 m_msgLimit[ic].declareUpdateHandler(&LoggedMessageSvc::setupLimits, this);
84 m_thresholdProp[ic].declareUpdateHandler(&LoggedMessageSvc::setupThreshold, this);
85 }
86
87 for (int i=0; i<MSG::NUM_LEVELS; ++i) {
88 m_msgCount[i] = 0;
89 }
90
91}
void initColors(Gaudi::Details::PropertyBase &prop)
void setupLimits(Gaudi::Details::PropertyBase &prop)
void setupColors(Gaudi::Details::PropertyBase &prop)
UnsignedIntegerProperty m_statLevel
BooleanProperty m_color
IntegerProperty m_msgLimit[MSG::NUM_LEVELS]
BooleanProperty m_inactCount
int m_msgCount[MSG::NUM_LEVELS]
StringArrayProperty m_thresholdProp[MSG::NUM_LEVELS]
Properties controling.
std::string m_defaultTimeFormat
Default format for timestamps in the messages.
StringArrayProperty m_logColors[MSG::NUM_LEVELS]
std::ostream * m_defaultStream
Pointer to the output stream.
std::map< std::string, std::string > m_loggedStreamsName
IntegerProperty m_logLevel
void setupThreshold(Gaudi::Details::PropertyBase &prop)
void setupInactCount(Gaudi::Details::PropertyBase &prop)
BooleanProperty m_stats
std::string m_defaultFormat
Default format for the messages.
StringArrayProperty m_keywords
BooleanProperty m_suppress
int ic
Definition grepfile.py:33

◆ ~LoggedMessageSvc()

LoggedMessageSvc::~LoggedMessageSvc ( )
virtual

Definition at line 95 of file LoggedMessageSvc.cxx.

96{
97 // closing log-files, if any
98 LoggedStreamsMap_t::iterator iStream = m_loggedStreams.begin();
99 LoggedStreamsMap_t::iterator endStream = m_loggedStreams.end();
100 for ( ; iStream != endStream; ++iStream ) {
101 delete iStream->second;
102 iStream->second = nullptr;
103 }
104}
LoggedStreamsMap_t m_loggedStreams

Member Function Documentation

◆ ATLAS_NOT_CONST_THREAD_SAFE()

virtual std::ostream *defaultStream LoggedMessageSvc::ATLAS_NOT_CONST_THREAD_SAFE ( ) const
inlineoverridevirtual

Definition at line 98 of file LoggedMessageSvc.h.

98 {
99 std::lock_guard<std::mutex> lock(m_reportMutex);
100 return m_defaultStream;
101 }
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
std::mutex m_reportMutex
Mutex to synchronize multiple threads printing.

◆ colTrans()

std::string LoggedMessageSvc::colTrans ( const std::string & col,
int offset )
private

Definition at line 446 of file LoggedMessageSvc.cxx.

446 {
447 ColorMap::const_iterator itr = m_colMap.find(col);
448 int icol;
449 if (itr != m_colMap.end()) {
450 icol = offset + itr->second;
451 } else {
452 icol = offset + 8;
453 }
454 return std::to_string (icol);
455
456}

◆ eraseMessage() [1/3]

void LoggedMessageSvc::eraseMessage ( )
overridevirtual

Definition at line 726 of file LoggedMessageSvc.cxx.

727{
728 std::lock_guard<std::recursive_mutex> lock(m_messageMapMutex);
729
730 m_messageMap.erase( m_messageMap.begin(), m_messageMap.end() );
731}
MessageMap m_messageMap
Message map.
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.

◆ eraseMessage() [2/3]

void LoggedMessageSvc::eraseMessage ( const StatusCode & code)
overridevirtual

Definition at line 740 of file LoggedMessageSvc.cxx.

741{
742 std::lock_guard<std::recursive_mutex> lock(m_messageMapMutex);
743
744 m_messageMap.erase( key );
745}

◆ eraseMessage() [3/3]

void LoggedMessageSvc::eraseMessage ( const StatusCode & code,
const Message & message )
overridevirtual

Definition at line 754 of file LoggedMessageSvc.cxx.

755{
756 std::lock_guard<std::recursive_mutex> lock(m_messageMapMutex);
757
758 bool changed = true;
759 while( changed ) {
760 changed = false;
761 MessageMap::iterator first = m_messageMap.lower_bound( key );
762 MessageMap::iterator last = m_messageMap.upper_bound( key );
763 while( first != last ) {
764 const Message& message = (*first).second;
765 if ( message == msg ) {
766 m_messageMap.erase( first );
767 changed = true;
768 break;
769 }
770 }
771 }
772}
bool first
Definition DeMoScan.py:534
MsgStream & msg
Definition testRead.cxx:32

◆ eraseStream() [1/4]

void LoggedMessageSvc::eraseStream ( )
overridevirtual

Definition at line 638 of file LoggedMessageSvc.cxx.

639{
640 m_streamMap.erase( m_streamMap.begin(), m_streamMap.end() );
641}
StreamMap m_streamMap
Stream map.

◆ eraseStream() [2/4]

void LoggedMessageSvc::eraseStream ( int message_type)
overridevirtual

Definition at line 650 of file LoggedMessageSvc.cxx.

651{
652 m_streamMap.erase( message_type );
653}

◆ eraseStream() [3/4]

void LoggedMessageSvc::eraseStream ( int message_type,
std::ostream * stream )
overridevirtual

Definition at line 662 of file LoggedMessageSvc.cxx.

662 {
663 if ( nullptr != stream ) {
664 bool changed = true;
665 while( changed ) {
666 changed = false;
667 StreamMap::iterator first = m_streamMap.lower_bound( key );
668 StreamMap::iterator last = m_streamMap.upper_bound( key );
669 while( first != last ) {
670 if ( (*first).second.second == stream ) {
671 m_streamMap.erase( first );
672 changed = true;
673 break;
674 }
675 }
676 }
677 }
678}

◆ eraseStream() [4/4]

void LoggedMessageSvc::eraseStream ( std::ostream * stream)
overridevirtual

Definition at line 687 of file LoggedMessageSvc.cxx.

687 {
688 if ( nullptr != stream ) {
689 bool changed = true;
690 while( changed ) {
691 changed = false;
692 StreamMap::iterator first = m_streamMap.begin();
693 while( first != m_streamMap.end() ) {
694 if ( (*first).second.second == stream ) {
695 m_streamMap.erase( first );
696 changed = true;
697 break;
698 }
699 }
700 }
701 }
702}

◆ finalize()

StatusCode LoggedMessageSvc::finalize ( )
overridevirtual

Finalize Service.

Definition at line 347 of file LoggedMessageSvc.cxx.

347 {
348
349 m_suppress = false;
350
351#define PR(FMT, ...) std::println(os, FMT __VA_OPT__(,) __VA_ARGS__)
352
353 {
354 std::ostringstream os;
355
356 if (m_stats) {
357 PR ("Summarizing all message counts");
358 } else {
359 PR ("Listing sources of suppressed message: ");
360 }
361
362 PR ("=====================================================");
363 PR (" Message Source | Level | Count");
364 PR ("-----------------------------+---------+-------------");
365
366
367 bool found(false);
368
369 std::lock_guard<std::mutex> lock(m_reportMutex);
370 std::map<std::string,MsgAry>::const_iterator itr;
371 for (itr=m_sourceMap.begin(); itr!=m_sourceMap.end(); ++itr) {
372 for (unsigned int ic = 0; ic < MSG::NUM_LEVELS; ++ic) {
373 if ( (itr->second.msg[ic] >= m_msgLimit[ic] && m_msgLimit[ic] != 0 ) ||
374 (m_stats && itr->second.msg[ic] > 0 && ic >= m_statLevel.value()) ) {
375 PR (" {:<28}|{:>8}|{:>9}",
376 itr->first, levelNames[ic], itr->second.msg[ic]);
377
378 found = true;
379 }
380 }
381 }
382 PR ("=====================================================");
383
384 if (found || m_stats) {
385 cout << os.str();
386 }
387 }
388
389
390#ifndef NDEBUG
391 if (m_inactCount.value()) {
392
393 std::ostringstream os;
394 PR ("Listing sources of Unprotected and Unseen messages");
395
396 bool found(false);
397
398 unsigned int ml(0);
399 std::map<std::string,MsgAry>::const_iterator itr;
400 for (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 if (itr->first.length() > ml) { ml = itr->first.length(); }
404 }
405 }
406 }
407
408 for (unsigned int i=0; i<ml+25; ++i) {
409 os << "=";
410 }
411
412 PR("");
413 PR(" {:<{}}| Level | Count", "MessageSource", ml+2);
414
415 for (unsigned int i=0; i<ml+3; ++i) {
416 os << "-";
417 }
418 PR ("+---------+-----------");
419
420
421 for (itr=m_inactiveMap.begin(); itr!=m_inactiveMap.end(); ++itr) {
422 for (unsigned int ic = 0; ic < MSG::NUM_LEVELS; ++ic) {
423 if (itr->second.msg[ic] != 0) {
424 PR (" {:<{}}|{:>8}|{:>9}",
425 itr->first, ml+2, levelNames[ic], itr->second.msg[ic]);
426 found = true;
427 }
428 }
429 }
430 for (unsigned int i=0; i<ml+25; ++i) {
431 os << "=";
432 }
433 PR("");
434
435 if (found) {
436 cout << os.str();
437 }
438 }
439#endif
440#undef PR
441
442 return StatusCode::SUCCESS;
443}
static constexpr std::string levelNames[MSG::NUM_LEVELS]
#define PR(FMT,...)
std::map< std::string, MsgAry, std::less<> > m_sourceMap
std::map< std::string, MsgAry, std::less<> > m_inactiveMap

◆ getKeyMessages()

auto LoggedMessageSvc::getKeyMessages ( ) const
overridevirtual

Definition at line 929 of file LoggedMessageSvc.cxx.

931{
932 std::lock_guard<std::mutex> lock(m_reportMutex);
933 return m_msgKeyLog;
934}
std::vector< LoggedMessage > m_msgKeyLog

◆ getLogColor()

std::string LoggedMessageSvc::getLogColor ( int logLevel) const
overridevirtual

Definition at line 810 of file LoggedMessageSvc.cxx.

810 {
811// ---------------------------------------------------------------------------
812 if (logLevel < MSG::NUM_LEVELS) {
814 } else {
815 return "";
816 }
817}
std::string m_logColorCodes[MSG::NUM_LEVELS]

◆ getMessages()

std::vector< std::pair< std::string, std::string > > LoggedMessageSvc::getMessages ( MSG::Level level) const
overridevirtual

Definition at line 922 of file LoggedMessageSvc.cxx.

923{
924 std::lock_guard<std::mutex> lock(m_reportMutex);
925 return m_msgLog[ level ];
926}
std::vector< std::pair< std::string, std::string > > m_msgLog[MSG::NUM_LEVELS]

◆ incrInactiveCount()

void LoggedMessageSvc::incrInactiveCount ( MSG::Level level,
std::string_view src )
overridevirtual

Definition at line 828 of file LoggedMessageSvc.cxx.

828 {
829
830 auto entry = m_inactiveMap.find( source );
831 if ( entry == m_inactiveMap.end() ) {
832 entry = m_inactiveMap.emplace( source, MsgAry{} ).first;
833 }
834 ++entry->second.msg[level];
835}
Private helper class to keep the count of messages of a type (MSG::LEVEL).

◆ initColors()

void LoggedMessageSvc::initColors ( Gaudi::Details::PropertyBase & prop)
private

Definition at line 151 of file LoggedMessageSvc.cxx.

151 {
152
153 if (m_color == true) {
154
155 if (m_logColors[MSG::FATAL].value().size() == 0) {
156 vector<string> fatDef;
157 fatDef.push_back( "[94;101;1m" );
158 m_logColors[MSG::FATAL].set( fatDef );
159 } else {
161 }
162
163 if (m_logColors[MSG::ERROR].value().size() == 0) {
164 vector<string> errDef;
165 errDef.push_back( "[97;101;1m" );
166 m_logColors[MSG::ERROR].set( errDef );
167 } else {
169 }
170
171 if (m_logColors[MSG::WARNING].value().size() == 0) {
172 vector<string> warDef;
173 warDef.push_back( "[93;1m" );
174 m_logColors[MSG::WARNING].set( warDef );
175 } else {
177 }
178
179 } else {
180
181 // reset all color codes;
182 for (int ic=0; ic<MSG::NUM_LEVELS; ++ic) {
183 vector<string> def;
184 m_logColors[ic].set( def );
185 }
186
187 }
188
189}
size_t size() const
Number of registered mappings.

◆ initialize()

StatusCode LoggedMessageSvc::initialize ( )
overridevirtual

Initialize Service.

Definition at line 109 of file LoggedMessageSvc.cxx.

109 {
111 sc = base_class::initialize();
112 if( sc.isFailure() ) return sc;
113 // hack since in Gaudi v30, msgSvc() now returns a const SmartIF<IMessageSvc>
114 // Release pointer to myself done in Service base class
115 SmartIF<IMessageSvc> &si ATLAS_THREAD_SAFE = const_cast<SmartIF<IMessageSvc>&> (msgSvc());
116 si.reset();
117
118#ifdef _WIN32
119 m_color = false;
120#endif
121
122 m_colMap["black"] = MSG::BLACK;
123 m_colMap["red"] = MSG::RED;
124 m_colMap["green"] = MSG::GREEN;
125 m_colMap["yellow"] = MSG::YELLOW;
126 m_colMap["blue"] = MSG::BLUE;
127 m_colMap["purple"] = MSG::PURPLE;
128 m_colMap["cyan"] = MSG::CYAN;
129 m_colMap["white"] = MSG::WHITE;
130
131 // make sure the map of logged stream names is initialized
133
134 if (m_keywords.value().size() > 0) {
135 m_keysUsed = true;
136 }
137
138 return StatusCode::SUCCESS;
139}
static Double_t sc
#define ATLAS_THREAD_SAFE
::StatusCode StatusCode
StatusCode definition for legacy code.

◆ insertMessage()

void LoggedMessageSvc::insertMessage ( const StatusCode & code,
Message message )
overridevirtual

Definition at line 712 of file LoggedMessageSvc.cxx.

713{
714 std::lock_guard<std::recursive_mutex> lock(m_messageMapMutex);
715
716 m_messageMap.emplace( key, std::move( msg ) );
717}

◆ insertStream()

void LoggedMessageSvc::insertStream ( int message_type,
std::string name,
std::ostream * stream )
overridevirtual

Definition at line 623 of file LoggedMessageSvc.cxx.

626{
627 typedef StreamMap::value_type value_type;
628 m_streamMap.insert( value_type( key, NamedStream( std::move(name), stream) ) );
629}
std::pair< std::string, std::ostream * > NamedStream

◆ messageCount()

int LoggedMessageSvc::messageCount ( MSG::Level logLevel) const
overridevirtual

Definition at line 820 of file LoggedMessageSvc.cxx.

820 {
821
822 return m_msgCount[level];
823
824}

◆ outputLevel() [1/2]

int LoggedMessageSvc::outputLevel ( ) const
overridevirtual

Definition at line 775 of file LoggedMessageSvc.cxx.

775 {
776// ---------------------------------------------------------------------------
777 return m_outputLevel;
778}

◆ outputLevel() [2/2]

int LoggedMessageSvc::outputLevel ( std::string_view source) const
overridevirtual

Definition at line 780 of file LoggedMessageSvc.cxx.

780 {
781// ---------------------------------------------------------------------------
782 std::lock_guard<std::mutex> lock(m_thresholdMapMutex);
783
784 auto it = m_thresholdMap.find( source );
785 return it != m_thresholdMap.end() ? it->second : m_outputLevel.value();
786}
ThresholdMap m_thresholdMap
Output level threshold map.
std::mutex m_thresholdMapMutex
Mutex to synchronize multiple access to m_thresholdMap (.

◆ reinitialize()

StatusCode LoggedMessageSvc::reinitialize ( )
overridevirtual

Reinitialize Service.

Definition at line 144 of file LoggedMessageSvc.cxx.

144 {
145 m_state = Gaudi::StateMachine::OFFLINE;
146 return initialize();
147}
virtual StatusCode initialize() override
Initialize Service.

◆ reportMessage() [1/4]

void LoggedMessageSvc::reportMessage ( const Message & message)
overridevirtual

Definition at line 562 of file LoggedMessageSvc.cxx.

562 {
563 reportMessage(msg, outputLevel(msg.getSource()));
564}
virtual void reportMessage(const Message &message) override
virtual int outputLevel() const override

◆ reportMessage() [2/4]

void LoggedMessageSvc::reportMessage ( const Message & msg,
int outputLevel )
overridevirtual

Definition at line 465 of file LoggedMessageSvc.cxx.

465 {
466 std::lock_guard<std::mutex> lock(m_reportMutex);
467
468 int key = msg.getType();
469 int nmsg;
470
471 m_msgCount[key] ++;
472
473 if (outputLevel >= m_logLevel) {
474 m_msgLog[ outputLevel ].push_back( make_pair (msg.getSource(), msg.getMessage() ) );
475 }
476
477 if (m_keysUsed) {
478 if (msg.getSource() != "AthenaSummarySvc") {
479 for (vector<string>::const_iterator itr=m_keywords.value().begin(); itr!= m_keywords.value().end(); ++itr) {
480 if (msg.getMessage().find( *itr ) != string::npos) {
481 m_msgKeyLog.push_back( LoggedMessage( outputLevel, msg.getSource(), msg.getMessage() ));
482 break;
483 }
484 }
485 }
486 }
487
488 const Message *cmsg = &msg;
489 std::unique_ptr<Message> suppressed_msg;
490
491 // processing logged streams
492 if ( !m_loggedStreams.empty() ) {
493 const LoggedStreamsMap_t::iterator iLog = m_loggedStreams.find( msg.getSource() );
494 if ( m_loggedStreams.end() != iLog ) {
495 (*iLog->second) << *cmsg << std::endl;
496 }
497 }
498
499 if ( m_suppress.value() || m_stats.value() ) {
500
501 std::map<std::string,MsgAry>::iterator itr =
502 m_sourceMap.find(msg.getSource());
503 if (itr != m_sourceMap.end()) {
504 itr->second.msg[key] += 1;
505 nmsg = itr->second.msg[key];
506 } else {
507 MsgAry A;
508 for (int i=0; i<MSG::NUM_LEVELS; ++i) {
509 A.msg[i] = 0;
510 }
511 A.msg[key] = 1;
512 m_sourceMap[msg.getSource()] = A;
513 nmsg = 1;
514 }
515
516 if (m_suppress.value()) {
517
518 if ( m_msgLimit[key] != 0 ) {
519 if (nmsg == m_msgLimit[key]) {
520 std::string str = levelNames[key] + " message limit (";
521 str += std::to_string( m_msgLimit[key].value() );
522 str += ") reached for ";
523 str += msg.getSource() + ". Suppressing further output.";
524 suppressed_msg = std::make_unique<Message>(msg.getSource(),MSG::WARNING,str);
525 suppressed_msg->setFormat(msg.getFormat());
526 cmsg = suppressed_msg.get();
527 } else if (nmsg > m_msgLimit[key]) {
528 return;
529 }
530 }
531 }
532
533 }
534
535 StreamMap::const_iterator first = m_streamMap.lower_bound( key );
536 if ( first != m_streamMap.end() ) {
537 StreamMap::const_iterator last = m_streamMap.upper_bound( key );
538 while( first != last ) {
539 std::ostream& stream = *( (*first).second.second );
540 stream << *cmsg << std::endl;
541 ++first;
542 }
543 }
544 else if ( key >= outputLevel ) {
545 msg.setFormat(m_defaultFormat);
546 msg.setTimeFormat(m_defaultTimeFormat);
547 if (!m_color) {
548 (*m_defaultStream) << *cmsg << std::endl << std::flush;
549 } else {
550 (*m_defaultStream) << m_logColorCodes[key] << *cmsg << "\033[m"
551 << std::endl << std::flush;
552 }
553 }
554}

◆ reportMessage() [3/4]

void LoggedMessageSvc::reportMessage ( const StatusCode & code,
std::string_view source = "" )
overridevirtual

Definition at line 586 of file LoggedMessageSvc.cxx.

588{
589 std::lock_guard<std::recursive_mutex> lock(m_messageMapMutex);
590
591 MessageMap::const_iterator first = m_messageMap.lower_bound( key );
592 if ( first != m_messageMap.end() ) {
593 MessageMap::const_iterator last = m_messageMap.upper_bound( key );
594 while( first != last ) {
595 Message msg = (*first).second;
596 msg.setSource( source );
597 std::ostringstream os1;
598 os1 << "Status Code " << key.getCode() << std::ends;
599 Message stat_code1( std::string{source}, msg.getType(), os1.str() );
600 reportMessage( stat_code1 );
602 ++first;
603 }
604 }
605 else {
606 Message mesg = m_defaultMessage;
607 mesg.setSource( source );
608 std::ostringstream os2;
609 os2 << "Status Code " << key.getCode() << std::ends;
610 Message stat_code2( std::string{source}, mesg.getType(), os2.str() );
611 reportMessage( stat_code2 );
612 reportMessage( mesg );
613 }
614}
Message m_defaultMessage
Default Message.

◆ reportMessage() [4/4]

void LoggedMessageSvc::reportMessage ( std::string source,
int type,
std::string message )
overridevirtual

Definition at line 572 of file LoggedMessageSvc.cxx.

574 {
575 Message msg( std::move(source), type, std::move(message));
577}

◆ setDefaultStream()

virtual void LoggedMessageSvc::setDefaultStream ( std::ostream * stream)
inlineoverridevirtual

Definition at line 104 of file LoggedMessageSvc.h.

104 {
105 std::lock_guard<std::mutex> lock(m_reportMutex);
107 }

◆ setOutputLevel() [1/2]

void LoggedMessageSvc::setOutputLevel ( int new_level)
overridevirtual

Definition at line 789 of file LoggedMessageSvc.cxx.

789 {
790// ---------------------------------------------------------------------------
791 m_outputLevel = new_level;
792}

◆ setOutputLevel() [2/2]

void LoggedMessageSvc::setOutputLevel ( std::string_view source,
int new_level )
overridevirtual

Definition at line 795 of file LoggedMessageSvc.cxx.

795 {
796// ---------------------------------------------------------------------------
797 std::lock_guard<std::mutex> lock(m_thresholdMapMutex);
798
799 // only write if we really have to...
800 auto i = m_thresholdMap.find( source );
801 if ( i == m_thresholdMap.end() ) {
802 m_thresholdMap.emplace( source, level );
803 } else if ( i->second != level ) {
804 i->second = level;
805 }
806
807}

◆ setupColors()

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

Definition at line 193 of file LoggedMessageSvc.cxx.

193 {
194
195 if (! m_color) return;
196
197 int ic;
198 if (prop.name() == "fatalColorCode") {
199 ic = MSG::FATAL;
200 } else if (prop.name() == "errorColorCode") {
201 ic = MSG::ERROR;
202 } else if (prop.name() == "warningColorCode") {
203 ic = MSG::WARNING;
204 } else if (prop.name() == "infoColorCode") {
205 ic = MSG::INFO;
206 } else if (prop.name() == "debugColorCode") {
207 ic = MSG::DEBUG;
208 } else if (prop.name() == "verboseColorCode") {
209 ic = MSG::VERBOSE;
210 } else if (prop.name() == "alwaysColorCode") {
211 ic = MSG::ALWAYS;
212 } else {
213 std::println ("ERROR: Unknown message color parameter: {}", prop.name());
214 return;
215 }
216
217 string code;
218 vector<string>::const_iterator itr;
219 itr = m_logColors[ic].value().begin();
220
221 if ( m_logColors[ic].value().size() == 1 ) {
222
223 if (itr->empty() ) {
224 code = "";
225 } else if ((*itr)[0] == '[') {
226 code = "\033" + *itr;
227 } else {
228 code = "\033[" + colTrans(*itr, 90) + ";1m";
229 }
230
231 } else if (m_logColors[ic].value().size() == 2) {
232 vector<string>::const_iterator itr2 = itr + 1;
233
234 code = "\033[" + colTrans(*itr, 90) + ";"
235 + colTrans(*itr2, 100) + ";1m";
236
237 }
238
239 m_logColorCodes[ic] = std::move(code);
240
241}
std::string colTrans(const std::string &, int)

◆ setupInactCount()

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

Definition at line 335 of file LoggedMessageSvc.cxx.

335 {
336 if (prop.name() == "countInactive") {
337#ifndef NDEBUG
338 BooleanProperty *p = dynamic_cast<BooleanProperty*>(&prop);
339 if (p)
340 MsgStream::enableCountInactive(p->value());
341#endif
342 }
343}

◆ setupLimits()

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

Definition at line 244 of file LoggedMessageSvc.cxx.

244 {
245
246 //int ic = 0;
247 if (prop.name() == "fatalLimit") {
248 //ic = MSG::FATAL;
249 } else if (prop.name() == "errorLimit") {
250 //ic = MSG::ERROR;
251 } else if (prop.name() == "warningLimit") {
252 //ic = MSG::WARNING;
253 } else if (prop.name() == "infoLimit") {
254 //ic = MSG::INFO;
255 } else if (prop.name() == "debugLimit") {
256 //ic = MSG::DEBUG;
257 } else if (prop.name() == "verboseLimit") {
258 //ic = MSG::VERBOSE;
259 } else if (prop.name() == "alwaysLimit") {
260 IntegerProperty *p = dynamic_cast<IntegerProperty*>(&prop);
261 if (p && p->value() != 0) {
262 std::println ("LoggedMessageSvc ERROR: cannot suppress ALWAYS messages");
263 p->setValue(0);
264 }
265 //ic = MSG::ALWAYS;
266 } else if (prop.name() == "defaultLimit") {
267 for (int i = MSG::VERBOSE; i< MSG::NUM_LEVELS; ++i) {
268 if (i != MSG::ALWAYS) {
269 m_msgLimit[i] = m_msgLimit[MSG::NIL].value();
270 }
271 }
272 } else {
273 std::println ("LoggedMessageSvc ERROR: Unknown message limit parameter: {}",
274 prop.name());
275 return;
276 }
277
278}

◆ setupLogStreams()

void LoggedMessageSvc::setupLogStreams ( )
private

Definition at line 838 of file LoggedMessageSvc.cxx.

839{
840 // reset state
841 for ( LoggedStreamsMap_t::iterator iLog = m_loggedStreams.begin();
842 iLog != m_loggedStreams.end();
843 ++iLog ) {
844 delete iLog->second;
845 }
846 m_loggedStreams.clear();
847
848 typedef std::map<std::string,std::string> StreamMap_t;
849 const StreamMap_t& streamMap = m_loggedStreamsName;
850 typedef StreamMap_t::const_iterator StreamMapIter;
851
852 for ( StreamMapIter iProp = streamMap.begin(), iEnd = streamMap.end();
853 iProp != iEnd;
854 ++iProp ) {
855
856 const std::string sourceName = iProp->first;
857 const std::string outFileName = iProp->second;
858
859 std::set<std::string> outFileNames;
860 for ( StreamMapIter jProp = streamMap.begin();
861 jProp != iEnd;
862 ++jProp ) {
863 if ( jProp->first != iProp->first ) {
864 outFileNames.insert( jProp->second );
865 }
866 }
867
868 tee( sourceName, outFileName, outFileNames );
869
870 }//> loop over property entries
871
872 return;
873}
void tee(const std::string &sourceName, const std::string &logFileName, const std::set< std::string > &declaredOutFileNames)

◆ setupThreshold()

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

Definition at line 281 of file LoggedMessageSvc.cxx.

281 {
282
283 int ic = 0;
284 if (prop.name() == "setFatal") {
285 ic = MSG::FATAL;
286 } else if (prop.name() == "setError") {
287 ic = MSG::ERROR;
288 } else if (prop.name() == "setWarning") {
289 ic = MSG::WARNING;
290 } else if (prop.name() == "setInfo") {
291 ic = MSG::INFO;
292 } else if (prop.name() == "setDebug") {
293 ic = MSG::DEBUG;
294 } else if (prop.name() == "setVerbose") {
295 ic = MSG::VERBOSE;
296 } else if (prop.name() == "setAlways") {
297 ic = MSG::ALWAYS;
298 } else if (prop.name() == "loggingLevel") {
299 IntegerProperty *iap = dynamic_cast<IntegerProperty*>( &prop );
300 if (iap)
301 m_logLevel = iap->value();
302 return;
303 } else if (prop.name() == "keywords") {
304 StringArrayProperty *sap = dynamic_cast<StringArrayProperty*>( &prop );
305 if (sap!= nullptr && sap->value().size() > 0) {
306 m_keysUsed = true;
307 } else {
308 m_keysUsed = false;
309 }
310 return;
311 } else {
312 std::println (cerr, "LoggedMessageSvc ERROR: Unknown message theshold parameter: {}",
313 prop.name());
314 return;
315 }
316
317 StringArrayProperty *sap = dynamic_cast<StringArrayProperty*>( &prop);
318 if (sap == nullptr) {
319 std::println (std::cerr, "could not dcast {} to a StringArrayProperty (which it should be!)",
320 prop.name());
321 return;
322 } else {
323 std::vector<std::string>::const_iterator itr;
324 for ( itr = sap->value().begin();
325 itr != sap->value().end();
326 ++itr) {
327 setOutputLevel( *itr, ic );
328 }
329 }
330
331}
virtual void setOutputLevel(int new_level) override

◆ tee()

void LoggedMessageSvc::tee ( const std::string & sourceName,
const std::string & logFileName,
const std::set< std::string > & declaredOutFileNames )
private

Definition at line 876 of file LoggedMessageSvc.cxx.

879{
880 const std::ios_base::openmode openMode = std::ios_base::out |
881 std::ios_base::trunc;
882
883 LoggedStreamsMap_t::iterator iEnd = m_loggedStreams.end();
884 LoggedStreamsMap_t::iterator iStream = m_loggedStreams.find( sourceName );
885 if ( iStream != iEnd ) {
886 delete iStream->second;
887 iStream->second = nullptr;
888 m_loggedStreams.erase( iStream );
889 }
890
891 // before creating a new ofstream, make sure there is no already existing
892 // one with the same file name...
893 iEnd = m_loggedStreams.end();
894 for ( iStream = m_loggedStreams.begin(); iStream != iEnd; ++iStream ) {
895 if ( outFileNames.find( outFileName ) != outFileNames.end() ) {
896 m_loggedStreams[sourceName] = m_loggedStreams[iStream->first];
897 return;
898 }
899 }
900
901 std::ofstream * out = new std::ofstream( outFileName.c_str(), openMode );
902
903 if ( !out->good() ) {
904 out->close();
905 delete out;
906 return;
907 }
908
909 m_loggedStreams[sourceName] = out;
910
911 return;
912}

◆ useColor()

virtual bool LoggedMessageSvc::useColor ( ) const
inlineoverridevirtual

Definition at line 122 of file LoggedMessageSvc.h.

122{ return m_color; }

Member Data Documentation

◆ m_colMap

ColorMap LoggedMessageSvc::m_colMap
private

Definition at line 170 of file LoggedMessageSvc.h.

◆ m_color

BooleanProperty LoggedMessageSvc::m_color
private

Definition at line 147 of file LoggedMessageSvc.h.

◆ m_defaultFormat

std::string LoggedMessageSvc::m_defaultFormat
private

Default format for the messages.

Definition at line 144 of file LoggedMessageSvc.h.

◆ m_defaultMessage

Message LoggedMessageSvc::m_defaultMessage
private

Default Message.

Definition at line 140 of file LoggedMessageSvc.h.

◆ m_defaultStream

std::ostream* LoggedMessageSvc::m_defaultStream
private

Pointer to the output stream.

Definition at line 139 of file LoggedMessageSvc.h.

◆ m_defaultTimeFormat

std::string LoggedMessageSvc::m_defaultTimeFormat
private

Default format for timestamps in the messages.

Definition at line 145 of file LoggedMessageSvc.h.

◆ m_inactCount

BooleanProperty LoggedMessageSvc::m_inactCount
private

Definition at line 166 of file LoggedMessageSvc.h.

◆ m_inactiveMap

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

Definition at line 165 of file LoggedMessageSvc.h.

◆ m_keysUsed

bool LoggedMessageSvc::m_keysUsed
private

Definition at line 201 of file LoggedMessageSvc.h.

◆ m_keywords

StringArrayProperty LoggedMessageSvc::m_keywords
private

Definition at line 153 of file LoggedMessageSvc.h.

◆ m_logColorCodes

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

Definition at line 155 of file LoggedMessageSvc.h.

◆ m_logColors

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

Definition at line 150 of file LoggedMessageSvc.h.

◆ m_loggedStreams

LoggedStreamsMap_t LoggedMessageSvc::m_loggedStreams
private

Definition at line 176 of file LoggedMessageSvc.h.

◆ m_loggedStreamsName

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

Definition at line 174 of file LoggedMessageSvc.h.

◆ m_logLevel

IntegerProperty LoggedMessageSvc::m_logLevel
private

Definition at line 152 of file LoggedMessageSvc.h.

◆ m_messageMap

MessageMap LoggedMessageSvc::m_messageMap
private

Message map.

Definition at line 142 of file LoggedMessageSvc.h.

◆ m_messageMapMutex

std::recursive_mutex LoggedMessageSvc::m_messageMapMutex
mutableprivate

Mutex to synchronize multiple access to m_messageMap.

Definition at line 193 of file LoggedMessageSvc.h.

◆ m_msgCount

int LoggedMessageSvc::m_msgCount[MSG::NUM_LEVELS]
private

Definition at line 172 of file LoggedMessageSvc.h.

◆ m_msgKeyLog

std::vector< LoggedMessage > LoggedMessageSvc::m_msgKeyLog
private

Definition at line 200 of file LoggedMessageSvc.h.

◆ m_msgLimit

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

Definition at line 151 of file LoggedMessageSvc.h.

◆ m_msgLog

std::vector< std::pair<std::string, std::string> > LoggedMessageSvc::m_msgLog[MSG::NUM_LEVELS]
private

Definition at line 199 of file LoggedMessageSvc.h.

◆ m_reportMutex

std::mutex LoggedMessageSvc::m_reportMutex
mutableprivate

Mutex to synchronize multiple threads printing.

Definition at line 190 of file LoggedMessageSvc.h.

◆ m_sourceMap

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

Definition at line 165 of file LoggedMessageSvc.h.

◆ m_statLevel

UnsignedIntegerProperty LoggedMessageSvc::m_statLevel
private

Definition at line 149 of file LoggedMessageSvc.h.

◆ m_stats

BooleanProperty LoggedMessageSvc::m_stats
private

Definition at line 148 of file LoggedMessageSvc.h.

◆ m_streamMap

StreamMap LoggedMessageSvc::m_streamMap
private

Stream map.

Definition at line 141 of file LoggedMessageSvc.h.

◆ m_suppress

BooleanProperty LoggedMessageSvc::m_suppress
private

Definition at line 166 of file LoggedMessageSvc.h.

◆ m_thresholdMap

ThresholdMap LoggedMessageSvc::m_thresholdMap
private

Output level threshold map.

Definition at line 143 of file LoggedMessageSvc.h.

◆ m_thresholdMapMutex

std::mutex LoggedMessageSvc::m_thresholdMapMutex
mutableprivate

Mutex to synchronize multiple access to m_thresholdMap (.

See also
MsgStream::doOutput).

Definition at line 197 of file LoggedMessageSvc.h.

◆ m_thresholdProp

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

Properties controling.

Definition at line 146 of file LoggedMessageSvc.h.


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