| The Gaudi Framework v32r1 (f65d50dc)

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
13 #include "GaudiKernel/IMessageSvc.h"
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:
32 typedef std::pair<std::string, std::ostream*> NamedStream;
33 typedef std::multimap<int, NamedStream> StreamMap;
34 typedef std::multimap<StatusCode, Message> MessageMap;
35 typedef std::map<std::string, int> ThresholdMap;
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 {
94 std::unique_lock<std::recursive_mutex> lock( m_reportMutex );
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:
130 Gaudi::Property<std::string> m_defaultFormat{this, "Format", Message::getDefaultFormat(), ""};
131 Gaudi::Property<std::string> m_defaultTimeFormat{this, "timeFormat", Message::getDefaultTimeFormat(), ""};
132 Gaudi::Property<bool> m_stats{this, "showStats", false, ""};
133 Gaudi::Property<unsigned int> m_statLevel{this, "statLevel", 0, ""};
134
135 std::array<Gaudi::Property<std::vector<std::string>>, MSG::NUM_LEVELS> m_thresholdProp{{{/*ignored*/},
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
146 std::array<Gaudi::Property<std::vector<std::string>>, MSG::NUM_LEVELS> m_logColors{{{/*ignored*/},
147 {this, "verboseColorCode"},
148 {this, "debugColorCode"},
149 {this, "infoColorCode"},
150 {this, "warningColorCode"},
151 {this, "errorColorCode"},
152 {this, "fatalColorCode"},
153 {this, "alwaysColorCode"}}};
154
155 std::array<Gaudi::Property<int>, MSG::NUM_LEVELS> m_msgLimit{{{this, "defaultLimit", 500},
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, ""};
165 Gaudi::Property<bool> m_inactCount{this, "countInactive", false, &MessageSvc::setupInactCount, ""};
166
167 Gaudi::Property<std::vector<std::string>> m_tracedInactiveSources{
168 this,
169 "tracedInactiveSources",
170 {},
171 "for each message source specified, print a stack trace for the unprotected and unseen messages"};
172
173 Gaudi::Property<std::map<std::string, std::string>> m_loggedStreamsName{
174 this, "loggedStreams", {}, "MessageStream sources we want to dump into a logfile"};
175
176 std::ostream* m_defaultStream = &std::cout;
177 Message m_defaultMessage;
178 StreamMap m_streamMap;
179 MessageMap m_messageMap;
180 ThresholdMap m_thresholdMap;
181
182 std::string m_logColorCodes[MSG::NUM_LEVELS];
183
185 struct MsgAry final {
187 std::array<int, MSG::NUM_LEVELS> msg = {{0}};
189 MsgAry() = default;
190 };
191
192 std::map<std::string, MsgAry> m_sourceMap, m_inactiveMap;
193
194 std::array<int, MSG::NUM_LEVELS> m_msgCount;
195
196 std::map<std::string, std::shared_ptr<std::ostream>> m_loggedStreams;
197
198 void setupColors( Gaudi::Details::PropertyBase& prop );
199 void setupLimits( Gaudi::Details::PropertyBase& prop );
200 void setupThreshold( Gaudi::Details::PropertyBase& prop );
201 void setupInactCount( Gaudi::Details::PropertyBase& prop );
202
203 void setupLogStreams();
204
205 void tee( const std::string& sourceName, const std::string& logFileName,
206 const std::set<std::string>& declaredOutFileNames );
207
209 mutable std::recursive_mutex m_reportMutex;
210
212 mutable std::recursive_mutex m_messageMapMutex;
213
216 mutable std::recursive_mutex m_thresholdMapMutex;
217 };
218
219 #endif
MessageSvc::m_defaultStream
std::ostream * m_defaultStream
Pointer to the output stream.
Definition: MessageSvc.h:176
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
MessageSvc::m_streamMap
StreamMap m_streamMap
Stream map.
Definition: MessageSvc.h:178
MessageSvc::MessageMap
std::multimap< StatusCode, Message > MessageMap
Definition: MessageSvc.h:34
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:352
MessageSvc::i_reportMessage
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition: MessageSvc.cpp:356
MessageSvc::setupInactCount
void setupInactCount(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:227
MessageSvc::m_sourceMap
std::map< std::string, MsgAry > m_sourceMap
Definition: MessageSvc.h:192
MessageSvc::m_defaultMessage
Message m_defaultMessage
Default Message.
Definition: MessageSvc.h:177
MessageSvc::m_inactiveMap
std::map< std::string, MsgAry > m_inactiveMap
Definition: MessageSvc.h:192
MessageSvc::m_messageMap
MessageMap m_messageMap
Message map.
Definition: MessageSvc.h:179
MessageSvc::setupLogStreams
void setupLogStreams()
Definition: MessageSvc.cpp:622
MessageSvc::m_defaultTimeFormat
Gaudi::Property< std::string > m_defaultTimeFormat
Definition: MessageSvc.h:131
MessageSvc::MessageSvc
MessageSvc(const std::string &name, ISvcLocator *svcloc)
Definition: MessageSvc.cpp:78
MessageSvc::m_messageMapMutex
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
Definition: MessageSvc.h:212
MessageSvc::reinitialize
StatusCode reinitialize() override
Reinitialize Service.
Definition: MessageSvc.cpp:123
std::map< std::string, int >
MessageSvc::eraseMessage
void eraseMessage() override
Definition: MessageSvc.cpp:534
MessageSvc::m_tracedInactiveSources
Gaudi::Property< std::vector< std::string > > m_tracedInactiveSources
Definition: MessageSvc.h:167
MessageSvc::setupColors
void setupColors(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:133
std::string
STL class.
MessageSvc::eraseStream
void eraseStream() override
Definition: MessageSvc.cpp:477
MessageSvc::incrInactiveCount
void incrInactiveCount(MSG::Level level, const std::string &src) override
Definition: MessageSvc.cpp:609
MessageSvc::m_loggedStreams
std::map< std::string, std::shared_ptr< std::ostream > > m_loggedStreams
Definition: MessageSvc.h:196
Service.h
MessageSvc::MsgAry
Private helper class to keep the count of messages of a type (MSG::LEVEL).
Definition: MessageSvc.h:185
MessageSvc::m_inactCount
Gaudi::Property< bool > m_inactCount
Definition: MessageSvc.h:165
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
MSG::Level
Level
Definition: IMessageSvc.h:15
MessageSvc::m_logColors
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_logColors
Definition: MessageSvc.h:146
MessageSvc::m_statLevel
Gaudi::Property< unsigned int > m_statLevel
Definition: MessageSvc.h:133
MessageSvc::useColor
bool useColor() const override
Definition: MessageSvc.h:111
MessageSvc::getLogColor
std::string getLogColor(int logLevel) const override
Definition: MessageSvc.cpp:600
MessageSvc::setOutputLevel
void setOutputLevel(int new_level) override
Definition: MessageSvc.cpp:580
MessageSvc::initialize
StatusCode initialize() override
Initialize Service.
Definition: MessageSvc.cpp:106
MessageSvc::m_thresholdMap
ThresholdMap m_thresholdMap
Output level threshold map.
Definition: MessageSvc.h:180
Message::getDefaultTimeFormat
static const std::string getDefaultTimeFormat()
Get the default time format string.
Definition: Message.cpp:165
MessageSvc::StreamMap
std::multimap< int, NamedStream > StreamMap
Definition: MessageSvc.h:33
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
gaudirun.type
type
Definition: gaudirun.py:142
MessageSvc::NamedStream
std::pair< std::string, std::ostream * > NamedStream
Definition: MessageSvc.h:32
Message::getDefaultFormat
static const std::string getDefaultFormat()
Get the default format string.
Definition: Message.cpp:134
std::recursive_mutex
MessageSvc::reportMessage
void reportMessage(const Message &message) override
Definition: MessageSvc.cpp:409
MessageSvc::m_color
Gaudi::Property< bool > m_color
Definition: MessageSvc.h:144
IMessageSvc.h
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
MessageSvc::m_defaultFormat
Gaudi::Property< std::string > m_defaultFormat
Definition: MessageSvc.h:130
MessageSvc::m_reportMutex
std::recursive_mutex m_reportMutex
Mutex to synchronize multiple threads printing.
Definition: MessageSvc.h:209
std::multimap< int, NamedStream >
std::pair
std::set< std::string >
MessageSvc::MsgAry::MsgAry
MsgAry()=default
Default constructor.
std::unique_lock
CommonMessagingBase::msg
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:113
Message
The Message class.
Definition: Message.h:17
MessageSvc::finalize
StatusCode finalize() override
Finalize Service.
Definition: MessageSvc.cpp:237
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
MSG::NUM_LEVELS
Definition: IMessageSvc.h:15
Property.h
MessageSvc::defaultStream
std::ostream * defaultStream() const override
Definition: MessageSvc.h:90
std::array
STL class.
MessageSvc::setupLimits
void setupLimits(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:175
MessageSvc::setupThreshold
void setupThreshold(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:195
MessageSvc::m_logColorCodes
std::string m_logColorCodes[MSG::NUM_LEVELS]
Definition: MessageSvc.h:182
MessageSvc::m_stats
Gaudi::Property< bool > m_stats
Definition: MessageSvc.h:132
MessageSvc::messageCount
int messageCount(MSG::Level logLevel) const override
Definition: MessageSvc.cpp:606
gaudirun.level
level
Definition: gaudirun.py:334
MessageSvc::m_msgCount
std::array< int, MSG::NUM_LEVELS > m_msgCount
Definition: MessageSvc.h:194
MessageSvc::m_thresholdProp
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_thresholdProp
Definition: MessageSvc.h:135
StatusCode.h
MessageSvc::m_msgLimit
std::array< Gaudi::Property< int >, MSG::NUM_LEVELS > m_msgLimit
Definition: MessageSvc.h:155
MessageSvc::outputLevel
int outputLevel() const override
Definition: MessageSvc.cpp:566
MessageSvc::tee
void tee(const std::string &sourceName, const std::string &logFileName, const std::set< std::string > &declaredOutFileNames)
Definition: MessageSvc.cpp:638
MessageSvc::m_suppress
Gaudi::Property< bool > m_suppress
Definition: MessageSvc.h:164
MessageSvc::insertMessage
void insertMessage(const StatusCode &code, const Message &message) override
Definition: MessageSvc.cpp:522
MessageSvc
Definition: MessageSvc.h:30
MessageSvc::m_loggedStreamsName
Gaudi::Property< std::map< std::string, std::string > > m_loggedStreamsName
Definition: MessageSvc.h:173
std::ostream
STL class.
MessageSvc::insertStream
void insertStream(int message_type, const std::string &name, std::ostream *stream) override
Definition: MessageSvc.cpp:466
MessageSvc::MsgAry::msg
std::array< int, MSG::NUM_LEVELS > msg
Internal array of counters.
Definition: MessageSvc.h:187
MessageSvc::setDefaultStream
void setDefaultStream(std::ostream *stream) override
Definition: MessageSvc.h:93
MessageSvc::ThresholdMap
std::map< std::string, int > ThresholdMap
Definition: MessageSvc.h:35
Message.h
MessageSvc::m_thresholdMapMutex
std::recursive_mutex m_thresholdMapMutex
Mutex to synchronize multiple access to m_thresholdMap (.
Definition: MessageSvc.h:216