00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #if !defined(AFX_ERRORHANDLER_H__B886D5A4_FD2D_4CB8_8459_7311CBE31B77__INCLUDED_)
00037 #define AFX_ERRORHANDLER_H__B886D5A4_FD2D_4CB8_8459_7311CBE31B77__INCLUDED_
00038
00039 #if _MSC_VER > 1000
00040 #pragma once
00041 #endif // _MSC_VER > 1000
00042
00043 #include "KomodiaSettings.h"
00044
00045 #include <string>
00046
00047 KOMODIA_NAMESPACE_START
00048
00049 class CErrorHandler
00050 {
00051 public:
00052
00053 typedef enum _LogPriority
00054 {
00055 lpDebug,
00056 lpMessage,
00057 lpCritical,
00058 lpError
00059 } LogPriority;
00060
00061
00062 class CErrorLog
00063 {
00064 friend class CErrorHandler;
00065 public:
00066
00067
00068 void SetAutoFlush(BOOL bFlush);
00069 BOOL GetAutoFlush()const;
00070
00071
00072 CErrorLog& operator=(const CErrorLog& rLog);
00073
00074
00075 CErrorLog();
00076 CErrorLog(const CErrorLog& rLog);
00077 virtual ~CErrorLog();
00078 protected:
00079
00080 virtual void ReportError(const std::string& rClass,
00081 const std::string& rMethod,
00082 const std::string& rMessage)=0;
00083
00084
00085 virtual void WriteMessage(const std::string& rClass,
00086 const std::string& rMethod,
00087 const std::string& rMessage,
00088 LogPriority aPriority)=0;
00089 private:
00090
00091 BOOL m_bAutoFlush;
00092 };
00093 public:
00094
00095 static std::string GetCurrentDateTime();
00096
00097
00098 static std::string ErrorCodeToString(DWORD dwErrorCode);
00099
00100
00101 void SetLocalLog(CErrorLog* pLog);
00102
00103
00104 static void SetLog(CErrorLog* pLog);
00105
00106
00107 CErrorHandler();
00108 CErrorHandler(const CErrorHandler& rHandler);
00109 virtual ~CErrorHandler();
00110 protected:
00111
00112 const std::string& GetClassName()const;
00113
00114
00115 void WriteMessage(const std::string& rMethod,
00116 const std::string& rMessage,
00117 LogPriority aPriority=lpMessage);
00118
00119
00120 void WriteMessage(const std::string& rMethod,
00121 const std::string& rMessage,
00122 DWORD dwAdditionalData,
00123 LogPriority aPriority=lpMessage);
00124
00125
00126 static void WriteStaticMessage(const std::string& rClass,
00127 const std::string& rMethod,
00128 const std::string& rMessage,
00129 LogPriority aPriority=lpMessage);
00130
00131
00132 static void WriteStaticMessage(const std::string& rClass,
00133 const std::string& rMethod,
00134 const std::string& rMessage,
00135 DWORD dwAdditionalData,
00136 LogPriority aPriority=lpMessage);
00137
00138
00139 static void ReportStaticError(const std::string& rClass,
00140 const std::string& rMethod);
00141
00142
00143 static void ReportStaticError(const std::string& rClass,
00144 const std::string& rMethod,
00145 const std::string& rMessage);
00146
00147
00148 static void ReportStaticError(const std::string& rClass,
00149 const std::string& rMethod,
00150 const std::string& rMessage,
00151 DWORD dwAdditionalData);
00152
00153
00154 virtual void ReportError(const std::string& rMethod)const;
00155
00156
00157 virtual void ReportError(const std::string& rMethod,
00158 const std::string& rMessage)const;
00159
00160
00161 virtual void ReportError(const std::string& rMethod,
00162 const std::string& rMessage,
00163 DWORD dwAdditionalData)const;
00164
00165
00166 virtual void ReportError(const std::string& rMethod,
00167 int iErrorCode)const;
00168
00169
00170 virtual void ReportError(const std::string& rMethod,
00171 const std::string& rMessage,
00172 int iErrorCode)const;
00173
00174
00175 virtual void ReportErrorOS(const std::string& rMethod,
00176 const std::string& rMessage)const;
00177
00178
00179 void SetName(const std::string& rName)const;
00180 private:
00181
00182 CErrorLog* GetLog()const;
00183
00184
00185 static CErrorLog* m_pLog;
00186
00187
00188 CErrorLog* m_pLocalLog;
00189
00190
00191 mutable std::string m_sClassName;
00192 };
00193
00194 KOMODIA_NAMESPACE_END
00195
00196 #endif // !defined(AFX_ERRORHANDLER_H__B886D5A4_FD2D_4CB8_8459_7311CBE31B77__INCLUDED_)