| The Gaudi Framework v28r2p1 (f1a77ff4)

- 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 <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 {
32 public:
33 typedef std::pair<std::string, std::ostream*> NamedStream;
34 typedef std::multimap<int, NamedStream> StreamMap;
35 typedef std::multimap<StatusCode, Message> MessageMap;
36 typedef std::map<std::string, int> ThresholdMap;
37
38 // Default constructor.
39 MessageSvc( const std::string& name, ISvcLocator* svcloc );
40 // Destructor.
41 ~MessageSvc() override = default;
42
43 // Implementation of IService::reinitialize()
44 StatusCode reinitialize() override;
45 // Implementation of IService::initialize()
46 StatusCode initialize() override;
47 // Implementation of IService::finalize()
48 StatusCode finalize() override;
49
50 // Implementation of IMessageSvc::reportMessage()
51 void reportMessage( const Message& message ) override;
52
53 // Implementation of IMessageSvc::reportMessage()
54 void reportMessage( const Message& msg, int outputLevel ) override;
55
56 // Implementation of IMessageSvc::reportMessage()
57 void reportMessage( const StatusCode& code, const std::string& source = "" ) override;
58
59 // Implementation of IMessageSvc::reportMessage()
60 void reportMessage( const char* source, int type, const char* message ) override;
61
62 // Implementation of IMessageSvc::reportMessage()
63 void reportMessage( const std::string& source, int type, const std::string& message ) override;
64
65 // Implementation of IMessageSvc::insertMessage()
66 void insertMessage( const StatusCode& code, const Message& message ) override;
67
68 // Implementation of IMessageSvc::eraseMessage()
69 void eraseMessage() override;
70
71 // Implementation of IMessageSvc::eraseMessage()
72 void eraseMessage( const StatusCode& code ) override;
73
74 // Implementation of IMessageSvc::eraseMessage()
75 void eraseMessage( const StatusCode& code, const Message& message ) override;
76
77 // Implementation of IMessageSvc::insertStream()
78 void insertStream( int message_type, const std::string& name, std::ostream* stream ) override;
79
80 // Implementation of IMessageSvc::eraseStream()
81 void eraseStream() override;
82
83 // Implementation of IMessageSvc::eraseStream()
84 void eraseStream( int message_type ) override;
85
86 // Implementation of IMessageSvc::eraseStream()
87 void eraseStream( int message_type, std::ostream* stream ) override;
88
89 // Implementation of IMessageSvc::eraseStream()
90 void eraseStream( std::ostream* stream ) override;
91
92 // Implementation of IMessageSvc::desaultStream()
93 std::ostream* defaultStream() const override { return m_defaultStream; }
94
95 // Implementation of IMessageSvc::setDefaultStream()
96 void setDefaultStream( std::ostream* stream ) override
97 {
98 std::unique_lock<std::recursive_mutex> lock( m_reportMutex );
99 m_defaultStream = stream;
100 }
101
102 // Implementation of IMessageSvc::ouputLevel()
103 int outputLevel() const override;
104
105 // Implementation of IMessageSvc::ouputLevel()
106 int outputLevel( const std::string& source ) const override;
107
108 // Implementation of IMessageSvc::setOuputLevel()
109 void setOutputLevel( int new_level ) override;
110
111 // Implementation of IMessageSvc::setOuputLevel()
112 void setOutputLevel( const std::string& source, int new_level ) override;
113
114 // Implementation of IMessageSvc::useColor()
115 bool useColor() const override { return m_color; }
116
117 // Implementation of IMessageSvc::getLogColor()
118 std::string getLogColor( int logLevel ) const override;
119
120 // Implementation of IMessageSvc::messageCount()
121 int messageCount( MSG::Level logLevel ) const override;
122
123 // Implementation of IInactiveMessageCounter::incrInactiveCount()
124 void incrInactiveCount( MSG::Level level, const std::string& src ) override;
125
126 protected:
128 virtual void i_reportMessage( const Message& msg, int outputLevel );
129
131 virtual void i_reportMessage( const StatusCode& code, const std::string& source );
132
133 private:
134 Gaudi::Property<std::string> m_defaultFormat{this, "Format", Message::getDefaultFormat(), ""};
135 Gaudi::Property<std::string> m_defaultTimeFormat{this, "timeFormat", Message::getDefaultTimeFormat(), ""};
136 Gaudi::Property<bool> m_stats{this, "showStats", false, ""};
137 Gaudi::Property<unsigned int> m_statLevel{this, "statLevel", 0, ""};
138
139 std::array<Gaudi::Property<std::vector<std::string>>, MSG::NUM_LEVELS> m_thresholdProp{{{/*ignored*/},
140 {this, "setVerbose"},
141 {this, "setDebug"},
142 {this, "setInfo"},
143 {this, "setWarning"},
144 {this, "setError"},
145 {this, "setFatal"},
146 {this, "setAlways"}}};
147
148 Gaudi::Property<bool> m_color{this, "useColors", false, ""};
149
150 std::array<Gaudi::Property<std::vector<std::string>>, MSG::NUM_LEVELS> m_logColors{{{/*ignored*/},
151 {this, "verboseColorCode"},
152 {this, "debugColorCode"},
153 {this, "infoColorCode"},
154 {this, "warningColorCode"},
155 {this, "errorColorCode"},
156 {this, "fatalColorCode"},
157 {this, "alwaysColorCode"}}};
158
159 std::array<Gaudi::Property<int>, MSG::NUM_LEVELS> m_msgLimit{{{this, "defaultLimit", 500},
160 {this, "verboseLimit", 500},
161 {this, "debugLimit", 500},
162 {this, "infoLimit", 500},
163 {this, "warningLimit", 500},
164 {this, "errorLimit", 500},
165 {this, "fatalLimit", 500},
166 {this, "alwaysLimit", 0}}};
167
168 Gaudi::Property<bool> m_suppress{this, "enableSuppression", false, ""};
169 Gaudi::Property<bool> m_inactCount{this, "countInactive", false, ""};
170
171 Gaudi::Property<std::vector<std::string>> m_tracedInactiveSources{
172 this,
173 "tracedInactiveSources",
174 {},
175 "for each message source specified, print a stack trace for the unprotected and unseen messages"};
176
177 Gaudi::Property<std::map<std::string, std::string>> m_loggedStreamsName{
178 this, "loggedStreams", {}, "MessageStream sources we want to dump into a logfile"};
179
180 std::ostream* m_defaultStream = &std::cout;
181 Message m_defaultMessage;
182 StreamMap m_streamMap;
183 MessageMap m_messageMap;
184 ThresholdMap m_thresholdMap;
185
186 std::string m_logColorCodes[MSG::NUM_LEVELS];
187
189 struct MsgAry final {
191 std::array<int, MSG::NUM_LEVELS> msg = {{0}};
193 MsgAry() = default;
194 };
195
196 std::map<std::string, MsgAry> m_sourceMap, m_inactiveMap;
197
198 std::array<int, MSG::NUM_LEVELS> m_msgCount;
199
200 std::map<std::string, std::shared_ptr<std::ostream>> m_loggedStreams;
201
202 void setupColors( Gaudi::Details::PropertyBase& prop );
203 void setupLimits( Gaudi::Details::PropertyBase& prop );
204 void setupThreshold( Gaudi::Details::PropertyBase& prop );
205 void setupInactCount( Gaudi::Details::PropertyBase& prop );
206
207 void setupLogStreams();
208
209 void tee( const std::string& sourceName, const std::string& logFileName,
210 const std::set<std::string>& declaredOutFileNames );
211
213 mutable std::recursive_mutex m_reportMutex;
214
216 mutable std::recursive_mutex m_messageMapMutex;
217
220 mutable std::recursive_mutex m_thresholdMapMutex;
221 };
222
223 #endif
CommonMessagingBase::msg
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:132
MessageSvc::useColor
bool useColor() const override
Definition: MessageSvc.h:115
MessageSvc::m_defaultStream
std::ostream * m_defaultStream
Pointer to the output stream.
Definition: MessageSvc.h:180
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:289
MessageSvc::m_streamMap
StreamMap m_streamMap
Stream map.
Definition: MessageSvc.h:182
MessageSvc::MessageMap
std::multimap< StatusCode, Message > MessageMap
Definition: MessageSvc.h:35
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:314
MessageSvc::getLogColor
std::string getLogColor(int logLevel) const override
Definition: MessageSvc.cpp:614
MessageSvc::i_reportMessage
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition: MessageSvc.cpp:350
MessageSvc::setupInactCount
void setupInactCount(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:216
MessageSvc::m_sourceMap
std::map< std::string, MsgAry > m_sourceMap
Definition: MessageSvc.h:196
MessageSvc::m_defaultMessage
Message m_defaultMessage
Default Message.
Definition: MessageSvc.h:181
MessageSvc::m_inactiveMap
std::map< std::string, MsgAry > m_inactiveMap
Definition: MessageSvc.h:196
MessageSvc::m_messageMap
MessageMap m_messageMap
Message map.
Definition: MessageSvc.h:183
MessageSvc::setupLogStreams
void setupLogStreams()
Definition: MessageSvc.cpp:638
MessageSvc::m_defaultTimeFormat
Gaudi::Property< std::string > m_defaultTimeFormat
Definition: MessageSvc.h:135
MessageSvc::MessageSvc
MessageSvc(const std::string &name, ISvcLocator *svcloc)
Definition: MessageSvc.cpp:73
MessageSvc::m_messageMapMutex
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
Definition: MessageSvc.h:216
MessageSvc::reinitialize
StatusCode reinitialize() override
Reinitialize Service.
Definition: MessageSvc.cpp:116
std::map< std::string, int >
MessageSvc::eraseMessage
void eraseMessage() override
Definition: MessageSvc.cpp:541
MessageSvc::m_tracedInactiveSources
Gaudi::Property< std::vector< std::string > > m_tracedInactiveSources
Definition: MessageSvc.h:171
MessageSvc::setupColors
void setupColors(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:124
std::string
STL class.
MessageSvc::eraseStream
void eraseStream() override
Definition: MessageSvc.cpp:481
MessageSvc::incrInactiveCount
void incrInactiveCount(MSG::Level level, const std::string &src) override
Definition: MessageSvc.cpp:624
MessageSvc::m_loggedStreams
std::map< std::string, std::shared_ptr< std::ostream > > m_loggedStreams
Definition: MessageSvc.h:200
Service.h
MessageSvc::MsgAry
Private helper class to keep the count of messages of a type (MSG::LEVEL).
Definition: MessageSvc.h:189
MessageSvc::m_inactCount
Gaudi::Property< bool > m_inactCount
Definition: MessageSvc.h:169
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:150
MessageSvc::m_statLevel
Gaudi::Property< unsigned int > m_statLevel
Definition: MessageSvc.h:137
MessageSvc::setOutputLevel
void setOutputLevel(int new_level) override
Definition: MessageSvc.cpp:592
MessageSvc::initialize
StatusCode initialize() override
Initialize Service.
Definition: MessageSvc.cpp:98
MessageSvc::m_thresholdMap
ThresholdMap m_thresholdMap
Output level threshold map.
Definition: MessageSvc.h:184
Message::getDefaultTimeFormat
static const std::string getDefaultTimeFormat()
Get the default time format string.
Definition: Message.cpp:226
MessageSvc::StreamMap
std::multimap< int, NamedStream > StreamMap
Definition: MessageSvc.h:34
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
gaudirun.type
type
Definition: gaudirun.py:125
MessageSvc::NamedStream
std::pair< std::string, std::ostream * > NamedStream
Definition: MessageSvc.h:33
Message::getDefaultFormat
static const std::string getDefaultFormat()
Get the default format string.
Definition: Message.cpp:187
std::recursive_mutex
MessageSvc::reportMessage
void reportMessage(const Message &message) override
Definition: MessageSvc.cpp:408
MessageSvc::m_color
Gaudi::Property< bool > m_color
Definition: MessageSvc.h:148
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:134
MessageSvc::m_reportMutex
std::recursive_mutex m_reportMutex
Mutex to synchronize multiple threads printing.
Definition: MessageSvc.h:213
std::multimap< int, NamedStream >
std::pair
std::set< std::string >
MessageSvc::MsgAry::MsgAry
MsgAry()=default
Default constructor.
std::unique_lock
Message
The Message class.
Definition: Message.h:15
MessageSvc::defaultStream
std::ostream * defaultStream() const override
Definition: MessageSvc.h:93
MessageSvc::finalize
StatusCode finalize() override
Finalize Service.
Definition: MessageSvc.cpp:227
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
Property.h
MessageSvc::outputLevel
int outputLevel() const override
Definition: MessageSvc.cpp:576
std::array
STL class.
MessageSvc::setupLimits
void setupLimits(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:160
MessageSvc::setupThreshold
void setupThreshold(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:183
MessageSvc::m_logColorCodes
std::string m_logColorCodes[MSG::NUM_LEVELS]
Definition: MessageSvc.h:186
MessageSvc::m_stats
Gaudi::Property< bool > m_stats
Definition: MessageSvc.h:136
gaudirun.level
level
Definition: gaudirun.py:261
MessageSvc::m_msgCount
std::array< int, MSG::NUM_LEVELS > m_msgCount
Definition: MessageSvc.h:198
MessageSvc::m_thresholdProp
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_thresholdProp
Definition: MessageSvc.h:139
StatusCode.h
MessageSvc::m_msgLimit
std::array< Gaudi::Property< int >, MSG::NUM_LEVELS > m_msgLimit
Definition: MessageSvc.h:159
MessageSvc::tee
void tee(const std::string &sourceName, const std::string &logFileName, const std::set< std::string > &declaredOutFileNames)
Definition: MessageSvc.cpp:657
MessageSvc::m_suppress
Gaudi::Property< bool > m_suppress
Definition: MessageSvc.h:168
MessageSvc::insertMessage
void insertMessage(const StatusCode &code, const Message &message) override
Definition: MessageSvc.cpp:528
MessageSvc
Definition: MessageSvc.h:30
MessageSvc::m_loggedStreamsName
Gaudi::Property< std::map< std::string, std::string > > m_loggedStreamsName
Definition: MessageSvc.h:177
std::ostream
STL class.
MessageSvc::insertStream
void insertStream(int message_type, const std::string &name, std::ostream *stream) override
Definition: MessageSvc.cpp:469
MessageSvc::setDefaultStream
void setDefaultStream(std::ostream *stream) override
Definition: MessageSvc.h:96
MessageSvc::messageCount
int messageCount(MSG::Level logLevel) const override
Definition: MessageSvc.cpp:621
MessageSvc::ThresholdMap
std::map< std::string, int > ThresholdMap
Definition: MessageSvc.h:36
Message.h
MessageSvc::m_thresholdMapMutex
std::recursive_mutex m_thresholdMapMutex
Mutex to synchronize multiple access to m_thresholdMap (.
Definition: MessageSvc.h:220