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