00001
00002
00003
00004
00005
00006
00007
00008 #ifndef ROOT_Root_TMsgLogger
00009 #define ROOT_Root_TMsgLogger
00010
00012
00013
00014
00015
00016
00018
00019
00020 #include <string>
00021 #include <sstream>
00022 #include <map>
00023
00024
00025 #include "TObject.h"
00026 #include "TString.h"
00027
00028
00029
00030 namespace Root {
00031
00032
00033 enum TMsgLevel {
00034 kVERBOSE = 1,
00035 kDEBUG = 2,
00036 kINFO = 3,
00037 kWARNING = 4,
00038 kERROR = 5,
00039 kFATAL = 6,
00040 kALWAYS = 7
00041 };
00042
00043 class TMsgLogger : public std::ostringstream, public TObject {
00044
00045 public:
00046
00047 TMsgLogger( const TObject* source, TMsgLevel minLevel = kINFO );
00048 TMsgLogger( const std::string& source, TMsgLevel minLevel = kINFO );
00049 TMsgLogger( TMsgLevel minLevel = kINFO );
00050 TMsgLogger( const TMsgLogger& parent );
00051 virtual ~TMsgLogger();
00052
00053
00054 void SetSource( const char* source ) { m_strSource = source; }
00055 void SetSource( const std::string& source ) { m_strSource = source; }
00056 void SetSource( const TString& source ) { m_strSource = source.Data(); }
00057 const std::string& GetSource() const { return m_strSource; }
00058
00059 UInt_t GetMaxSourceSize() const { return (UInt_t)m_maxSourceSize; }
00060 std::string GetPrintedSource() const;
00061 std::string GetFormattedSource() const;
00062
00063 TMsgLevel GetMinLevel() const { return m_minLevel; }
00064 const std::string& GetMinLevelStr() const { return m_levelMap.find( m_minLevel )->second; }
00065
00066 TMsgLevel MapLevel( const TString& instr ) const;
00067
00068
00069 TMsgLogger& operator= ( const TMsgLogger& parent );
00070
00071
00072 static TMsgLogger& endmsg( TMsgLogger& logger );
00073
00074
00075 TMsgLogger& operator<< ( TMsgLogger& ( *_f )( TMsgLogger& ) );
00076 TMsgLogger& operator<< ( std::ostream& ( *_f )( std::ostream& ) );
00077 TMsgLogger& operator<< ( std::ios& ( *_f )( std::ios& ) );
00078
00079
00080 TMsgLogger& operator<< ( TMsgLevel level );
00081
00082
00083 template <class T> TMsgLogger& operator<< ( T arg ) {
00084 *(std::ostringstream*)this << arg; return *this;
00085 }
00086
00087 static void SetMinLevel( TMsgLevel minLevel ) { m_minLevel = minLevel; }
00088
00089 private:
00090
00091
00092
00093 static TMsgLevel m_minLevel;
00094
00095
00096 void Send();
00097 void InitMaps();
00098 void WriteMsg( TMsgLevel level, const std::string& line ) const;
00099
00100 const TObject* m_objSource;
00101 std::string m_strSource;
00102 const std::string m_prefix;
00103 const std::string m_suffix;
00104 TMsgLevel m_activeLevel;
00105 const std::string::size_type m_maxSourceSize;
00106
00107 std::map<TMsgLevel, std::string> m_levelMap;
00108 std::map<TMsgLevel, std::string> m_colorMap;
00109
00110
00111
00112 };
00113
00114 inline TMsgLogger& TMsgLogger::operator<< ( TMsgLogger& (*_f)( TMsgLogger& ) )
00115 {
00116 return (_f)(*this);
00117 }
00118
00119 inline TMsgLogger& TMsgLogger::operator<< ( std::ostream& (*_f)( std::ostream& ) )
00120 {
00121 (_f)(*this);
00122 return *this;
00123 }
00124
00125 inline TMsgLogger& TMsgLogger::operator<< ( std::ios& ( *_f )( std::ios& ) )
00126 {
00127 (_f)(*this);
00128 return *this;
00129 }
00130
00131 inline TMsgLogger& TMsgLogger::operator<< ( TMsgLevel level )
00132 {
00133 m_activeLevel = level;
00134 return *this;
00135 }
00136
00137
00138
00139
00140
00141 #define GEndl TMsgLogger::endmsg
00142
00143 }
00144
00145 #endif // Root_TMsgLogger