The Gaudi Framework  v29r0 (ff2e7097)
MessageSvc.h
Go to the documentation of this file.
1 #ifndef GAUDI_MESSAGESVC_H
2 #define GAUDI_MESSAGESVC_H
3 
4 // Include files
5 #include <iosfwd>
6 #include <map>
7 #include <memory>
8 #include <mutex>
9 #include <set>
10 #include <string>
11 #include <vector>
12 
14 #include "GaudiKernel/Message.h"
15 #include "GaudiKernel/Property.h"
16 #include "GaudiKernel/Service.h"
17 #include "GaudiKernel/StatusCode.h"
18 
19 // Forward declarations
20 class ISvcLocator;
21 
22 //
23 // ClassName: MessageSvc
24 //
25 // Description: The MessageSvc service implements the IMessageSvc interface and provides the
26 // basic messaging needed by batch oriented applications.
27 //
28 // Author: Iain Last
29 //
30 class MessageSvc : public extends<Service, IMessageSvc, IInactiveMessageCounter>
31 {
32 public:
37 
38  // Default constructor.
39  MessageSvc( const std::string& name, ISvcLocator* svcloc );
40  // Destructor.
41  ~MessageSvc() override = default;
42 
43  // Implementation of IService::reinitialize()
44  StatusCode reinitialize() override;
45  // Implementation of IService::initialize()
46  StatusCode initialize() override;
47  // Implementation of IService::finalize()
48  StatusCode finalize() override;
49 
50  // Implementation of IMessageSvc::reportMessage()
51  void reportMessage( const Message& message ) override;
52 
53  // Implementation of IMessageSvc::reportMessage()
54  void reportMessage( const Message& msg, int outputLevel ) override;
55 
56  // Implementation of IMessageSvc::reportMessage()
57  void reportMessage( const StatusCode& code, const std::string& source = "" ) override;
58 
59  // Implementation of IMessageSvc::reportMessage()
60  void reportMessage( const char* source, int type, const char* message ) override;
61 
62  // Implementation of IMessageSvc::reportMessage()
63  void reportMessage( const std::string& source, int type, const std::string& message ) override;
64 
65  // Implementation of IMessageSvc::insertMessage()
66  void insertMessage( const StatusCode& code, const Message& message ) override;
67 
68  // Implementation of IMessageSvc::eraseMessage()
69  void eraseMessage() override;
70 
71  // Implementation of IMessageSvc::eraseMessage()
72  void eraseMessage( const StatusCode& code ) override;
73 
74  // Implementation of IMessageSvc::eraseMessage()
75  void eraseMessage( const StatusCode& code, const Message& message ) override;
76 
77  // Implementation of IMessageSvc::insertStream()
78  void insertStream( int message_type, const std::string& name, std::ostream* stream ) override;
79 
80  // Implementation of IMessageSvc::eraseStream()
81  void eraseStream() override;
82 
83  // Implementation of IMessageSvc::eraseStream()
84  void eraseStream( int message_type ) override;
85 
86  // Implementation of IMessageSvc::eraseStream()
87  void eraseStream( int message_type, std::ostream* stream ) override;
88 
89  // Implementation of IMessageSvc::eraseStream()
90  void eraseStream( std::ostream* stream ) override;
91 
92  // Implementation of IMessageSvc::desaultStream()
93  std::ostream* defaultStream() const override { return m_defaultStream; }
94 
95  // Implementation of IMessageSvc::setDefaultStream()
96  void setDefaultStream( std::ostream* stream ) override
97  {
99  m_defaultStream = stream;
100  }
101 
102  // Implementation of IMessageSvc::ouputLevel()
103  int outputLevel() const override;
104 
105  // Implementation of IMessageSvc::ouputLevel()
106  int outputLevel( const std::string& source ) const override;
107 
108  // Implementation of IMessageSvc::setOuputLevel()
109  void setOutputLevel( int new_level ) override;
110 
111  // Implementation of IMessageSvc::setOuputLevel()
112  void setOutputLevel( const std::string& source, int new_level ) override;
113 
114  // Implementation of IMessageSvc::useColor()
115  bool useColor() const override { return m_color; }
116 
117  // Implementation of IMessageSvc::getLogColor()
118  std::string getLogColor( int logLevel ) const override;
119 
120  // Implementation of IMessageSvc::messageCount()
121  int messageCount( MSG::Level logLevel ) const override;
122 
123  // Implementation of IInactiveMessageCounter::incrInactiveCount()
124  void incrInactiveCount( MSG::Level level, const std::string& src ) override;
125 
126 protected:
128  virtual void i_reportMessage( const Message& msg, int outputLevel );
129 
131  virtual void i_reportMessage( const StatusCode& code, const std::string& source );
132 
133 private:
136  Gaudi::Property<bool> m_stats{this, "showStats", false, ""};
137  Gaudi::Property<unsigned int> m_statLevel{this, "statLevel", 0, ""};
138 
140  {this, "setVerbose"},
141  {this, "setDebug"},
142  {this, "setInfo"},
143  {this, "setWarning"},
144  {this, "setError"},
145  {this, "setFatal"},
146  {this, "setAlways"}}};
147 
148  Gaudi::Property<bool> m_color{this, "useColors", false, ""};
149 
151  {this, "verboseColorCode"},
152  {this, "debugColorCode"},
153  {this, "infoColorCode"},
154  {this, "warningColorCode"},
155  {this, "errorColorCode"},
156  {this, "fatalColorCode"},
157  {this, "alwaysColorCode"}}};
158 
160  {this, "verboseLimit", 500},
161  {this, "debugLimit", 500},
162  {this, "infoLimit", 500},
163  {this, "warningLimit", 500},
164  {this, "errorLimit", 500},
165  {this, "fatalLimit", 500},
166  {this, "alwaysLimit", 0}}};
167 
168  Gaudi::Property<bool> m_suppress{this, "enableSuppression", false, ""};
169  Gaudi::Property<bool> m_inactCount{this, "countInactive", false, ""};
170 
172  this,
173  "tracedInactiveSources",
174  {},
175  "for each message source specified, print a stack trace for the unprotected and unseen messages"};
176 
178  this, "loggedStreams", {}, "MessageStream sources we want to dump into a logfile"};
179 
182  StreamMap m_streamMap;
183  MessageMap m_messageMap;
184  ThresholdMap m_thresholdMap;
185 
187 
189  struct MsgAry final {
193  MsgAry() = default;
194  };
195 
197 
199 
201 
206 
207  void setupLogStreams();
208 
209  void tee( const std::string& sourceName, const std::string& logFileName,
210  const std::set<std::string>& declaredOutFileNames );
211 
214 
217 
221 };
222 
223 #endif
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
bool useColor() const override
Definition: MessageSvc.h:115
std::ostream * m_defaultStream
Pointer to the output stream.
Definition: MessageSvc.h:180
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:289
StreamMap m_streamMap
Stream map.
Definition: MessageSvc.h:182
std::multimap< StatusCode, Message > MessageMap
Definition: MessageSvc.h:35
Implementation of property with value of concrete type.
Definition: Property.h:319
std::string getLogColor(int logLevel) const override
Definition: MessageSvc.cpp:630
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition: MessageSvc.cpp:366
void setupInactCount(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:232
std::map< std::string, MsgAry > m_sourceMap
Definition: MessageSvc.h:196
Message m_defaultMessage
Default Message.
Definition: MessageSvc.h:181
std::map< std::string, MsgAry > m_inactiveMap
Definition: MessageSvc.h:196
MessageMap m_messageMap
Message map.
Definition: MessageSvc.h:183
void setupLogStreams()
Definition: MessageSvc.cpp:654
Gaudi::Property< std::string > m_defaultTimeFormat
Definition: MessageSvc.h:135
MessageSvc(const std::string &name, ISvcLocator *svcloc)
Definition: MessageSvc.cpp:82
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
Definition: MessageSvc.h:216
StatusCode reinitialize() override
Reinitialize Service.
Definition: MessageSvc.cpp:125
void eraseMessage() override
Definition: MessageSvc.cpp:557
Gaudi::Property< std::vector< std::string > > m_tracedInactiveSources
Definition: MessageSvc.h:171
void setupColors(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:133
STL class.
void eraseStream() override
Definition: MessageSvc.cpp:497
void incrInactiveCount(MSG::Level level, const std::string &src) override
Definition: MessageSvc.cpp:640
std::map< std::string, std::shared_ptr< std::ostream > > m_loggedStreams
Definition: MessageSvc.h:200
Private helper class to keep the count of messages of a type (MSG::LEVEL).
Definition: MessageSvc.h:189
Gaudi::Property< bool > m_inactCount
Definition: MessageSvc.h:169
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_logColors
Definition: MessageSvc.h:150
Gaudi::Property< unsigned int > m_statLevel
Definition: MessageSvc.h:137
void setOutputLevel(int new_level) override
Definition: MessageSvc.cpp:608
StatusCode initialize() override
Initialize Service.
Definition: MessageSvc.cpp:107
ThresholdMap m_thresholdMap
Output level threshold map.
Definition: MessageSvc.h:184
static const std::string getDefaultTimeFormat()
Get the default time format string.
Definition: Message.cpp:194
std::multimap< int, NamedStream > StreamMap
Definition: MessageSvc.h:34
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
std::pair< std::string, std::ostream * > NamedStream
Definition: MessageSvc.h:33
static const std::string getDefaultFormat()
Get the default format string.
Definition: Message.cpp:162
void reportMessage(const Message &message) override
Definition: MessageSvc.cpp:424
Gaudi::Property< bool > m_color
Definition: MessageSvc.h:148
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
Gaudi::Property< std::string > m_defaultFormat
Definition: MessageSvc.h:134
std::recursive_mutex m_reportMutex
Mutex to synchronize multiple threads printing.
Definition: MessageSvc.h:213
MsgAry()=default
Default constructor.
The Message class.
Definition: Message.h:15
std::ostream * defaultStream() const override
Definition: MessageSvc.h:93
StatusCode finalize() override
Finalize Service.
Definition: MessageSvc.cpp:243
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
~MessageSvc() override=default
int outputLevel() const override
Definition: MessageSvc.cpp:592
STL class.
void setupLimits(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:176
void setupThreshold(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:199
std::string m_logColorCodes[MSG::NUM_LEVELS]
Definition: MessageSvc.h:186
Gaudi::Property< bool > m_stats
Definition: MessageSvc.h:136
std::array< int, MSG::NUM_LEVELS > m_msgCount
Definition: MessageSvc.h:198
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_thresholdProp
Definition: MessageSvc.h:139
std::array< Gaudi::Property< int >, MSG::NUM_LEVELS > m_msgLimit
Definition: MessageSvc.h:159
void tee(const std::string &sourceName, const std::string &logFileName, const std::set< std::string > &declaredOutFileNames)
Definition: MessageSvc.cpp:673
Gaudi::Property< bool > m_suppress
Definition: MessageSvc.h:168
void insertMessage(const StatusCode &code, const Message &message) override
Definition: MessageSvc.cpp:544
Gaudi::Property< std::map< std::string, std::string > > m_loggedStreamsName
Definition: MessageSvc.h:177
STL class.
void insertStream(int message_type, const std::string &name, std::ostream *stream) override
Definition: MessageSvc.cpp:485
void setDefaultStream(std::ostream *stream) override
Definition: MessageSvc.h:96
int messageCount(MSG::Level logLevel) const override
Definition: MessageSvc.cpp:637
std::map< std::string, int > ThresholdMap
Definition: MessageSvc.h:36
std::recursive_mutex m_thresholdMapMutex
Mutex to synchronize multiple access to m_thresholdMap (.
Definition: MessageSvc.h:220