The Gaudi Framework  v36r1 (3e2fb5a8)
MessageSvc.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDI_MESSAGESVC_H
12 #define GAUDI_MESSAGESVC_H
13 
14 // Include files
15 #include <iosfwd>
16 #include <map>
17 #include <memory>
18 #include <mutex>
19 #include <set>
20 #include <string>
21 #include <vector>
22 
24 #include "GaudiKernel/Message.h"
25 #include "GaudiKernel/Service.h"
26 #include "GaudiKernel/StatusCode.h"
27 #include <Gaudi/Property.h>
28 
29 // Forward declarations
30 class ISvcLocator;
31 
32 //
33 // ClassName: MessageSvc
34 //
35 // Description: The MessageSvc service implements the IMessageSvc interface and provides the
36 // basic messaging needed by batch oriented applications.
37 //
38 // Author: Iain Last
39 //
40 class MessageSvc : public extends<Service, IMessageSvc, IInactiveMessageCounter> {
41 public:
46 
47  // Default constructor.
48  MessageSvc( const std::string& name, ISvcLocator* svcloc );
49 
50  // Implementation of IService::reinitialize()
51  StatusCode reinitialize() override;
52  // Implementation of IService::initialize()
53  StatusCode initialize() override;
54  // Implementation of IService::finalize()
55  StatusCode finalize() override;
56 
57  // Implementation of IMessageSvc::reportMessage()
58  void reportMessage( const Message& message ) override;
59 
60  // Implementation of IMessageSvc::reportMessage()
61  void reportMessage( const Message& msg, int outputLevel ) override;
62 
63  // Implementation of IMessageSvc::reportMessage()
64  void reportMessage( const StatusCode& code, std::string_view source = "" ) override;
65 
66  // Implementation of IMessageSvc::reportMessage()
67  void reportMessage( std::string source, int type, std::string message ) override;
68 
69  // Implementation of IMessageSvc::insertMessage()
70  void insertMessage( const StatusCode& code, Message message ) override;
71 
72  // Implementation of IMessageSvc::eraseMessage()
73  void eraseMessage() override;
74 
75  // Implementation of IMessageSvc::eraseMessage()
76  void eraseMessage( const StatusCode& code ) override;
77 
78  // Implementation of IMessageSvc::eraseMessage()
79  void eraseMessage( const StatusCode& code, const Message& message ) override;
80 
81  // Implementation of IMessageSvc::insertStream()
82  void insertStream( int message_type, std::string name, std::ostream* stream ) override;
83 
84  // Implementation of IMessageSvc::eraseStream()
85  void eraseStream() override;
86 
87  // Implementation of IMessageSvc::eraseStream()
88  void eraseStream( int message_type ) override;
89 
90  // Implementation of IMessageSvc::eraseStream()
91  void eraseStream( int message_type, std::ostream* stream ) override;
92 
93  // Implementation of IMessageSvc::eraseStream()
94  void eraseStream( std::ostream* stream ) override;
95 
96  // Implementation of IMessageSvc::desaultStream()
97  std::ostream* defaultStream() const override { return m_defaultStream; }
98 
99  // Implementation of IMessageSvc::setDefaultStream()
101  auto lock = std::scoped_lock{m_reportMutex};
103  }
104 
105  // Implementation of IMessageSvc::ouputLevel()
106  int outputLevel() const override;
107 
108  // Implementation of IMessageSvc::ouputLevel()
109  int outputLevel( std::string_view source ) const override;
110 
111  // Implementation of IMessageSvc::setOuputLevel()
112  void setOutputLevel( int new_level ) override;
113 
114  // Implementation of IMessageSvc::setOuputLevel()
115  void setOutputLevel( std::string_view source, int new_level ) override;
116 
117  // Implementation of IMessageSvc::useColor()
118  bool useColor() const override { return m_color; }
119 
120  // Implementation of IMessageSvc::getLogColor()
121  std::string getLogColor( int logLevel ) const override;
122 
123  // Implementation of IMessageSvc::messageCount()
124  int messageCount( MSG::Level logLevel ) const override;
125 
126  // Implementation of IInactiveMessageCounter::incrInactiveCount()
127  void incrInactiveCount( MSG::Level level, std::string_view src ) override;
128 
129 protected:
131  virtual void i_reportMessage( const Message& msg, int outputLevel );
132 
134  virtual void i_reportMessage( const StatusCode& code, std::string_view source );
135 
136 private:
139  Gaudi::Property<bool> m_stats{this, "showStats", false, ""};
140  Gaudi::Property<unsigned int> m_statLevel{this, "statLevel", 0, ""};
141 
143  {this, "setVerbose"},
144  {this, "setDebug"},
145  {this, "setInfo"},
146  {this, "setWarning"},
147  {this, "setError"},
148  {this, "setFatal"},
149  {this, "setAlways"}}};
150 
151  Gaudi::Property<bool> m_color{this, "useColors", false, ""};
152 
154  {this, "verboseColorCode"},
155  {this, "debugColorCode"},
156  {this, "infoColorCode"},
157  {this, "warningColorCode"},
158  {this, "errorColorCode"},
159  {this, "fatalColorCode"},
160  {this, "alwaysColorCode"}}};
161 
163  {this, "verboseLimit", 500},
164  {this, "debugLimit", 500},
165  {this, "infoLimit", 500},
166  {this, "warningLimit", 500},
167  {this, "errorLimit", 500},
168  {this, "fatalLimit", 500},
169  {this, "alwaysLimit", 0}}};
170 
171  Gaudi::Property<bool> m_suppress{this, "enableSuppression", false, ""};
173 
175  this,
176  "tracedInactiveSources",
177  {},
178  "for each message source specified, print a stack trace for the unprotected and unseen messages"};
179 
181  this, "loggedStreams", {}, "MessageStream sources we want to dump into a logfile"};
182 
188 
190 
192  struct MsgAry final {
196  MsgAry() = default;
197  };
198 
200 
202 
204 
209 
210  void setupLogStreams();
211 
214 
217 
221 };
222 
223 #endif
MessageSvc::MsgAry::MsgAry
MsgAry()=default
Default constructor.
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: PropertyBase.h:35
GaudiHive.precedence.message
message
Definition: precedence.py:21
MessageSvc::reinitialize
StatusCode reinitialize() override
Reinitialize Service.
Definition: MessageSvc.cpp:127
MessageSvc::m_logColors
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_logColors
Definition: MessageSvc.h:153
Write.stream
stream
Definition: Write.py:31
MessageSvc::setupLimits
void setupLimits(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:179
std::string
STL class.
MessageSvc::m_stats
Gaudi::Property< bool > m_stats
Definition: MessageSvc.h:139
MessageSvc::MsgAry::msg
std::array< int, MSG::NUM_LEVELS > msg
Internal array of counters.
Definition: MessageSvc.h:194
std::pair
MessageSvc::MsgAry
Private helper class to keep the count of messages of a type (MSG::LEVEL).
Definition: MessageSvc.h:192
MessageSvc::m_defaultTimeFormat
Gaudi::Property< std::string > m_defaultTimeFormat
Definition: MessageSvc.h:138
MessageSvc::insertMessage
void insertMessage(const StatusCode &code, Message message) override
Definition: MessageSvc.cpp:516
ISvcLocator
Definition: ISvcLocator.h:46
MessageSvc::incrInactiveCount
void incrInactiveCount(MSG::Level level, std::string_view src) override
Definition: MessageSvc.cpp:603
MessageSvc::reportMessage
void reportMessage(const Message &message) override
Definition: MessageSvc.cpp:413
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:18
std::recursive_mutex
STL class.
MessageSvc::m_logColorCodes
std::string m_logColorCodes[MSG::NUM_LEVELS]
Definition: MessageSvc.h:189
MessageSvc::m_reportMutex
std::recursive_mutex m_reportMutex
Mutex to synchronize multiple threads printing.
Definition: MessageSvc.h:213
MessageSvc::i_reportMessage
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition: MessageSvc.cpp:360
MessageSvc::messageCount
int messageCount(MSG::Level logLevel) const override
Definition: MessageSvc.cpp:600
std::less
StatusCode.h
IMessageSvc.h
MessageSvc::m_streamMap
StreamMap m_streamMap
Stream map.
Definition: MessageSvc.h:185
MessageSvc::m_thresholdMapMutex
std::recursive_mutex m_thresholdMapMutex
Mutex to synchronize multiple access to m_thresholdMap (.
Definition: MessageSvc.h:220
Message::getDefaultFormat
static const std::string getDefaultFormat()
Get the default format string.
Definition: Message.cpp:144
MessageSvc::m_msgLimit
std::array< Gaudi::Property< int >, MSG::NUM_LEVELS > m_msgLimit
Definition: MessageSvc.h:162
MessageSvc::m_statLevel
Gaudi::Property< unsigned int > m_statLevel
Definition: MessageSvc.h:140
Service::name
const std::string & name() const override
Retrieve name of the service
Definition: Service.cpp:332
StatusCode
Definition: StatusCode.h:65
Message
Definition: Message.h:27
std::ostream
STL class.
MessageSvc::ThresholdMap
std::map< std::string, int, std::less<> > ThresholdMap
Definition: MessageSvc.h:45
MessageSvc::MessageMap
std::multimap< StatusCode, Message > MessageMap
Definition: MessageSvc.h:44
MessageSvc::m_sourceMap
std::map< std::string, MsgAry, std::less<> > m_sourceMap
Definition: MessageSvc.h:199
MessageSvc::m_msgCount
std::array< int, MSG::NUM_LEVELS > m_msgCount
Definition: MessageSvc.h:201
std::array
STL class.
MessageSvc::m_defaultMessage
Message m_defaultMessage
Default Message.
Definition: MessageSvc.h:184
MessageSvc::m_thresholdMap
ThresholdMap m_thresholdMap
Output level threshold map.
Definition: MessageSvc.h:187
std::map
STL class.
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
MessageSvc::m_defaultStream
std::ostream * m_defaultStream
Pointer to the output stream.
Definition: MessageSvc.h:183
MessageSvc::defaultStream
std::ostream * defaultStream() const override
Definition: MessageSvc.h:97
MessageSvc::m_messageMap
MessageMap m_messageMap
Message map.
Definition: MessageSvc.h:186
MessageSvc::setupThreshold
void setupThreshold(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:199
gaudirun.level
level
Definition: gaudirun.py:346
MessageSvc::m_tracedInactiveSources
Gaudi::Property< std::vector< std::string > > m_tracedInactiveSources
Definition: MessageSvc.h:174
MessageSvc::m_inactiveMap
std::map< std::string, MsgAry, std::less<> > m_inactiveMap
Definition: MessageSvc.h:199
MessageSvc::setDefaultStream
void setDefaultStream(std::ostream *stream) override
Definition: MessageSvc.h:100
MessageSvc
Definition: MessageSvc.h:40
Service.h
MessageSvc::outputLevel
int outputLevel() const override
Definition: MessageSvc.cpp:560
MessageSvc::finalize
StatusCode finalize() override
Finalize Service.
Definition: MessageSvc.cpp:241
MessageSvc::m_inactCount
Gaudi::Property< bool > m_inactCount
Definition: MessageSvc.h:172
MSG::Level
Level
Definition: IMessageSvc.h:25
gaudirun.type
type
Definition: gaudirun.py:154
MessageSvc::m_messageMapMutex
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
Definition: MessageSvc.h:216
MessageSvc::NamedStream
std::pair< std::string, std::ostream * > NamedStream
Definition: MessageSvc.h:42
MessageSvc::m_loggedStreamsName
Gaudi::Property< std::map< std::string, std::string, std::less<> > > m_loggedStreamsName
Definition: MessageSvc.h:180
MessageSvc::setupInactCount
void setupInactCount(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:231
MessageSvc::eraseMessage
void eraseMessage() override
Definition: MessageSvc.cpp:528
std::multimap< int, NamedStream >
MessageSvc::m_color
Gaudi::Property< bool > m_color
Definition: MessageSvc.h:151
MessageSvc::m_loggedStreams
std::map< std::string, std::shared_ptr< std::ostream >, std::less<> > m_loggedStreams
Definition: MessageSvc.h:203
MessageSvc::initialize
StatusCode initialize() override
Initialize Service.
Definition: MessageSvc.cpp:110
MessageSvc::getLogColor
std::string getLogColor(int logLevel) const override
Definition: MessageSvc.cpp:594
MessageSvc::eraseStream
void eraseStream() override
Definition: MessageSvc.cpp:471
MessageSvc::m_thresholdProp
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_thresholdProp
Definition: MessageSvc.h:142
MessageSvc::setupLogStreams
void setupLogStreams()
Definition: MessageSvc.cpp:619
MessageSvc::MessageSvc
MessageSvc(const std::string &name, ISvcLocator *svcloc)
Definition: MessageSvc.cpp:82
MessageSvc::m_suppress
Gaudi::Property< bool > m_suppress
Definition: MessageSvc.h:171
MSG::NUM_LEVELS
@ NUM_LEVELS
Definition: IMessageSvc.h:25
MessageSvc::StreamMap
std::multimap< int, NamedStream > StreamMap
Definition: MessageSvc.h:43
MessageSvc::insertStream
void insertStream(int message_type, std::string name, std::ostream *stream) override
Definition: MessageSvc.cpp:460
MessageSvc::useColor
bool useColor() const override
Definition: MessageSvc.h:118
MessageSvc::m_defaultFormat
Gaudi::Property< std::string > m_defaultFormat
Definition: MessageSvc.h:137
MessageSvc::setOutputLevel
void setOutputLevel(int new_level) override
Definition: MessageSvc.cpp:574
Gaudi::Property< std::string >
Property.h
Message.h
MessageSvc::setupColors
void setupColors(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:137
Message::getDefaultTimeFormat
static const std::string getDefaultTimeFormat()
Get the default time format string.
Definition: Message.cpp:175