Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 public:
36 
37  // Default constructor.
38  MessageSvc( const std::string& name, ISvcLocator* svcloc );
39 
40  // Implementation of IService::reinitialize()
41  StatusCode reinitialize() override;
42  // Implementation of IService::initialize()
43  StatusCode initialize() override;
44  // Implementation of IService::finalize()
45  StatusCode finalize() override;
46 
47  // Implementation of IMessageSvc::reportMessage()
48  void reportMessage( const Message& message ) override;
49 
50  // Implementation of IMessageSvc::reportMessage()
51  void reportMessage( const Message& msg, int outputLevel ) override;
52 
53  // Implementation of IMessageSvc::reportMessage()
54  void reportMessage( const StatusCode& code, const std::string& source = "" ) override;
55 
56  // Implementation of IMessageSvc::reportMessage()
57  void reportMessage( const char* source, int type, const char* message ) override;
58 
59  // Implementation of IMessageSvc::reportMessage()
60  void reportMessage( const std::string& source, int type, const std::string& message ) override;
61 
62  // Implementation of IMessageSvc::insertMessage()
63  void insertMessage( const StatusCode& code, const Message& message ) override;
64 
65  // Implementation of IMessageSvc::eraseMessage()
66  void eraseMessage() override;
67 
68  // Implementation of IMessageSvc::eraseMessage()
69  void eraseMessage( const StatusCode& code ) override;
70 
71  // Implementation of IMessageSvc::eraseMessage()
72  void eraseMessage( const StatusCode& code, const Message& message ) override;
73 
74  // Implementation of IMessageSvc::insertStream()
75  void insertStream( int message_type, const std::string& name, std::ostream* stream ) override;
76 
77  // Implementation of IMessageSvc::eraseStream()
78  void eraseStream() override;
79 
80  // Implementation of IMessageSvc::eraseStream()
81  void eraseStream( int message_type ) override;
82 
83  // Implementation of IMessageSvc::eraseStream()
84  void eraseStream( int message_type, std::ostream* stream ) override;
85 
86  // Implementation of IMessageSvc::eraseStream()
87  void eraseStream( std::ostream* stream ) override;
88 
89  // Implementation of IMessageSvc::desaultStream()
90  std::ostream* defaultStream() const override { return m_defaultStream; }
91 
92  // Implementation of IMessageSvc::setDefaultStream()
93  void setDefaultStream( std::ostream* stream ) override {
95  m_defaultStream = stream;
96  }
97 
98  // Implementation of IMessageSvc::ouputLevel()
99  int outputLevel() const override;
100 
101  // Implementation of IMessageSvc::ouputLevel()
102  int outputLevel( const std::string& source ) const override;
103 
104  // Implementation of IMessageSvc::setOuputLevel()
105  void setOutputLevel( int new_level ) override;
106 
107  // Implementation of IMessageSvc::setOuputLevel()
108  void setOutputLevel( const std::string& source, int new_level ) override;
109 
110  // Implementation of IMessageSvc::useColor()
111  bool useColor() const override { return m_color; }
112 
113  // Implementation of IMessageSvc::getLogColor()
114  std::string getLogColor( int logLevel ) const override;
115 
116  // Implementation of IMessageSvc::messageCount()
117  int messageCount( MSG::Level logLevel ) const override;
118 
119  // Implementation of IInactiveMessageCounter::incrInactiveCount()
120  void incrInactiveCount( MSG::Level level, const std::string& src ) override;
121 
122 protected:
124  virtual void i_reportMessage( const Message& msg, int outputLevel );
125 
127  virtual void i_reportMessage( const StatusCode& code, const std::string& source );
128 
129 private:
132  Gaudi::Property<bool> m_stats{this, "showStats", false, ""};
133  Gaudi::Property<unsigned int> m_statLevel{this, "statLevel", 0, ""};
134 
136  {this, "setVerbose"},
137  {this, "setDebug"},
138  {this, "setInfo"},
139  {this, "setWarning"},
140  {this, "setError"},
141  {this, "setFatal"},
142  {this, "setAlways"}}};
143 
144  Gaudi::Property<bool> m_color{this, "useColors", false, ""};
145 
147  {this, "verboseColorCode"},
148  {this, "debugColorCode"},
149  {this, "infoColorCode"},
150  {this, "warningColorCode"},
151  {this, "errorColorCode"},
152  {this, "fatalColorCode"},
153  {this, "alwaysColorCode"}}};
154 
156  {this, "verboseLimit", 500},
157  {this, "debugLimit", 500},
158  {this, "infoLimit", 500},
159  {this, "warningLimit", 500},
160  {this, "errorLimit", 500},
161  {this, "fatalLimit", 500},
162  {this, "alwaysLimit", 0}}};
163 
164  Gaudi::Property<bool> m_suppress{this, "enableSuppression", false, ""};
166 
168  this,
169  "tracedInactiveSources",
170  {},
171  "for each message source specified, print a stack trace for the unprotected and unseen messages"};
172 
174  this, "loggedStreams", {}, "MessageStream sources we want to dump into a logfile"};
175 
178  StreamMap m_streamMap;
179  MessageMap m_messageMap;
180  ThresholdMap m_thresholdMap;
181 
183 
185  struct MsgAry final {
189  MsgAry() = default;
190  };
191 
193 
195 
197 
202 
203  void setupLogStreams();
204 
205  void tee( const std::string& sourceName, const std::string& logFileName,
206  const std::set<std::string>& declaredOutFileNames );
207 
210 
213 
217 };
218 
219 #endif
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
bool useColor() const override
Definition: MessageSvc.h:111
std::ostream * m_defaultStream
Pointer to the output stream.
Definition: MessageSvc.h:176
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:274
StreamMap m_streamMap
Stream map.
Definition: MessageSvc.h:178
std::multimap< StatusCode, Message > MessageMap
Definition: MessageSvc.h:34
Implementation of property with value of concrete type.
Definition: Property.h:352
std::string getLogColor(int logLevel) const override
Definition: MessageSvc.cpp:597
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition: MessageSvc.cpp:353
void setupInactCount(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:224
std::map< std::string, MsgAry > m_sourceMap
Definition: MessageSvc.h:192
Message m_defaultMessage
Default Message.
Definition: MessageSvc.h:177
std::map< std::string, MsgAry > m_inactiveMap
Definition: MessageSvc.h:192
MessageMap m_messageMap
Message map.
Definition: MessageSvc.h:179
void setupLogStreams()
Definition: MessageSvc.cpp:619
Gaudi::Property< std::string > m_defaultTimeFormat
Definition: MessageSvc.h:131
MessageSvc(const std::string &name, ISvcLocator *svcloc)
Definition: MessageSvc.cpp:78
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
Definition: MessageSvc.h:212
StatusCode reinitialize() override
Reinitialize Service.
Definition: MessageSvc.cpp:123
void eraseMessage() override
Definition: MessageSvc.cpp:531
Gaudi::Property< std::vector< std::string > > m_tracedInactiveSources
Definition: MessageSvc.h:167
void setupColors(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:130
STL class.
void eraseStream() override
Definition: MessageSvc.cpp:474
void incrInactiveCount(MSG::Level level, const std::string &src) override
Definition: MessageSvc.cpp:606
std::map< std::string, std::shared_ptr< std::ostream > > m_loggedStreams
Definition: MessageSvc.h:196
Private helper class to keep the count of messages of a type (MSG::LEVEL).
Definition: MessageSvc.h:185
Gaudi::Property< bool > m_inactCount
Definition: MessageSvc.h:165
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_logColors
Definition: MessageSvc.h:146
Gaudi::Property< unsigned int > m_statLevel
Definition: MessageSvc.h:133
void setOutputLevel(int new_level) override
Definition: MessageSvc.cpp:577
StatusCode initialize() override
Initialize Service.
Definition: MessageSvc.cpp:106
ThresholdMap m_thresholdMap
Output level threshold map.
Definition: MessageSvc.h:180
static const std::string getDefaultTimeFormat()
Get the default time format string.
Definition: Message.cpp:165
std::multimap< int, NamedStream > StreamMap
Definition: MessageSvc.h:33
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
std::pair< std::string, std::ostream * > NamedStream
Definition: MessageSvc.h:32
static const std::string getDefaultFormat()
Get the default format string.
Definition: Message.cpp:134
void reportMessage(const Message &message) override
Definition: MessageSvc.cpp:406
Gaudi::Property< bool > m_color
Definition: MessageSvc.h:144
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
Gaudi::Property< std::string > m_defaultFormat
Definition: MessageSvc.h:130
std::recursive_mutex m_reportMutex
Mutex to synchronize multiple threads printing.
Definition: MessageSvc.h:209
MsgAry()=default
Default constructor.
The Message class.
Definition: Message.h:17
std::ostream * defaultStream() const override
Definition: MessageSvc.h:90
StatusCode finalize() override
Finalize Service.
Definition: MessageSvc.cpp:234
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
int outputLevel() const override
Definition: MessageSvc.cpp:563
STL class.
void setupLimits(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:172
void setupThreshold(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:192
std::string m_logColorCodes[MSG::NUM_LEVELS]
Definition: MessageSvc.h:182
Gaudi::Property< bool > m_stats
Definition: MessageSvc.h:132
std::array< int, MSG::NUM_LEVELS > m_msgCount
Definition: MessageSvc.h:194
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_thresholdProp
Definition: MessageSvc.h:135
std::array< Gaudi::Property< int >, MSG::NUM_LEVELS > m_msgLimit
Definition: MessageSvc.h:155
void tee(const std::string &sourceName, const std::string &logFileName, const std::set< std::string > &declaredOutFileNames)
Definition: MessageSvc.cpp:635
Gaudi::Property< bool > m_suppress
Definition: MessageSvc.h:164
void insertMessage(const StatusCode &code, const Message &message) override
Definition: MessageSvc.cpp:519
Gaudi::Property< std::map< std::string, std::string > > m_loggedStreamsName
Definition: MessageSvc.h:173
STL class.
void insertStream(int message_type, const std::string &name, std::ostream *stream) override
Definition: MessageSvc.cpp:463
void setDefaultStream(std::ostream *stream) override
Definition: MessageSvc.h:93
int messageCount(MSG::Level logLevel) const override
Definition: MessageSvc.cpp:603
std::map< std::string, int > ThresholdMap
Definition: MessageSvc.h:35
std::recursive_mutex m_thresholdMapMutex
Mutex to synchronize multiple access to m_thresholdMap (.
Definition: MessageSvc.h:216