Go to the documentation of this file.00001 #ifndef GAUDI_MESSAGESVC_H
00002 #define GAUDI_MESSAGESVC_H
00003
00004
00005 #include <string>
00006 #include <vector>
00007 #include <map>
00008 #include <set>
00009 #include <iosfwd>
00010
00011 #include "GaudiKernel/StatusCode.h"
00012 #include "GaudiKernel/Service.h"
00013 #include "GaudiKernel/IMessageSvc.h"
00014 #include "GaudiKernel/Message.h"
00015 #include "GaudiKernel/Property.h"
00016
00017 #include <boost/thread/recursive_mutex.hpp>
00018 #include <boost/array.hpp>
00019
00020
00021 class ISvcLocator;
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 class MessageSvc : public extends2<Service, IMessageSvc, IInactiveMessageCounter> {
00032 public:
00033 typedef std::pair< std::string, std::ostream* > NamedStream;
00034 typedef std::multimap< int, NamedStream > StreamMap;
00035 typedef std::multimap< StatusCode, Message > MessageMap;
00036 typedef std::map< std::string, int > ThresholdMap;
00037
00038
00039 MessageSvc( const std::string& name, ISvcLocator* svcloc );
00040
00041 virtual ~MessageSvc();
00042
00043
00044 virtual StatusCode reinitialize();
00045
00046 virtual StatusCode initialize();
00047
00048 virtual StatusCode finalize();
00049
00050
00051 virtual void reportMessage( const Message& message );
00052
00053
00054 virtual void reportMessage( const Message& msg, int outputLevel );
00055
00056
00057 virtual void reportMessage( const StatusCode& code, const std::string& source = "");
00058
00059
00060 virtual void reportMessage( const char* source, int type, const char* message);
00061
00062
00063 virtual void reportMessage( const std::string& source, int type, const std::string& message);
00064
00065
00066 virtual void insertMessage( const StatusCode& code, const Message& message );
00067
00068
00069 virtual void eraseMessage();
00070
00071
00072 virtual void eraseMessage( const StatusCode& code ) ;
00073
00074
00075 virtual void eraseMessage( const StatusCode& code, const Message& message );
00076
00077
00078 virtual void insertStream( int message_type, const std::string& name, std::ostream* stream );
00079
00080
00081 virtual void eraseStream();
00082
00083
00084 virtual void eraseStream( int message_type );
00085
00086
00087 virtual void eraseStream( int message_type, std::ostream* stream );
00088
00089
00090 virtual void eraseStream( std::ostream* stream );
00091
00092
00093 virtual std::ostream* defaultStream() const {
00094 return m_defaultStream;
00095 }
00096
00097
00098 virtual void setDefaultStream( std::ostream* stream ) {
00099 boost::recursive_mutex::scoped_lock lock(m_reportMutex);
00100 m_defaultStream = stream;
00101 }
00102
00103
00104 virtual int outputLevel() const;
00105
00106
00107 virtual int outputLevel(const std::string& source) const;
00108
00109
00110 virtual void setOutputLevel(int new_level);
00111
00112
00113 virtual void setOutputLevel(const std::string& source, int new_level);
00114
00115
00116 virtual bool useColor() const { return m_color; }
00117
00118
00119 virtual std::string getLogColor(int logLevel) const;
00120
00121
00122 virtual int messageCount( MSG::Level logLevel ) const;
00123
00124
00125 virtual void incrInactiveCount( MSG::Level level,
00126 const std::string& src );
00127
00128
00129 private:
00130 std::ostream* m_defaultStream;
00131 Message m_defaultMessage;
00132 StreamMap m_streamMap;
00133 MessageMap m_messageMap;
00134 ThresholdMap m_thresholdMap;
00135 std::string m_defaultFormat;
00136 std::string m_defaultTimeFormat;
00137 StringArrayProperty m_thresholdProp[MSG::NUM_LEVELS];
00138 BooleanProperty m_color;
00139 BooleanProperty m_stats;
00140 UnsignedIntegerProperty m_statLevel;
00141 StringArrayProperty m_logColors[MSG::NUM_LEVELS];
00142 IntegerProperty m_msgLimit[MSG::NUM_LEVELS];
00143
00144 std::string m_logColorCodes[MSG::NUM_LEVELS];
00145
00147 struct MsgAry {
00149 typedef boost::array<int,MSG::NUM_LEVELS> ArrayType;
00151 ArrayType msg;
00153 MsgAry() {
00154
00155
00156
00157 static const ArrayType zero = {{0}};
00158 msg = zero;
00159 }
00160 };
00161
00162 std::map<std::string,MsgAry> m_sourceMap, m_inactiveMap;
00163 BooleanProperty m_suppress, m_inactCount;
00164
00165 std::string colTrans(std::string, int);
00166 typedef std::map<std::string, MSG::Color> ColorMap;
00167 ColorMap m_colMap;
00168
00169 int m_msgCount[MSG::NUM_LEVELS];
00170
00171 std::map<std::string, std::string> m_loggedStreamsName;
00172 typedef std::map<std::string, std::ostream*> LoggedStreamsMap_t;
00173 LoggedStreamsMap_t m_loggedStreams;
00174
00175 void initColors(Property& prop);
00176 void setupColors(Property& prop);
00177 void setupLimits(Property& prop);
00178 void setupThreshold(Property& prop);
00179 void setupInactCount(Property& prop);
00180
00181 void setupLogStreams();
00182
00183 void tee( const std::string& sourceName, const std::string& logFileName,
00184 const std::set<std::string>& declaredOutFileNames );
00185
00187 mutable boost::recursive_mutex m_reportMutex;
00188
00190 mutable boost::recursive_mutex m_messageMapMutex;
00191
00194 mutable boost::recursive_mutex m_thresholdMapMutex;
00195 };
00196
00197 #endif