The Gaudi Framework  v30r3 (a5ef0a68)
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 
41  // Implementation of IService::reinitialize()
42  StatusCode reinitialize() override;
43  // Implementation of IService::initialize()
44  StatusCode initialize() override;
45  // Implementation of IService::finalize()
46  StatusCode finalize() override;
47 
48  // Implementation of IMessageSvc::reportMessage()
49  void reportMessage( const Message& message ) override;
50 
51  // Implementation of IMessageSvc::reportMessage()
52  void reportMessage( const Message& msg, int outputLevel ) override;
53 
54  // Implementation of IMessageSvc::reportMessage()
55  void reportMessage( const StatusCode& code, const std::string& source = "" ) override;
56 
57  // Implementation of IMessageSvc::reportMessage()
58  void reportMessage( const char* source, int type, const char* message ) override;
59 
60  // Implementation of IMessageSvc::reportMessage()
61  void reportMessage( const std::string& source, int type, const std::string& message ) override;
62 
63  // Implementation of IMessageSvc::insertMessage()
64  void insertMessage( const StatusCode& code, const Message& message ) override;
65 
66  // Implementation of IMessageSvc::eraseMessage()
67  void eraseMessage() override;
68 
69  // Implementation of IMessageSvc::eraseMessage()
70  void eraseMessage( const StatusCode& code ) override;
71 
72  // Implementation of IMessageSvc::eraseMessage()
73  void eraseMessage( const StatusCode& code, const Message& message ) override;
74 
75  // Implementation of IMessageSvc::insertStream()
76  void insertStream( int message_type, const std::string& name, std::ostream* stream ) override;
77 
78  // Implementation of IMessageSvc::eraseStream()
79  void eraseStream() override;
80 
81  // Implementation of IMessageSvc::eraseStream()
82  void eraseStream( int message_type ) override;
83 
84  // Implementation of IMessageSvc::eraseStream()
85  void eraseStream( int message_type, std::ostream* stream ) override;
86 
87  // Implementation of IMessageSvc::eraseStream()
88  void eraseStream( std::ostream* stream ) override;
89 
90  // Implementation of IMessageSvc::desaultStream()
91  std::ostream* defaultStream() const override { return m_defaultStream; }
92 
93  // Implementation of IMessageSvc::setDefaultStream()
94  void setDefaultStream( std::ostream* stream ) override
95  {
97  m_defaultStream = stream;
98  }
99 
100  // Implementation of IMessageSvc::ouputLevel()
101  int outputLevel() const override;
102 
103  // Implementation of IMessageSvc::ouputLevel()
104  int outputLevel( const std::string& source ) const override;
105 
106  // Implementation of IMessageSvc::setOuputLevel()
107  void setOutputLevel( int new_level ) override;
108 
109  // Implementation of IMessageSvc::setOuputLevel()
110  void setOutputLevel( const std::string& source, int new_level ) override;
111 
112  // Implementation of IMessageSvc::useColor()
113  bool useColor() const override { return m_color; }
114 
115  // Implementation of IMessageSvc::getLogColor()
116  std::string getLogColor( int logLevel ) const override;
117 
118  // Implementation of IMessageSvc::messageCount()
119  int messageCount( MSG::Level logLevel ) const override;
120 
121  // Implementation of IInactiveMessageCounter::incrInactiveCount()
122  void incrInactiveCount( MSG::Level level, const std::string& src ) override;
123 
124 protected:
126  virtual void i_reportMessage( const Message& msg, int outputLevel );
127 
129  virtual void i_reportMessage( const StatusCode& code, const std::string& source );
130 
131 private:
134  Gaudi::Property<bool> m_stats{this, "showStats", false, ""};
135  Gaudi::Property<unsigned int> m_statLevel{this, "statLevel", 0, ""};
136 
138  {this, "setVerbose"},
139  {this, "setDebug"},
140  {this, "setInfo"},
141  {this, "setWarning"},
142  {this, "setError"},
143  {this, "setFatal"},
144  {this, "setAlways"}}};
145 
146  Gaudi::Property<bool> m_color{this, "useColors", false, ""};
147 
149  {this, "verboseColorCode"},
150  {this, "debugColorCode"},
151  {this, "infoColorCode"},
152  {this, "warningColorCode"},
153  {this, "errorColorCode"},
154  {this, "fatalColorCode"},
155  {this, "alwaysColorCode"}}};
156 
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}}};
165 
166  Gaudi::Property<bool> m_suppress{this, "enableSuppression", false, ""};
167  Gaudi::Property<bool> m_inactCount{this, "countInactive", false, ""};
168 
170  this,
171  "tracedInactiveSources",
172  {},
173  "for each message source specified, print a stack trace for the unprotected and unseen messages"};
174 
176  this, "loggedStreams", {}, "MessageStream sources we want to dump into a logfile"};
177 
180  StreamMap m_streamMap;
181  MessageMap m_messageMap;
182  ThresholdMap m_thresholdMap;
183 
185 
187  struct MsgAry final {
191  MsgAry() = default;
192  };
193 
195 
197 
199 
204 
205  void setupLogStreams();
206 
207  void tee( const std::string& sourceName, const std::string& logFileName,
208  const std::set<std::string>& declaredOutFileNames );
209 
212 
215 
219 };
220 
221 #endif
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
bool useColor() const override
Definition: MessageSvc.h:113
std::ostream * m_defaultStream
Pointer to the output stream.
Definition: MessageSvc.h:178
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:288
StreamMap m_streamMap
Stream map.
Definition: MessageSvc.h:180
std::multimap< StatusCode, Message > MessageMap
Definition: MessageSvc.h:35
Implementation of property with value of concrete type.
Definition: Property.h:381
std::string getLogColor(int logLevel) const override
Definition: MessageSvc.cpp:636
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition: MessageSvc.cpp:372
void setupInactCount(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:238
std::map< std::string, MsgAry > m_sourceMap
Definition: MessageSvc.h:194
Message m_defaultMessage
Default Message.
Definition: MessageSvc.h:179
std::map< std::string, MsgAry > m_inactiveMap
Definition: MessageSvc.h:194
MessageMap m_messageMap
Message map.
Definition: MessageSvc.h:181
void setupLogStreams()
Definition: MessageSvc.cpp:660
Gaudi::Property< std::string > m_defaultTimeFormat
Definition: MessageSvc.h:133
MessageSvc(const std::string &name, ISvcLocator *svcloc)
Definition: MessageSvc.cpp:83
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
Definition: MessageSvc.h:214
StatusCode reinitialize() override
Reinitialize Service.
Definition: MessageSvc.cpp:131
void eraseMessage() override
Definition: MessageSvc.cpp:563
Gaudi::Property< std::vector< std::string > > m_tracedInactiveSources
Definition: MessageSvc.h:169
void setupColors(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:139
STL class.
void eraseStream() override
Definition: MessageSvc.cpp:503
void incrInactiveCount(MSG::Level level, const std::string &src) override
Definition: MessageSvc.cpp:646
std::map< std::string, std::shared_ptr< std::ostream > > m_loggedStreams
Definition: MessageSvc.h:198
Private helper class to keep the count of messages of a type (MSG::LEVEL).
Definition: MessageSvc.h:187
Gaudi::Property< bool > m_inactCount
Definition: MessageSvc.h:167
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_logColors
Definition: MessageSvc.h:148
Gaudi::Property< unsigned int > m_statLevel
Definition: MessageSvc.h:135
void setOutputLevel(int new_level) override
Definition: MessageSvc.cpp:614
StatusCode initialize() override
Initialize Service.
Definition: MessageSvc.cpp:113
ThresholdMap m_thresholdMap
Output level threshold map.
Definition: MessageSvc.h:182
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:51
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:430
Gaudi::Property< bool > m_color
Definition: MessageSvc.h:146
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
Gaudi::Property< std::string > m_defaultFormat
Definition: MessageSvc.h:132
std::recursive_mutex m_reportMutex
Mutex to synchronize multiple threads printing.
Definition: MessageSvc.h:211
MsgAry()=default
Default constructor.
The Message class.
Definition: Message.h:15
std::ostream * defaultStream() const override
Definition: MessageSvc.h:91
StatusCode finalize() override
Finalize Service.
Definition: MessageSvc.cpp:249
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
int outputLevel() const override
Definition: MessageSvc.cpp:598
STL class.
void setupLimits(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:182
void setupThreshold(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:205
std::string m_logColorCodes[MSG::NUM_LEVELS]
Definition: MessageSvc.h:184
Gaudi::Property< bool > m_stats
Definition: MessageSvc.h:134
std::array< int, MSG::NUM_LEVELS > m_msgCount
Definition: MessageSvc.h:196
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_thresholdProp
Definition: MessageSvc.h:137
std::array< Gaudi::Property< int >, MSG::NUM_LEVELS > m_msgLimit
Definition: MessageSvc.h:157
void tee(const std::string &sourceName, const std::string &logFileName, const std::set< std::string > &declaredOutFileNames)
Definition: MessageSvc.cpp:679
Gaudi::Property< bool > m_suppress
Definition: MessageSvc.h:166
void insertMessage(const StatusCode &code, const Message &message) override
Definition: MessageSvc.cpp:550
Gaudi::Property< std::map< std::string, std::string > > m_loggedStreamsName
Definition: MessageSvc.h:175
STL class.
void insertStream(int message_type, const std::string &name, std::ostream *stream) override
Definition: MessageSvc.cpp:491
void setDefaultStream(std::ostream *stream) override
Definition: MessageSvc.h:94
int messageCount(MSG::Level logLevel) const override
Definition: MessageSvc.cpp:643
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:218