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 <string>
6 #include <vector>
7 #include <map>
8 #include <mutex>
9 #include <set>
10 #include <iosfwd>
11 #include <memory>
12 
13 #include "GaudiKernel/StatusCode.h"
14 #include "GaudiKernel/Service.h"
16 #include "GaudiKernel/Message.h"
17 #include "GaudiKernel/Property.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,
31  IMessageSvc,
32  IInactiveMessageCounter> {
33 public:
38 
39  // Default constructor.
40  MessageSvc( const std::string& name, ISvcLocator* svcloc );
41  // Destructor.
42  ~MessageSvc() override = default;
43 
44  // Implementation of IService::reinitialize()
45  StatusCode reinitialize() override;
46  // Implementation of IService::initialize()
47  StatusCode initialize() override;
48  // Implementation of IService::finalize()
49  StatusCode finalize() override;
50 
51  // Implementation of IMessageSvc::reportMessage()
52  void reportMessage( const Message& message ) override;
53 
54  // Implementation of IMessageSvc::reportMessage()
55  void reportMessage( const Message& msg, int outputLevel ) override;
56 
57  // Implementation of IMessageSvc::reportMessage()
58  void reportMessage( const StatusCode& code, const std::string& source = "") override;
59 
60  // Implementation of IMessageSvc::reportMessage()
61  void reportMessage( const char* source, int type, const char* message) override;
62 
63  // Implementation of IMessageSvc::reportMessage()
64  void reportMessage( const std::string& source, int type, const std::string& message) override;
65 
66  // Implementation of IMessageSvc::insertMessage()
67  void insertMessage( const StatusCode& code, const Message& message ) override;
68 
69  // Implementation of IMessageSvc::eraseMessage()
70  void eraseMessage() override;
71 
72  // Implementation of IMessageSvc::eraseMessage()
73  void eraseMessage( const StatusCode& code ) override;
74 
75  // Implementation of IMessageSvc::eraseMessage()
76  void eraseMessage( const StatusCode& code, const Message& message ) override;
77 
78  // Implementation of IMessageSvc::insertStream()
79  void insertStream( int message_type, const std::string& name, std::ostream* stream ) override;
80 
81  // Implementation of IMessageSvc::eraseStream()
82  void eraseStream() override;
83 
84  // Implementation of IMessageSvc::eraseStream()
85  void eraseStream( int message_type ) override;
86 
87  // Implementation of IMessageSvc::eraseStream()
88  void eraseStream( int message_type, std::ostream* stream ) override;
89 
90  // Implementation of IMessageSvc::eraseStream()
91  void eraseStream( std::ostream* stream ) override;
92 
93  // Implementation of IMessageSvc::desaultStream()
94  std::ostream* defaultStream() const override {
95  return m_defaultStream;
96  }
97 
98  // Implementation of IMessageSvc::setDefaultStream()
99  void setDefaultStream( std::ostream* stream ) override{
101  m_defaultStream = stream;
102  }
103 
104  // Implementation of IMessageSvc::ouputLevel()
105  int outputLevel() const override;
106 
107  // Implementation of IMessageSvc::ouputLevel()
108  int outputLevel(const std::string& source) const override;
109 
110  // Implementation of IMessageSvc::setOuputLevel()
111  void setOutputLevel(int new_level) override;
112 
113  // Implementation of IMessageSvc::setOuputLevel()
114  void setOutputLevel(const std::string& source, int new_level) override;
115 
116  // Implementation of IMessageSvc::useColor()
117  bool useColor() const override { return m_color; }
118 
119  // Implementation of IMessageSvc::getLogColor()
120  std::string getLogColor(int logLevel) const override;
121 
122  // Implementation of IMessageSvc::messageCount()
123  int messageCount( MSG::Level logLevel ) const override;
124 
125  // Implementation of IInactiveMessageCounter::incrInactiveCount()
127  const std::string& src ) override;
128 
129 protected:
131  virtual void i_reportMessage( const Message& msg, int outputLevel );
132 
134  virtual void i_reportMessage( const StatusCode& code, const std::string& source);
135 
136 
137 private:
140  StreamMap m_streamMap;
141  MessageMap m_messageMap;
142  ThresholdMap m_thresholdMap;
151 
153 
155  struct MsgAry final {
157  std::array<int,MSG::NUM_LEVELS> msg = {{0}}; // empty value-initialization will trigger zero-initialize of all elements (i.e. 0)
159  MsgAry() = default;
160  };
161 
165 
168  ColorMap m_colMap;
169 
171 
174 
175  void initColors(Property& prop);
176  void setupColors(Property& prop);
177  void setupLimits(Property& prop);
178  void setupThreshold(Property& prop);
179  void setupInactCount(Property& prop);
180 
181  void setupLogStreams();
182 
183  void tee( const std::string& sourceName, const std::string& logFileName,
184  const std::set<std::string>& declaredOutFileNames );
185 
188 
191 
195 };
196 
197 #endif
IntegerProperty m_msgLimit[MSG::NUM_LEVELS]
Definition: MessageSvc.h:150
std::string colTrans(std::string, int)
Definition: MessageSvc.cpp:434
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
std::ostream * m_defaultStream
Pointer to the output stream.
Definition: MessageSvc.h:138
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
std::multimap< int, NamedStream > StreamMap
Definition: MessageSvc.h:35
StreamMap m_streamMap
Stream map.
Definition: MessageSvc.h:140
std::array< int, MSG::NUM_LEVELS > m_msgCount
Definition: MessageSvc.h:170
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition: MessageSvc.cpp:451
ColorMap m_colMap
Definition: MessageSvc.h:168
Message m_defaultMessage
Default Message.
Definition: MessageSvc.h:139
MessageMap m_messageMap
Message map.
Definition: MessageSvc.h:141
void setupLimits(Property &prop)
Definition: MessageSvc.cpp:245
void setupInactCount(Property &prop)
Definition: MessageSvc.cpp:309
void setupLogStreams()
Definition: MessageSvc.cpp:756
MessageSvc(const std::string &name, ISvcLocator *svcloc)
Definition: MessageSvc.cpp:58
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
Definition: MessageSvc.h:190
StatusCode reinitialize() override
Reinitialize Service.
Definition: MessageSvc.cpp:158
std::pair< std::string, std::ostream * > NamedStream
Definition: MessageSvc.h:34
void eraseMessage() override
Definition: MessageSvc.cpp:658
std::map< std::string, int > ThresholdMap
Definition: MessageSvc.h:37
UnsignedIntegerProperty m_statLevel
Definition: MessageSvc.h:148
STL class.
void eraseStream() override
Definition: MessageSvc.cpp:592
void incrInactiveCount(MSG::Level level, const std::string &src) override
Definition: MessageSvc.cpp:741
std::map< std::string, std::shared_ptr< std::ostream > > m_loggedStreams
Definition: MessageSvc.h:173
Private helper class to keep the count of messages of a type (MSG::LEVEL).
Definition: MessageSvc.h:155
std::map< std::string, MsgAry > m_sourceMap
Definition: MessageSvc.h:162
std::map< std::string, MSG::Color > ColorMap
Definition: MessageSvc.h:167
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:319
bool useColor() const override
Definition: MessageSvc.h:117
std::string getLogColor(int logLevel) const override
Definition: MessageSvc.cpp:727
void setOutputLevel(int new_level) override
Definition: MessageSvc.cpp:707
string type
Definition: gaudirun.py:151
StatusCode initialize() override
Initialize Service.
Definition: MessageSvc.cpp:123
ThresholdMap m_thresholdMap
Output level threshold map.
Definition: MessageSvc.h:142
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
void reportMessage(const Message &message) override
Definition: MessageSvc.cpp:510
def lock(file)
Definition: locker.py:16
std::recursive_mutex m_reportMutex
Mutex to synchronize multiple threads printing.
Definition: MessageSvc.h:187
std::multimap< StatusCode, Message > MessageMap
Definition: MessageSvc.h:36
MsgAry()=default
Default constructor.
StringArrayProperty m_thresholdProp[MSG::NUM_LEVELS]
Properties controlling.
Definition: MessageSvc.h:145
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
The Message class.
Definition: Message.h:14
StatusCode finalize() override
Finalize Service.
Definition: MessageSvc.cpp:321
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
~MessageSvc() override=default
std::string m_defaultFormat
Default format for the messages.
Definition: MessageSvc.h:143
std::ostream * defaultStream() const override
Definition: MessageSvc.h:94
void setupColors(Property &prop)
Definition: MessageSvc.cpp:195
std::map< std::string, MsgAry > m_inactiveMap
Definition: MessageSvc.h:162
void initColors(Property &prop)
Definition: MessageSvc.cpp:165
std::string m_logColorCodes[MSG::NUM_LEVELS]
Definition: MessageSvc.h:152
int messageCount(MSG::Level logLevel) const override
Definition: MessageSvc.cpp:733
BooleanProperty m_color
Definition: MessageSvc.h:146
BooleanProperty m_inactCount
Definition: MessageSvc.h:163
int outputLevel() const override
Definition: MessageSvc.cpp:693
void tee(const std::string &sourceName, const std::string &logFileName, const std::set< std::string > &declaredOutFileNames)
Definition: MessageSvc.cpp:775
BooleanProperty m_stats
Definition: MessageSvc.h:147
std::map< std::string, std::string > m_loggedStreamsName
Definition: MessageSvc.h:172
std::vector< std::string > m_tracedInactiveSources
Definition: MessageSvc.h:164
void insertMessage(const StatusCode &code, const Message &message) override
Definition: MessageSvc.cpp:645
BooleanProperty m_suppress
Definition: MessageSvc.h:163
STL class.
void setupThreshold(Property &prop)
Definition: MessageSvc.cpp:272
std::array< int, MSG::NUM_LEVELS > msg
Internal array of counters.
Definition: MessageSvc.h:157
std::string m_defaultTimeFormat
Default format for timestamps in the messages.
Definition: MessageSvc.h:144
void insertStream(int message_type, const std::string &name, std::ostream *stream) override
Definition: MessageSvc.cpp:578
void setDefaultStream(std::ostream *stream) override
Definition: MessageSvc.h:99
StringArrayProperty m_logColors[MSG::NUM_LEVELS]
Definition: MessageSvc.h:149
std::recursive_mutex m_thresholdMapMutex
Mutex to synchronize multiple access to m_thresholdMap (.
Definition: MessageSvc.h:194