00001
00011 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
00012 #pragma once
00013 #endif
00014 #ifndef COMMON_LOGGER_H_
00015 #define COMMON_LOGGER_H_
00016
00017
00018 namespace std
00019 {
00020 template <typename T> struct char_traits;
00021 template <typename T1, typename T2> class basic_ostream;
00022 typedef basic_ostream<char, char_traits<char> > ostream;
00023 };
00024
00025 namespace common
00026 {
00027
00032
00034 class ILog;
00036 class Logger_pimpl;
00037
00039 class Logger
00040 {
00041 friend void CreateLogger(bool);
00042 friend void DestroyLogger();
00043 friend class ILog;
00044
00045 private:
00046 scoped_ptr<Logger_pimpl> pimpl;
00047
00048 Logger(bool UseQueue);
00049 ~Logger();
00050
00051 public:
00055
00056 void AddLogMapping(uint4 Mask, ILog *Log);
00058 void AddTypePrefixMapping(uint4 Mask, const tstring &Prefix);
00060 void SetPrefixFormat(const tstring &PrefixFormat);
00062
00066
00067 void SetCustomPrefixInfo(int Index, const tstring &Info);
00069 void Log(uint4 Type, const tstring &Message);
00071 };
00072
00074 class ILog
00075 {
00076 friend class Logger_pimpl;
00077
00078 private:
00080 class ILog_pimpl;
00081 scoped_ptr<ILog_pimpl> pimpl;
00082
00083 protected:
00085 virtual void OnLog(uint4 Type, const tstring &Prefix, const tstring &TypePrefix, const tstring &Message) = 0;
00086
00087 public:
00088 ILog();
00089 virtual ~ILog();
00090
00093
00094 void AddTypePrefixMapping(uint4 Mask, const tstring &Prefix);
00096 void SetPrefixFormat(const tstring &PrefixFormat);
00098 };
00099
00101 void CreateLogger(bool UseQueue);
00103 void DestroyLogger();
00105 Logger & GetLogger();
00107 bool IsLogger();
00108
00109
00110
00111
00112
00114 enum LOG_FILE_MODE
00115 {
00117 FILE_MODE_NORMAL,
00119 FILE_MODE_FLUSH,
00121 FILE_MODE_REOPEN,
00122 };
00123
00125 class TextFileLog : public ILog
00126 {
00127 private:
00129 class TextFileLog_pimpl;
00130 scoped_ptr<TextFileLog_pimpl> pimpl;
00131
00132 protected:
00133 virtual void OnLog(uint4 Type, const tstring &Prefix, const tstring &TypePrefix, const tstring &Message);
00134
00135 public:
00136 TextFileLog(const tstring &FileName, LOG_FILE_MODE Mode, EOLMODE EolMode, bool Append = false, const tstring &StartText = _T(""));
00137 virtual ~TextFileLog();
00138 };
00139
00141 class HtmlFileLog : public ILog
00142 {
00143 public:
00144 struct STYLE
00145 {
00146 uint4 BackgroundColor;
00147 uint4 FontColor;
00148 bool Bold;
00149 bool Italic;
00150
00151 STYLE(bool Bold = false, bool Italic = false, uint FontColor = 0x000000, uint BackgroundColor = 0xFFFFFF);
00152 };
00153
00154 private:
00156 class HtmlFileLog_pimpl;
00157 scoped_ptr<HtmlFileLog_pimpl> pimpl;
00158
00159 protected:
00160 virtual void OnLog(uint4 Type, const tstring &Prefix, const tstring &TypePrefix, const tstring &Message);
00161
00162 public:
00163 HtmlFileLog(const tstring &FileName, LOG_FILE_MODE Mode, bool Append = false, const tstring &StartText = _T(""));
00164 virtual ~HtmlFileLog();
00165
00168
00169 void AddStyleMapping(uint4 Mask, const STYLE &Style);
00171 };
00172
00174 class OstreamLog : public ILog
00175 {
00176 private:
00177 class Pimpl;
00178 scoped_ptr<Pimpl> pimpl;
00179
00180 protected:
00181 virtual void OnLog(uint4 Type, const tstring &Prefix, const tstring &TypePrefix, const tstring &Message);
00182
00183 public:
00184 #ifdef _UNICODE
00185 OstreamLog(std::wostream *Ostream);
00186 #else
00187 OstreamLog(std::ostream *Ostream);
00188 #endif
00189 virtual ~OstreamLog();
00190 };
00191
00193
00194
00195 }
00196
00199
00200 #define LOG(Type, s) { if (common::IsLogger()) common::GetLogger().Log((Type), (s)); else assert(0 && "LOG macro: Logger not initialized."); }
00201
00202
00203 #endif