| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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"
15 #include "GaudiKernel/IMessageSvc.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:
34 typedef std::pair< std::string, std::ostream* > NamedStream;
35 typedef std::multimap< int, NamedStream > StreamMap;
36 typedef std::multimap< StatusCode, Message > MessageMap;
37 typedef std::map< std::string, int > ThresholdMap;
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{
100 std::unique_lock<std::recursive_mutex> lock(m_reportMutex);
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()
126 void incrInactiveCount( MSG::Level level,
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:
138 std::ostream* m_defaultStream;
139 Message m_defaultMessage;
140 StreamMap m_streamMap;
141 MessageMap m_messageMap;
142 ThresholdMap m_thresholdMap;
143 std::string m_defaultFormat;
144 std::string m_defaultTimeFormat;
145 StringArrayProperty m_thresholdProp[MSG::NUM_LEVELS];
146 BooleanProperty m_color;
147 BooleanProperty m_stats;
148 UnsignedIntegerProperty m_statLevel;
149 StringArrayProperty m_logColors[MSG::NUM_LEVELS];
150 IntegerProperty m_msgLimit[MSG::NUM_LEVELS];
151
152 std::string m_logColorCodes[MSG::NUM_LEVELS];
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
162 std::map<std::string,MsgAry> m_sourceMap, m_inactiveMap;
163 BooleanProperty m_suppress, m_inactCount;
164 std::vector<std::string> m_tracedInactiveSources;
165
166 std::string colTrans(std::string, int);
167 typedef std::map<std::string, MSG::Color> ColorMap;
168 ColorMap m_colMap;
169
170 std::array<int,MSG::NUM_LEVELS> m_msgCount;
171
172 std::map<std::string, std::string> m_loggedStreamsName;
173 std::map<std::string, std::shared_ptr<std::ostream>> m_loggedStreams;
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
187 mutable std::recursive_mutex m_reportMutex;
188
190 mutable std::recursive_mutex m_messageMapMutex;
191
194 mutable std::recursive_mutex m_thresholdMapMutex;
195 };
196
197 #endif
MessageSvc::m_msgLimit
IntegerProperty m_msgLimit[MSG::NUM_LEVELS]
Definition: MessageSvc.h:150
MessageSvc::colTrans
std::string colTrans(std::string, int)
Definition: MessageSvc.cpp:434
CommonMessagingBase::msg
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:133
MessageSvc::m_defaultStream
std::ostream * m_defaultStream
Pointer to the output stream.
Definition: MessageSvc.h:138
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
MessageSvc::StreamMap
std::multimap< int, NamedStream > StreamMap
Definition: MessageSvc.h:35
MessageSvc::m_streamMap
StreamMap m_streamMap
Stream map.
Definition: MessageSvc.h:140
MessageSvc::m_msgCount
std::array< int, MSG::NUM_LEVELS > m_msgCount
Definition: MessageSvc.h:170
MessageSvc::i_reportMessage
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition: MessageSvc.cpp:451
MessageSvc::m_colMap
ColorMap m_colMap
Definition: MessageSvc.h:168
MessageSvc::m_defaultMessage
Message m_defaultMessage
Default Message.
Definition: MessageSvc.h:139
MessageSvc::m_messageMap
MessageMap m_messageMap
Message map.
Definition: MessageSvc.h:141
MessageSvc::setupLimits
void setupLimits(Property &prop)
Definition: MessageSvc.cpp:245
MessageSvc::setupInactCount
void setupInactCount(Property &prop)
Definition: MessageSvc.cpp:309
MessageSvc::setupLogStreams
void setupLogStreams()
Definition: MessageSvc.cpp:756
MessageSvc::MessageSvc
MessageSvc(const std::string &name, ISvcLocator *svcloc)
Definition: MessageSvc.cpp:58
MessageSvc::m_messageMapMutex
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
Definition: MessageSvc.h:190
MessageSvc::reinitialize
StatusCode reinitialize() override
Reinitialize Service.
Definition: MessageSvc.cpp:158
std::map< std::string, int >
MessageSvc::NamedStream
std::pair< std::string, std::ostream * > NamedStream
Definition: MessageSvc.h:34
MessageSvc::eraseMessage
void eraseMessage() override
Definition: MessageSvc.cpp:658
MessageSvc::ThresholdMap
std::map< std::string, int > ThresholdMap
Definition: MessageSvc.h:37
MessageSvc::m_statLevel
UnsignedIntegerProperty m_statLevel
Definition: MessageSvc.h:148
std::string
STL class.
MessageSvc::eraseStream
void eraseStream() override
Definition: MessageSvc.cpp:592
MessageSvc::incrInactiveCount
void incrInactiveCount(MSG::Level level, const std::string &src) override
Definition: MessageSvc.cpp:741
MessageSvc::m_loggedStreams
std::map< std::string, std::shared_ptr< std::ostream > > m_loggedStreams
Definition: MessageSvc.h:173
SimpleProperty< std::vector< std::string > >
Service.h
MessageSvc::MsgAry
Private helper class to keep the count of messages of a type (MSG::LEVEL).
Definition: MessageSvc.h:155
MessageSvc::m_sourceMap
std::map< std::string, MsgAry > m_sourceMap
Definition: MessageSvc.h:162
MessageSvc::ColorMap
std::map< std::string, MSG::Color > ColorMap
Definition: MessageSvc.h:167
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:319
MSG::Level
Level
Definition: IMessageSvc.h:15
MessageSvc::useColor
bool useColor() const override
Definition: MessageSvc.h:117
MessageSvc::getLogColor
std::string getLogColor(int logLevel) const override
Definition: MessageSvc.cpp:727
MessageSvc::setOutputLevel
void setOutputLevel(int new_level) override
Definition: MessageSvc.cpp:707
gaudirun.type
string type
Definition: gaudirun.py:151
MessageSvc::initialize
StatusCode initialize() override
Initialize Service.
Definition: MessageSvc.cpp:123
MessageSvc::m_thresholdMap
ThresholdMap m_thresholdMap
Output level threshold map.
Definition: MessageSvc.h:142
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::recursive_mutex
MessageSvc::reportMessage
void reportMessage(const Message &message) override
Definition: MessageSvc.cpp:510
locker.lock
def lock(file)
Definition: locker.py:16
IMessageSvc.h
MessageSvc::m_reportMutex
std::recursive_mutex m_reportMutex
Mutex to synchronize multiple threads printing.
Definition: MessageSvc.h:187
MessageSvc::MessageMap
std::multimap< StatusCode, Message > MessageMap
Definition: MessageSvc.h:36
std::multimap< int, NamedStream >
std::pair
std::set< std::string >
MessageSvc::MsgAry::MsgAry
MsgAry()=default
Default constructor.
std::unique_lock
MessageSvc::m_thresholdProp
StringArrayProperty m_thresholdProp[MSG::NUM_LEVELS]
Properties controlling.
Definition: MessageSvc.h:145
Property
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
std::vector< std::string >
Message
The Message class.
Definition: Message.h:14
MessageSvc::finalize
StatusCode finalize() override
Finalize Service.
Definition: MessageSvc.cpp:321
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
MessageSvc::~MessageSvc
~MessageSvc() override=default
MSG::NUM_LEVELS
Definition: IMessageSvc.h:24
MessageSvc::m_defaultFormat
std::string m_defaultFormat
Default format for the messages.
Definition: MessageSvc.h:143
Property.h
MessageSvc::defaultStream
std::ostream * defaultStream() const override
Definition: MessageSvc.h:94
MessageSvc::setupColors
void setupColors(Property &prop)
Definition: MessageSvc.cpp:195
std::array< int, MSG::NUM_LEVELS >
MessageSvc::m_inactiveMap
std::map< std::string, MsgAry > m_inactiveMap
Definition: MessageSvc.h:162
MessageSvc::initColors
void initColors(Property &prop)
Definition: MessageSvc.cpp:165
MessageSvc::m_logColorCodes
std::string m_logColorCodes[MSG::NUM_LEVELS]
Definition: MessageSvc.h:152
MessageSvc::messageCount
int messageCount(MSG::Level logLevel) const override
Definition: MessageSvc.cpp:733
gaudirun.level
level
Definition: gaudirun.py:261
MessageSvc::m_color
BooleanProperty m_color
Definition: MessageSvc.h:146
StatusCode.h
MessageSvc::m_inactCount
BooleanProperty m_inactCount
Definition: MessageSvc.h:163
MessageSvc::outputLevel
int outputLevel() const override
Definition: MessageSvc.cpp:693
MessageSvc::tee
void tee(const std::string &sourceName, const std::string &logFileName, const std::set< std::string > &declaredOutFileNames)
Definition: MessageSvc.cpp:775
MessageSvc::m_stats
BooleanProperty m_stats
Definition: MessageSvc.h:147
MessageSvc::m_loggedStreamsName
std::map< std::string, std::string > m_loggedStreamsName
Definition: MessageSvc.h:172
MessageSvc::m_tracedInactiveSources
std::vector< std::string > m_tracedInactiveSources
Definition: MessageSvc.h:164
MessageSvc::insertMessage
void insertMessage(const StatusCode &code, const Message &message) override
Definition: MessageSvc.cpp:645
MessageSvc
Definition: MessageSvc.h:30
MessageSvc::m_suppress
BooleanProperty m_suppress
Definition: MessageSvc.h:163
std::ostream
STL class.
MessageSvc::setupThreshold
void setupThreshold(Property &prop)
Definition: MessageSvc.cpp:272
MessageSvc::MsgAry::msg
std::array< int, MSG::NUM_LEVELS > msg
Internal array of counters.
Definition: MessageSvc.h:157
MessageSvc::m_defaultTimeFormat
std::string m_defaultTimeFormat
Default format for timestamps in the messages.
Definition: MessageSvc.h:144
MessageSvc::insertStream
void insertStream(int message_type, const std::string &name, std::ostream *stream) override
Definition: MessageSvc.cpp:578
MessageSvc::setDefaultStream
void setDefaultStream(std::ostream *stream) override
Definition: MessageSvc.h:99
MessageSvc::m_logColors
StringArrayProperty m_logColors[MSG::NUM_LEVELS]
Definition: MessageSvc.h:149
Message.h
MessageSvc::m_thresholdMapMutex
std::recursive_mutex m_thresholdMapMutex
Mutex to synchronize multiple access to m_thresholdMap (.
Definition: MessageSvc.h:194