ATLAS Offline Software
LoggedMessageSvc.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ATHENASERVICES_LOGGEDMESSAGESVC_H
6 #define ATHENASERVICES_LOGGEDMESSAGESVC_H 1
7 
8 // Include files
9 #include <string>
10 #include <vector>
11 #include <map>
12 #include <set>
13 #include <iosfwd>
14 #include <mutex>
15 
16 #include "GaudiKernel/StatusCode.h"
17 #include "GaudiKernel/Service.h"
18 #include "GaudiKernel/IMessageSvc.h"
19 #include "GaudiKernel/Message.h"
20 #include "Gaudi/Property.h"
24 
25 // Forward declarations
26 class ISvcLocator;
27 
28 //
29 // ClassName: LoggedMessageSvc
30 //
31 // Description: The LoggedMessageSvc service implements the IMessageSvc
32 // interface, extending the MessageSvc to include logging of
33 // all messages above a user defined threshold.
34 //
35 // Author: Charles Leggett
36 //
38  public extends<AthService, ILoggedMessageSvc, IInactiveMessageCounter> {
39 
40 public:
41  typedef std::pair< std::string, std::ostream* > NamedStream;
42  typedef std::multimap< int, NamedStream > StreamMap;
43  typedef std::multimap< StatusCode, Message > MessageMap;
44  typedef std::map< std::string, int, std::less<> > ThresholdMap;
45 
46  // Default constructor.
47  LoggedMessageSvc( const std::string& name, ISvcLocator* svcloc );
48  // Destructor.
49  virtual ~LoggedMessageSvc();
50 
51  // Implementation of IService::reinitialize()
52  virtual StatusCode reinitialize() override;
53  // Implementation of IService::initialize()
54  virtual StatusCode initialize() override;
55  // Implementation of IService::finalize()
56  virtual StatusCode finalize() override;
57 
58  // Implementation of IMessageSvc::reportMessage()
59  virtual void reportMessage( const Message& message ) override;
60 
61  // Implementation of IMessageSvc::reportMessage()
62  virtual void reportMessage( const Message& msg, int outputLevel ) override;
63 
64  // Implementation of IMessageSvc::reportMessage()
65  virtual void reportMessage( const StatusCode& code, std::string_view source = "") override;
66 
67  // Implementation of IMessageSvc::reportMessage()
68  virtual void reportMessage( std::string source, int type, std::string message) override;
69 
70  // Implementation of IMessageSvc::insertMessage()
71  virtual void insertMessage( const StatusCode& code, Message message ) override;
72 
73  // Implementation of IMessageSvc::eraseMessage()
74  virtual void eraseMessage() override;
75 
76  // Implementation of IMessageSvc::eraseMessage()
77  virtual void eraseMessage( const StatusCode& code ) override;
78 
79  // Implementation of IMessageSvc::eraseMessage()
80  virtual void eraseMessage( const StatusCode& code, const Message& message ) override;
81 
82  // Implementation of IMessageSvc::insertStream()
83  virtual void insertStream( int message_type, std::string name, std::ostream* stream ) override;
84 
85  // Implementation of IMessageSvc::eraseStream()
86  virtual void eraseStream() override;
87 
88  // Implementation of IMessageSvc::eraseStream()
89  virtual void eraseStream( int message_type ) override;
90 
91  // Implementation of IMessageSvc::eraseStream()
92  virtual void eraseStream( int message_type, std::ostream* stream ) override;
93 
94  // Implementation of IMessageSvc::eraseStream()
95  virtual void eraseStream( std::ostream* stream ) override;
96 
97  // Implementation of IMessageSvc::defaultStream()
98  virtual std::ostream* defaultStream ATLAS_NOT_CONST_THREAD_SAFE () const override {
99  return m_defaultStream;
100  }
101 
102  // Implementation of IMessageSvc::setDefaultStream()
103  virtual void setDefaultStream( std::ostream* stream ) override {
104  std::lock_guard<std::mutex> lock(m_reportMutex);
106  }
107 
108  // Implementation of IMessageSvc::ouputLevel()
109  virtual int outputLevel() const override;
110 
111  // Implementation of IMessageSvc::ouputLevel()
112  virtual int outputLevel(std::string_view source) const override;
113 
114  // Implementation of IMessageSvc::setOuputLevel()
115  virtual void setOutputLevel(int new_level) override;
116 
117  // Implementation of IMessageSvc::setOuputLevel()
118  virtual void setOutputLevel(std::string_view source, int new_level) override;
119 
120  // Implementation of IMessageSvc::useColor()
121  virtual bool useColor() const override { return m_color; }
122 
123  // Implementation of IMessageSvc::getLogColor()
124  virtual std::string getLogColor(int logLevel) const override;
125 
126  // Implementation of IMessageSvc::messageCount()
127  virtual int messageCount( MSG::Level logLevel ) const override;
128 
129  // Implementation of IInactiveMessageCounter::incrInactiveCount()
130  virtual void incrInactiveCount( MSG::Level level,
131  std::string_view src ) override;
132 
133  virtual const std::vector< std::pair<std::string, std::string> >& getMessages( MSG::Level level) const override;
134 
135  virtual const std::vector< LoggedMessage >& getKeyMessages() const override { return m_msgKeyLog; }
136 
137 private:
138  std::ostream* m_defaultStream;
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  IntegerProperty m_logLevel;
152  StringArrayProperty m_keywords;
153 
155 
157  struct MsgAry final {
159  std::array<int, MSG::NUM_LEVELS> msg = {{0}};
161  MsgAry() = default;
162  };
163 
164  std::map<std::string, MsgAry, std::less<>> m_sourceMap, m_inactiveMap;
165  BooleanProperty m_suppress, m_inactCount;
166 
167  std::string colTrans(const std::string&, int);
168  typedef std::map<std::string, MSG::Color> ColorMap;
170 
172 
173  std::map<std::string, std::string> m_loggedStreamsName;
174  typedef std::map<std::string, std::ostream*> LoggedStreamsMap_t;
176 
177  void initColors(Gaudi::Details::PropertyBase& prop);
178  void setupColors(Gaudi::Details::PropertyBase& prop);
179  void setupLimits(Gaudi::Details::PropertyBase& prop);
180  void setupThreshold(Gaudi::Details::PropertyBase& prop);
181  void setupInactCount(Gaudi::Details::PropertyBase& prop);
182 
183  void setupLogStreams();
184 
185  void tee( const std::string& sourceName, const std::string& logFileName,
186  const std::set<std::string>& declaredOutFileNames );
187 
190 
192  mutable std::recursive_mutex m_messageMapMutex;
193 
197 
198  std::vector< std::pair<std::string, std::string> > m_msgLog[ MSG::NUM_LEVELS ];
199  std::vector< LoggedMessage > m_msgKeyLog;
201 
202 };
203 
204 #endif
LoggedMessageSvc::m_logColors
StringArrayProperty m_logColors[MSG::NUM_LEVELS]
Definition: LoggedMessageSvc.h:149
LoggedMessageSvc::insertStream
virtual void insertStream(int message_type, std::string name, std::ostream *stream) override
Definition: LoggedMessageSvc.cxx:657
LoggedMessageSvc::m_msgKeyLog
std::vector< LoggedMessage > m_msgKeyLog
Definition: LoggedMessageSvc.h:199
LoggedMessageSvc::LoggedStreamsMap_t
std::map< std::string, std::ostream * > LoggedStreamsMap_t
Definition: LoggedMessageSvc.h:174
LoggedMessageSvc::useColor
virtual bool useColor() const override
Definition: LoggedMessageSvc.h:121
LoggedMessageSvc::MsgAry::msg
std::array< int, MSG::NUM_LEVELS > msg
Internal array of counters.
Definition: LoggedMessageSvc.h:159
LoggedMessageSvc::finalize
virtual StatusCode finalize() override
Finalize Service.
Definition: LoggedMessageSvc.cxx:348
LoggedMessageSvc::m_colMap
ColorMap m_colMap
Definition: LoggedMessageSvc.h:169
LoggedMessageSvc::insertMessage
virtual void insertMessage(const StatusCode &code, Message message) override
Definition: LoggedMessageSvc.cxx:746
WriteCellNoiseToCool.src
src
Definition: WriteCellNoiseToCool.py:513
LoggedMessageSvc::m_color
BooleanProperty m_color
Definition: LoggedMessageSvc.h:146
LoggedMessageSvc::m_keysUsed
bool m_keysUsed
Definition: LoggedMessageSvc.h:200
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
LoggedMessageSvc::m_msgLog
std::vector< std::pair< std::string, std::string > > m_msgLog[MSG::NUM_LEVELS]
Definition: LoggedMessageSvc.h:198
LoggedMessageSvc::m_defaultMessage
Message m_defaultMessage
Default Message.
Definition: LoggedMessageSvc.h:139
python.TrigPSCPythonDbSetup.logLevel
logLevel
If HLT PSK is set on command line read it from DB instead of COOL (ATR-25974)
Definition: TrigPSCPythonDbSetup.py:27
LoggedMessageSvc::initColors
void initColors(Gaudi::Details::PropertyBase &prop)
Definition: LoggedMessageSvc.cxx:151
LoggedMessageSvc::outputLevel
virtual int outputLevel() const override
Definition: LoggedMessageSvc.cxx:809
LoggedMessageSvc::ColorMap
std::map< std::string, MSG::Color > ColorMap
Definition: LoggedMessageSvc.h:168
LoggedMessageSvc::incrInactiveCount
virtual void incrInactiveCount(MSG::Level level, std::string_view src) override
Definition: LoggedMessageSvc.cxx:862
LoggedMessageSvc::m_loggedStreams
LoggedStreamsMap_t m_loggedStreams
Definition: LoggedMessageSvc.h:175
LoggedMessageSvc::MsgAry
Private helper class to keep the count of messages of a type (MSG::LEVEL).
Definition: LoggedMessageSvc.h:157
ReweightUtils.message
message
Definition: ReweightUtils.py:15
LoggedMessageSvc::m_stats
BooleanProperty m_stats
Definition: LoggedMessageSvc.h:147
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
LoggedMessageSvc::ThresholdMap
std::map< std::string, int, std::less<> > ThresholdMap
Definition: LoggedMessageSvc.h:44
LoggedMessageSvc::setDefaultStream
virtual void setDefaultStream(std::ostream *stream) override
Definition: LoggedMessageSvc.h:103
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
LoggedMessageSvc::m_inactiveMap
std::map< std::string, MsgAry, std::less<> > m_inactiveMap
Definition: LoggedMessageSvc.h:164
LoggedMessageSvc
Definition: LoggedMessageSvc.h:38
LoggedMessageSvc::reinitialize
virtual StatusCode reinitialize() override
Reinitialize Service.
Definition: LoggedMessageSvc.cxx:144
LoggedMessageSvc::m_thresholdMapMutex
std::mutex m_thresholdMapMutex
Mutex to synchronize multiple access to m_thresholdMap (.
Definition: LoggedMessageSvc.h:196
LoggedMessageSvc::m_msgCount
int m_msgCount[MSG::NUM_LEVELS]
Definition: LoggedMessageSvc.h:171
histSizes.code
code
Definition: histSizes.py:129
LoggedMessageSvc::initialize
virtual StatusCode initialize() override
Initialize Service.
Definition: LoggedMessageSvc.cxx:109
LoggedMessageSvc::messageCount
virtual int messageCount(MSG::Level logLevel) const override
Definition: LoggedMessageSvc.cxx:854
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
LoggedMessageSvc::setupLogStreams
void setupLogStreams()
Definition: LoggedMessageSvc.cxx:872
ILoggedMessageSvc.h
LoggedMessageSvc::LoggedMessageSvc
LoggedMessageSvc(const std::string &name, ISvcLocator *svcloc)
Definition: LoggedMessageSvc.cxx:23
LoggedMessageSvc::m_logLevel
IntegerProperty m_logLevel
Definition: LoggedMessageSvc.h:151
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
LoggedMessageSvc::m_messageMapMutex
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
Definition: LoggedMessageSvc.h:192
LoggedMessageSvc::tee
void tee(const std::string &sourceName, const std::string &logFileName, const std::set< std::string > &declaredOutFileNames)
Definition: LoggedMessageSvc.cxx:910
LoggedMessageSvc::m_msgLimit
IntegerProperty m_msgLimit[MSG::NUM_LEVELS]
Definition: LoggedMessageSvc.h:150
LoggedMessageSvc::m_suppress
BooleanProperty m_suppress
Definition: LoggedMessageSvc.h:165
LoggedMessageSvc::colTrans
std::string colTrans(const std::string &, int)
Definition: LoggedMessageSvc.cxx:476
LoggedMessageSvc::eraseStream
virtual void eraseStream() override
Definition: LoggedMessageSvc.cxx:672
LoggedMessageSvc::NamedStream
std::pair< std::string, std::ostream * > NamedStream
Definition: LoggedMessageSvc.h:41
LoggedMessageSvc::m_inactCount
BooleanProperty m_inactCount
Definition: LoggedMessageSvc.h:165
LoggedMessageSvc::getKeyMessages
virtual const std::vector< LoggedMessage > & getKeyMessages() const override
Definition: LoggedMessageSvc.h:135
LoggedMessageSvc::m_sourceMap
std::map< std::string, MsgAry, std::less<> > m_sourceMap
Definition: LoggedMessageSvc.h:164
LoggedMessageSvc::setOutputLevel
virtual void setOutputLevel(int new_level) override
Definition: LoggedMessageSvc.cxx:823
LoggedMessageSvc::StreamMap
std::multimap< int, NamedStream > StreamMap
Definition: LoggedMessageSvc.h:42
LoggedMessageSvc::m_thresholdMap
ThresholdMap m_thresholdMap
Output level threshold map.
Definition: LoggedMessageSvc.h:142
LoggedMessageSvc::m_loggedStreamsName
std::map< std::string, std::string > m_loggedStreamsName
Definition: LoggedMessageSvc.h:173
TrigConf::MSGTC::NUM_LEVELS
@ NUM_LEVELS
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:30
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
LoggedMessageSvc::getMessages
virtual const std::vector< std::pair< std::string, std::string > > & getMessages(MSG::Level level) const override
Definition: LoggedMessageSvc.cxx:956
LoggedMessageSvc::ATLAS_NOT_CONST_THREAD_SAFE
virtual std::ostream *defaultStream ATLAS_NOT_CONST_THREAD_SAFE() const override
Definition: LoggedMessageSvc.h:98
LoggedMessageSvc::getLogColor
virtual std::string getLogColor(int logLevel) const override
Definition: LoggedMessageSvc.cxx:844
LoggedMessageSvc::setupThreshold
void setupThreshold(Gaudi::Details::PropertyBase &prop)
Definition: LoggedMessageSvc.cxx:282
LoggedMessageSvc::m_defaultTimeFormat
std::string m_defaultTimeFormat
Default format for timestamps in the messages.
Definition: LoggedMessageSvc.h:144
LoggedMessageSvc::m_thresholdProp
StringArrayProperty m_thresholdProp[MSG::NUM_LEVELS]
Properties controling.
Definition: LoggedMessageSvc.h:145
LoggedMessageSvc::setupLimits
void setupLimits(Gaudi::Details::PropertyBase &prop)
Definition: LoggedMessageSvc.cxx:245
LoggedMessageSvc::MsgAry::MsgAry
MsgAry()=default
Default constructor.
LoggedMessageSvc::m_reportMutex
std::mutex m_reportMutex
Mutex to synchronize multiple threads printing.
Definition: LoggedMessageSvc.h:189
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
LoggedMessageSvc::m_defaultStream
std::ostream * m_defaultStream
Pointer to the output stream.
Definition: LoggedMessageSvc.h:138
AthService.h
LoggedMessageSvc::reportMessage
virtual void reportMessage(const Message &message) override
Definition: LoggedMessageSvc.cxx:596
copySelective.source
string source
Definition: copySelective.py:32
LoggedMessageSvc::m_logColorCodes
std::string m_logColorCodes[MSG::NUM_LEVELS]
Definition: LoggedMessageSvc.h:154
LoggedMessageSvc::m_keywords
StringArrayProperty m_keywords
Definition: LoggedMessageSvc.h:152
LoggedMessageSvc::MessageMap
std::multimap< StatusCode, Message > MessageMap
Definition: LoggedMessageSvc.h:43
LoggedMessageSvc::m_streamMap
StreamMap m_streamMap
Stream map.
Definition: LoggedMessageSvc.h:140
LoggedMessageSvc::~LoggedMessageSvc
virtual ~LoggedMessageSvc()
Definition: LoggedMessageSvc.cxx:95
checker_macros.h
Define macros for attributes used to control the static checker.
LoggedMessageSvc::setupInactCount
void setupInactCount(Gaudi::Details::PropertyBase &prop)
Definition: LoggedMessageSvc.cxx:336
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
LoggedMessageSvc::m_statLevel
UnsignedIntegerProperty m_statLevel
Definition: LoggedMessageSvc.h:148
LoggedMessageSvc::setupColors
void setupColors(Gaudi::Details::PropertyBase &prop)
Definition: LoggedMessageSvc.cxx:193
run.Message
Message
Definition: run.py:57
LoggedMessageSvc::m_messageMap
MessageMap m_messageMap
Message map.
Definition: LoggedMessageSvc.h:141
LoggedMessageSvc::m_defaultFormat
std::string m_defaultFormat
Default format for the messages.
Definition: LoggedMessageSvc.h:143
LoggedMessageSvc::eraseMessage
virtual void eraseMessage() override
Definition: LoggedMessageSvc.cxx:760