ATLAS Offline Software
Loading...
Searching...
No Matches
LoggedMessageSvc.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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
26class 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
40public:
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 std::lock_guard<std::mutex> lock(m_reportMutex);
100 return m_defaultStream;
101 }
102
103 // Implementation of IMessageSvc::setDefaultStream()
104 virtual void setDefaultStream( std::ostream* stream ) override {
105 std::lock_guard<std::mutex> lock(m_reportMutex);
106 m_defaultStream = stream;
107 }
108
109 // Implementation of IMessageSvc::ouputLevel()
110 virtual int outputLevel() const override;
111
112 // Implementation of IMessageSvc::ouputLevel()
113 virtual int outputLevel(std::string_view source) const override;
114
115 // Implementation of IMessageSvc::setOuputLevel()
116 virtual void setOutputLevel(int new_level) override;
117
118 // Implementation of IMessageSvc::setOuputLevel()
119 virtual void setOutputLevel(std::string_view source, int new_level) override;
120
121 // Implementation of IMessageSvc::useColor()
122 virtual bool useColor() const override { return m_color; }
123
124 // Implementation of IMessageSvc::getLogColor()
125 virtual std::string getLogColor(int logLevel) const override;
126
127 // Implementation of IMessageSvc::messageCount()
128 virtual int messageCount( MSG::Level logLevel ) const override;
129
130 // Implementation of IInactiveMessageCounter::incrInactiveCount()
131 virtual void incrInactiveCount( MSG::Level level,
132 std::string_view src ) override;
133
134 virtual std::vector< std::pair<std::string, std::string> > getMessages( MSG::Level level) const override;
135
136 virtual std::vector< LoggedMessage > getKeyMessages() const override;
137
138private:
139 std::ostream* m_defaultStream;
144 std::string m_defaultFormat;
146 StringArrayProperty m_thresholdProp[MSG::NUM_LEVELS];
147 BooleanProperty m_color;
148 BooleanProperty m_stats;
149 UnsignedIntegerProperty m_statLevel;
150 StringArrayProperty m_logColors[MSG::NUM_LEVELS];
151 IntegerProperty m_msgLimit[MSG::NUM_LEVELS];
152 IntegerProperty m_logLevel;
153 StringArrayProperty m_keywords;
154
155 std::string m_logColorCodes[MSG::NUM_LEVELS];
156
158 struct MsgAry final {
160 std::array<int, MSG::NUM_LEVELS> msg = {{0}};
162 MsgAry() = default;
163 };
164
165 std::map<std::string, MsgAry, std::less<>> m_sourceMap, m_inactiveMap;
166 BooleanProperty m_suppress, m_inactCount;
167
168 std::string colTrans(const std::string&, int);
169 typedef std::map<std::string, MSG::Color> ColorMap;
171
172 int m_msgCount[MSG::NUM_LEVELS];
173
174 std::map<std::string, std::string> m_loggedStreamsName;
175 typedef std::map<std::string, std::ostream*> LoggedStreamsMap_t;
177
178 void initColors(Gaudi::Details::PropertyBase& prop);
179 void setupColors(Gaudi::Details::PropertyBase& prop);
180 void setupLimits(Gaudi::Details::PropertyBase& prop);
181 void setupThreshold(Gaudi::Details::PropertyBase& prop);
182 void setupInactCount(Gaudi::Details::PropertyBase& prop);
183
184 void setupLogStreams();
185
186 void tee( const std::string& sourceName, const std::string& logFileName,
187 const std::set<std::string>& declaredOutFileNames );
188
190 mutable std::mutex m_reportMutex;
191
193 mutable std::recursive_mutex m_messageMapMutex;
194
197 mutable std::mutex m_thresholdMapMutex;
198
199 std::vector< std::pair<std::string, std::string> > m_msgLog[ MSG::NUM_LEVELS ];
200 std::vector< LoggedMessage > m_msgKeyLog;
202
203};
204
205#endif
Define macros for attributes used to control the static checker.
MessageMap m_messageMap
Message map.
void initColors(Gaudi::Details::PropertyBase &prop)
virtual void insertStream(int message_type, std::string name, std::ostream *stream) override
virtual int messageCount(MSG::Level logLevel) const override
LoggedStreamsMap_t m_loggedStreams
void setupLimits(Gaudi::Details::PropertyBase &prop)
virtual void eraseStream() override
LoggedMessageSvc(const std::string &name, ISvcLocator *svcloc)
StreamMap m_streamMap
Stream map.
void setupColors(Gaudi::Details::PropertyBase &prop)
UnsignedIntegerProperty m_statLevel
std::map< std::string, MSG::Color > ColorMap
void tee(const std::string &sourceName, const std::string &logFileName, const std::set< std::string > &declaredOutFileNames)
virtual StatusCode initialize() override
Initialize Service.
std::mutex m_reportMutex
Mutex to synchronize multiple threads printing.
virtual void setOutputLevel(int new_level) override
std::multimap< StatusCode, Message > MessageMap
std::vector< LoggedMessage > m_msgKeyLog
BooleanProperty m_color
std::pair< std::string, std::ostream * > NamedStream
virtual std::string getLogColor(int logLevel) const override
IntegerProperty m_msgLimit[MSG::NUM_LEVELS]
virtual StatusCode reinitialize() override
Reinitialize Service.
std::vector< std::pair< std::string, std::string > > m_msgLog[MSG::NUM_LEVELS]
std::map< std::string, MsgAry, std::less<> > m_sourceMap
std::map< std::string, std::ostream * > LoggedStreamsMap_t
BooleanProperty m_inactCount
virtual bool useColor() const override
Message m_defaultMessage
Default Message.
virtual StatusCode finalize() override
Finalize Service.
ThresholdMap m_thresholdMap
Output level threshold map.
virtual std::vector< std::pair< std::string, std::string > > getMessages(MSG::Level level) const override
std::mutex m_thresholdMapMutex
Mutex to synchronize multiple access to m_thresholdMap (.
int m_msgCount[MSG::NUM_LEVELS]
StringArrayProperty m_thresholdProp[MSG::NUM_LEVELS]
Properties controling.
virtual std::ostream *defaultStream ATLAS_NOT_CONST_THREAD_SAFE() const override
std::string m_defaultTimeFormat
Default format for timestamps in the messages.
virtual void reportMessage(const Message &message) override
StringArrayProperty m_logColors[MSG::NUM_LEVELS]
virtual void setDefaultStream(std::ostream *stream) override
std::string colTrans(const std::string &, int)
std::multimap< int, NamedStream > StreamMap
std::map< std::string, MsgAry, std::less<> > m_inactiveMap
virtual void insertMessage(const StatusCode &code, Message message) override
virtual int outputLevel() const override
std::ostream * m_defaultStream
Pointer to the output stream.
std::map< std::string, std::string > m_loggedStreamsName
IntegerProperty m_logLevel
std::map< std::string, int, std::less<> > ThresholdMap
void setupThreshold(Gaudi::Details::PropertyBase &prop)
void setupInactCount(Gaudi::Details::PropertyBase &prop)
virtual std::vector< LoggedMessage > getKeyMessages() const override
std::string m_logColorCodes[MSG::NUM_LEVELS]
BooleanProperty m_stats
std::string m_defaultFormat
Default format for the messages.
StringArrayProperty m_keywords
virtual void incrInactiveCount(MSG::Level level, std::string_view src) override
BooleanProperty m_suppress
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
virtual void eraseMessage() override
MsgAry()=default
Default constructor.
std::array< int, MSG::NUM_LEVELS > msg
Internal array of counters.
MsgStream & msg
Definition testRead.cxx:32