The Gaudi Framework  v33r0 (d5ea422b)
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/Property.h"
26 #include "GaudiKernel/Service.h"
27 #include "GaudiKernel/StatusCode.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, const std::string& source = "" ) override;
65 
66  // Implementation of IMessageSvc::reportMessage()
67  void reportMessage( const char* source, int type, const char* message ) override;
68 
69  // Implementation of IMessageSvc::reportMessage()
70  void reportMessage( const std::string& source, int type, const std::string& message ) override;
71 
72  // Implementation of IMessageSvc::insertMessage()
73  void insertMessage( const StatusCode& code, const Message& message ) override;
74 
75  // Implementation of IMessageSvc::eraseMessage()
76  void eraseMessage() override;
77 
78  // Implementation of IMessageSvc::eraseMessage()
79  void eraseMessage( const StatusCode& code ) override;
80 
81  // Implementation of IMessageSvc::eraseMessage()
82  void eraseMessage( const StatusCode& code, const Message& message ) override;
83 
84  // Implementation of IMessageSvc::insertStream()
85  void insertStream( int message_type, const std::string& name, std::ostream* stream ) override;
86 
87  // Implementation of IMessageSvc::eraseStream()
88  void eraseStream() override;
89 
90  // Implementation of IMessageSvc::eraseStream()
91  void eraseStream( int message_type ) override;
92 
93  // Implementation of IMessageSvc::eraseStream()
94  void eraseStream( int message_type, std::ostream* stream ) override;
95 
96  // Implementation of IMessageSvc::eraseStream()
97  void eraseStream( std::ostream* stream ) override;
98 
99  // Implementation of IMessageSvc::desaultStream()
100  std::ostream* defaultStream() const override { return m_defaultStream; }
101 
102  // Implementation of IMessageSvc::setDefaultStream()
103  void setDefaultStream( std::ostream* stream ) override {
105  m_defaultStream = stream;
106  }
107 
108  // Implementation of IMessageSvc::ouputLevel()
109  int outputLevel() const override;
110 
111  // Implementation of IMessageSvc::ouputLevel()
112  int outputLevel( const std::string& source ) const override;
113 
114  // Implementation of IMessageSvc::setOuputLevel()
115  void setOutputLevel( int new_level ) override;
116 
117  // Implementation of IMessageSvc::setOuputLevel()
118  void setOutputLevel( const std::string& source, int new_level ) override;
119 
120  // Implementation of IMessageSvc::useColor()
121  bool useColor() const override { return m_color; }
122 
123  // Implementation of IMessageSvc::getLogColor()
124  std::string getLogColor( int logLevel ) const override;
125 
126  // Implementation of IMessageSvc::messageCount()
127  int messageCount( MSG::Level logLevel ) const override;
128 
129  // Implementation of IInactiveMessageCounter::incrInactiveCount()
130  void incrInactiveCount( MSG::Level level, const std::string& src ) override;
131 
132 protected:
134  virtual void i_reportMessage( const Message& msg, int outputLevel );
135 
137  virtual void i_reportMessage( const StatusCode& code, const std::string& source );
138 
139 private:
142  Gaudi::Property<bool> m_stats{this, "showStats", false, ""};
143  Gaudi::Property<unsigned int> m_statLevel{this, "statLevel", 0, ""};
144 
146  {this, "setVerbose"},
147  {this, "setDebug"},
148  {this, "setInfo"},
149  {this, "setWarning"},
150  {this, "setError"},
151  {this, "setFatal"},
152  {this, "setAlways"}}};
153 
154  Gaudi::Property<bool> m_color{this, "useColors", false, ""};
155 
157  {this, "verboseColorCode"},
158  {this, "debugColorCode"},
159  {this, "infoColorCode"},
160  {this, "warningColorCode"},
161  {this, "errorColorCode"},
162  {this, "fatalColorCode"},
163  {this, "alwaysColorCode"}}};
164 
166  {this, "verboseLimit", 500},
167  {this, "debugLimit", 500},
168  {this, "infoLimit", 500},
169  {this, "warningLimit", 500},
170  {this, "errorLimit", 500},
171  {this, "fatalLimit", 500},
172  {this, "alwaysLimit", 0}}};
173 
174  Gaudi::Property<bool> m_suppress{this, "enableSuppression", false, ""};
176 
178  this,
179  "tracedInactiveSources",
180  {},
181  "for each message source specified, print a stack trace for the unprotected and unseen messages"};
182 
184  this, "loggedStreams", {}, "MessageStream sources we want to dump into a logfile"};
185 
191 
193 
195  struct MsgAry final {
199  MsgAry() = default;
200  };
201 
203 
205 
207 
212 
213  void setupLogStreams();
214 
215  void tee( const std::string& sourceName, const std::string& logFileName,
216  const std::set<std::string>& declaredOutFileNames );
217 
220 
223 
227 };
228 
229 #endif
std::ostream * m_defaultStream
Pointer to the output stream.
Definition: MessageSvc.h:186
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:35
StreamMap m_streamMap
Stream map.
Definition: MessageSvc.h:188
std::multimap< StatusCode, Message > MessageMap
Definition: MessageSvc.h:44
Implementation of property with value of concrete type.
Definition: Property.h:370
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition: MessageSvc.cpp:366
void setupInactCount(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:237
std::map< std::string, MsgAry > m_sourceMap
Definition: MessageSvc.h:202
Message m_defaultMessage
Default Message.
Definition: MessageSvc.h:187
std::map< std::string, MsgAry > m_inactiveMap
Definition: MessageSvc.h:202
MessageMap m_messageMap
Message map.
Definition: MessageSvc.h:189
void setupLogStreams()
Definition: MessageSvc.cpp:632
Gaudi::Property< std::string > m_defaultTimeFormat
Definition: MessageSvc.h:141
MessageSvc(const std::string &name, ISvcLocator *svcloc)
Definition: MessageSvc.cpp:88
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
Definition: MessageSvc.h:222
StatusCode reinitialize() override
Reinitialize Service.
Definition: MessageSvc.cpp:133
void eraseMessage() override
Definition: MessageSvc.cpp:544
Gaudi::Property< std::vector< std::string > > m_tracedInactiveSources
Definition: MessageSvc.h:177
void setupColors(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:143
STL class.
void eraseStream() override
Definition: MessageSvc.cpp:487
void incrInactiveCount(MSG::Level level, const std::string &src) override
Definition: MessageSvc.cpp:619
std::map< std::string, std::shared_ptr< std::ostream > > m_loggedStreams
Definition: MessageSvc.h:206
Private helper class to keep the count of messages of a type (MSG::LEVEL).
Definition: MessageSvc.h:195
Gaudi::Property< bool > m_inactCount
Definition: MessageSvc.h:175
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_logColors
Definition: MessageSvc.h:156
Gaudi::Property< unsigned int > m_statLevel
Definition: MessageSvc.h:143
bool useColor() const override
Definition: MessageSvc.h:121
std::string getLogColor(int logLevel) const override
Definition: MessageSvc.cpp:610
void setOutputLevel(int new_level) override
Definition: MessageSvc.cpp:590
StatusCode initialize() override
Initialize Service.
Definition: MessageSvc.cpp:116
ThresholdMap m_thresholdMap
Output level threshold map.
Definition: MessageSvc.h:190
static const std::string getDefaultTimeFormat()
Get the default time format string.
Definition: Message.cpp:175
std::multimap< int, NamedStream > StreamMap
Definition: MessageSvc.h:43
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
std::pair< std::string, std::ostream * > NamedStream
Definition: MessageSvc.h:42
static const std::string getDefaultFormat()
Get the default format string.
Definition: Message.cpp:144
void reportMessage(const Message &message) override
Definition: MessageSvc.cpp:419
Gaudi::Property< bool > m_color
Definition: MessageSvc.h:154
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:42
Gaudi::Property< std::string > m_defaultFormat
Definition: MessageSvc.h:140
std::recursive_mutex m_reportMutex
Mutex to synchronize multiple threads printing.
Definition: MessageSvc.h:219
MsgAry()=default
Default constructor.
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
The Message class.
Definition: Message.h:27
StatusCode finalize() override
Finalize Service.
Definition: MessageSvc.cpp:247
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
std::ostream * defaultStream() const override
Definition: MessageSvc.h:100
STL class.
void setupLimits(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:185
void setupThreshold(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:205
std::string m_logColorCodes[MSG::NUM_LEVELS]
Definition: MessageSvc.h:192
Gaudi::Property< bool > m_stats
Definition: MessageSvc.h:142
int messageCount(MSG::Level logLevel) const override
Definition: MessageSvc.cpp:616
std::array< int, MSG::NUM_LEVELS > m_msgCount
Definition: MessageSvc.h:204
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_thresholdProp
Definition: MessageSvc.h:145
std::array< Gaudi::Property< int >, MSG::NUM_LEVELS > m_msgLimit
Definition: MessageSvc.h:165
int outputLevel() const override
Definition: MessageSvc.cpp:576
void tee(const std::string &sourceName, const std::string &logFileName, const std::set< std::string > &declaredOutFileNames)
Definition: MessageSvc.cpp:648
Gaudi::Property< bool > m_suppress
Definition: MessageSvc.h:174
void insertMessage(const StatusCode &code, const Message &message) override
Definition: MessageSvc.cpp:532
Gaudi::Property< std::map< std::string, std::string > > m_loggedStreamsName
Definition: MessageSvc.h:183
STL class.
void insertStream(int message_type, const std::string &name, std::ostream *stream) override
Definition: MessageSvc.cpp:476
std::array< int, MSG::NUM_LEVELS > msg
Internal array of counters.
Definition: MessageSvc.h:197
void setDefaultStream(std::ostream *stream) override
Definition: MessageSvc.h:103
std::map< std::string, int > ThresholdMap
Definition: MessageSvc.h:45
std::recursive_mutex m_thresholdMapMutex
Mutex to synchronize multiple access to m_thresholdMap (.
Definition: MessageSvc.h:226