All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 <string>
6 #include <vector>
7 #include <map>
8 #include <set>
9 #include <iosfwd>
10 
11 #include "GaudiKernel/StatusCode.h"
12 #include "GaudiKernel/Service.h"
14 #include "GaudiKernel/Message.h"
15 #include "GaudiKernel/Property.h"
16 
17 #include <boost/thread/recursive_mutex.hpp>
18 #include <boost/array.hpp>
19 
20 // Forward declarations
21 class ISvcLocator;
22 
23 //
24 // ClassName: MessageSvc
25 //
26 // Description: The MessageSvc service implements the IMessageSvc interface and provides the
27 // basic messaging needed by batch oriented applications.
28 //
29 // Author: Iain Last
30 //
31 class MessageSvc : public extends2<Service, IMessageSvc, IInactiveMessageCounter> {
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  virtual ~MessageSvc();
42 
43  // Implementation of IService::reinitialize()
44  virtual StatusCode reinitialize();
45  // Implementation of IService::initialize()
46  virtual StatusCode initialize();
47  // Implementation of IService::finalize()
48  virtual StatusCode finalize();
49 
50  // Implementation of IMessageSvc::reportMessage()
51  virtual void reportMessage( const Message& message );
52 
53  // Implementation of IMessageSvc::reportMessage()
54  virtual void reportMessage( const Message& msg, int outputLevel );
55 
56  // Implementation of IMessageSvc::reportMessage()
57  virtual void reportMessage( const StatusCode& code, const std::string& source = "");
58 
59  // Implementation of IMessageSvc::reportMessage()
60  virtual void reportMessage( const char* source, int type, const char* message);
61 
62  // Implementation of IMessageSvc::reportMessage()
63  virtual void reportMessage( const std::string& source, int type, const std::string& message);
64 
65  // Implementation of IMessageSvc::insertMessage()
66  virtual void insertMessage( const StatusCode& code, const Message& message );
67 
68  // Implementation of IMessageSvc::eraseMessage()
69  virtual void eraseMessage();
70 
71  // Implementation of IMessageSvc::eraseMessage()
72  virtual void eraseMessage( const StatusCode& code ) ;
73 
74  // Implementation of IMessageSvc::eraseMessage()
75  virtual void eraseMessage( const StatusCode& code, const Message& message );
76 
77  // Implementation of IMessageSvc::insertStream()
78  virtual void insertStream( int message_type, const std::string& name, std::ostream* stream );
79 
80  // Implementation of IMessageSvc::eraseStream()
81  virtual void eraseStream();
82 
83  // Implementation of IMessageSvc::eraseStream()
84  virtual void eraseStream( int message_type );
85 
86  // Implementation of IMessageSvc::eraseStream()
87  virtual void eraseStream( int message_type, std::ostream* stream );
88 
89  // Implementation of IMessageSvc::eraseStream()
90  virtual void eraseStream( std::ostream* stream );
91 
92  // Implementation of IMessageSvc::desaultStream()
93  virtual std::ostream* defaultStream() const {
94  return m_defaultStream;
95  }
96 
97  // Implementation of IMessageSvc::setDefaultStream()
98  virtual void setDefaultStream( std::ostream* stream ) {
99  boost::recursive_mutex::scoped_lock lock(m_reportMutex);
100  m_defaultStream = stream;
101  }
102 
103  // Implementation of IMessageSvc::ouputLevel()
104  virtual int outputLevel() const;
105 
106  // Implementation of IMessageSvc::ouputLevel()
107  virtual int outputLevel(const std::string& source) const;
108 
109  // Implementation of IMessageSvc::setOuputLevel()
110  virtual void setOutputLevel(int new_level);
111 
112  // Implementation of IMessageSvc::setOuputLevel()
113  virtual void setOutputLevel(const std::string& source, int new_level);
114 
115  // Implementation of IMessageSvc::useColor()
116  virtual bool useColor() const { return m_color; }
117 
118  // Implementation of IMessageSvc::getLogColor()
119  virtual std::string getLogColor(int logLevel) const;
120 
121  // Implementation of IMessageSvc::messageCount()
122  virtual int messageCount( MSG::Level logLevel ) const;
123 
124  // Implementation of IInactiveMessageCounter::incrInactiveCount()
125  virtual void incrInactiveCount( MSG::Level level,
126  const std::string& src );
127 
128 
129 private:
130  std::ostream* m_defaultStream;
135  std::string m_defaultFormat;
136  std::string m_defaultTimeFormat;
143 
145 
147  struct MsgAry {
149  typedef boost::array<int,MSG::NUM_LEVELS> ArrayType;
153  MsgAry() {
154  // This is a special hack to have a fast initialization of the array
155  // because we cannot use initializer lists in the constructor (should be
156  // possible in C++0X).
157  static const ArrayType zero = {{0}};
158  msg = zero;
159  }
160  };
161 
162  std::map<std::string,MsgAry> m_sourceMap, m_inactiveMap;
164 
165  std::string colTrans(std::string, int);
166  typedef std::map<std::string, MSG::Color> ColorMap;
168 
170 
171  std::map<std::string, std::string> m_loggedStreamsName;
172  typedef std::map<std::string, std::ostream*> LoggedStreamsMap_t;
174 
175  void initColors(Property& prop);
176  void setupColors(Property& prop);
177  void setupLimits(Property& prop);
178  void setupThreshold(Property& prop);
179  void setupInactCount(Property& prop);
180 
181  void setupLogStreams();
182 
183  void tee( const std::string& sourceName, const std::string& logFileName,
184  const std::set<std::string>& declaredOutFileNames );
185 
187  mutable boost::recursive_mutex m_reportMutex;
188 
190  mutable boost::recursive_mutex m_messageMapMutex;
191 
194  mutable boost::recursive_mutex m_thresholdMapMutex;
195 };
196 
197 #endif
IntegerProperty m_msgLimit[MSG::NUM_LEVELS]
Definition: MessageSvc.h:142
std::string colTrans(std::string, int)
Definition: MessageSvc.cpp:461
virtual void setDefaultStream(std::ostream *stream)
Set the default stream.
Definition: MessageSvc.h:98
std::ostream * m_defaultStream
Pointer to the output stream.
Definition: MessageSvc.h:130
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
boost::recursive_mutex m_reportMutex
Mutex to synchronize multiple threads printing.
Definition: MessageSvc.h:187
std::multimap< int, NamedStream > StreamMap
Definition: MessageSvc.h:34
virtual std::string getLogColor(int logLevel) const
Get the color codes for various log levels.
Definition: MessageSvc.cpp:828
ArrayType msg
Internal array of counters.
Definition: MessageSvc.h:151
StreamMap m_streamMap
Stream map.
Definition: MessageSvc.h:132
virtual StatusCode initialize()
Initialize Service.
Definition: MessageSvc.cpp:114
ColorMap m_colMap
Definition: MessageSvc.h:167
Message m_defaultMessage
Default Message.
Definition: MessageSvc.h:131
def lock
Definition: locker.py:16
virtual ~MessageSvc()
Definition: MessageSvc.cpp:100
MessageMap m_messageMap
Message map.
Definition: MessageSvc.h:133
void setupLimits(Property &prop)
Definition: MessageSvc.cpp:249
void setupInactCount(Property &prop)
Definition: MessageSvc.cpp:320
int m_msgCount[MSG::NUM_LEVELS]
Definition: MessageSvc.h:169
void setupLogStreams()
Definition: MessageSvc.cpp:853
MessageSvc(const std::string &name, ISvcLocator *svcloc)
Definition: MessageSvc.cpp:26
Base class used to extend a class implementing other interfaces.
Definition: extends.h:75
virtual void setOutputLevel(int new_level)
Set new global output level threshold.
Definition: MessageSvc.cpp:805
std::pair< std::string, std::ostream * > NamedStream
Definition: MessageSvc.h:33
virtual StatusCode finalize()
Finalize Service.
Definition: MessageSvc.cpp:332
std::map< std::string, int > ThresholdMap
Definition: MessageSvc.h:36
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
UnsignedIntegerProperty m_statLevel
Definition: MessageSvc.h:140
Private helper class to keep the count of messages of a type (MSG::LEVEL).
Definition: MessageSvc.h:147
virtual void incrInactiveCount(MSG::Level level, const std::string &src)
Increment deactivated message count.
Definition: MessageSvc.cpp:846
std::map< std::string, MsgAry > m_sourceMap
Definition: MessageSvc.h:162
std::map< std::string, MSG::Color > ColorMap
Definition: MessageSvc.h:166
virtual void insertStream(int message_type, const std::string &name, std::ostream *stream)
Add a new stream for a message type (severity level).
Definition: MessageSvc.cpp:630
virtual void reportMessage(const Message &message)
Report a message by sending a Message object to the message service.
Definition: MessageSvc.cpp:556
boost::array< int, MSG::NUM_LEVELS > ArrayType
Simple typedef for readability.
Definition: MessageSvc.h:149
string type
Definition: gaudirun.py:126
virtual void eraseStream()
Delete all the streams.
Definition: MessageSvc.cpp:645
ThresholdMap m_thresholdMap
Output level threshold map.
Definition: MessageSvc.h:134
virtual int outputLevel() const
Retrieve the current output level threshold.
Definition: MessageSvc.cpp:783
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:331
std::multimap< StatusCode, Message > MessageMap
Definition: MessageSvc.h:35
virtual StatusCode reinitialize()
Reinitialize Service.
Definition: MessageSvc.cpp:148
std::map< std::string, std::ostream * > LoggedStreamsMap_t
Definition: MessageSvc.h:172
StringArrayProperty m_thresholdProp[MSG::NUM_LEVELS]
Properties controlling.
Definition: MessageSvc.h:137
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:43
The Message class.
Definition: Message.h:15
std::string m_defaultFormat
Default format for the messages.
Definition: MessageSvc.h:135
virtual bool useColor() const
Show whether colors are used.
Definition: MessageSvc.h:116
void setupColors(Property &prop)
Definition: MessageSvc.cpp:197
LoggedStreamsMap_t m_loggedStreams
Definition: MessageSvc.h:173
virtual int messageCount(MSG::Level logLevel) const
Get the number of messages issued at a particular level.
Definition: MessageSvc.cpp:838
std::map< std::string, MsgAry > m_inactiveMap
Definition: MessageSvc.h:162
void initColors(Property &prop)
Definition: MessageSvc.cpp:155
std::string m_logColorCodes[MSG::NUM_LEVELS]
Definition: MessageSvc.h:144
BooleanProperty m_color
Definition: MessageSvc.h:138
BooleanProperty m_inactCount
Definition: MessageSvc.h:163
MsgAry()
Default constructor.
Definition: MessageSvc.h:153
void tee(const std::string &sourceName, const std::string &logFileName, const std::set< std::string > &declaredOutFileNames)
Definition: MessageSvc.cpp:891
BooleanProperty m_stats
Definition: MessageSvc.h:139
std::map< std::string, std::string > m_loggedStreamsName
Definition: MessageSvc.h:171
BooleanProperty m_suppress
Definition: MessageSvc.h:163
void setupThreshold(Property &prop)
Definition: MessageSvc.cpp:276
virtual void eraseMessage()
Erase all messages associated to all status codes.
Definition: MessageSvc.cpp:734
std::string m_defaultTimeFormat
Default format for timestamps in the messages.
Definition: MessageSvc.h:136
virtual std::ostream * defaultStream() const
Get the default stream.
Definition: MessageSvc.h:93
boost::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
Definition: MessageSvc.h:190
virtual void insertMessage(const StatusCode &code, const Message &message)
Insert a message to be sent for a given status code into the error code repository.
Definition: MessageSvc.cpp:719
boost::recursive_mutex m_thresholdMapMutex
Mutex to synchronize multiple access to m_thresholdMap (.
Definition: MessageSvc.h:194
StringArrayProperty m_logColors[MSG::NUM_LEVELS]
Definition: MessageSvc.h:141