首先在目录下创建一个Log.ini文件,这个文件用于是否打印日志的开关。
文件内容为:
[LogSettings]
IsLog=1
调用GetPrivateProfileInt获取打印日志的开关。
1==GetPrivateProfileInt( _T("LogSettings"), _T("IsLog"), 0, _T("Log.ini"));
最后一个值是文件路径名。
.h
Class::CDBLog
{
static bool m_IsLog;
static bool IsLog();
static bool Debug(const TCHAR *pszFmtStr, ...);
}
.cpp
CDBLog::isLog=CDBLog::IsLog();
bool Debug(const TCHAR *pszFmtStr, ...)
{
if(m_IsLog)
{
......
.....
OutputDebugString(pszFmtStr);
}
return true;
}
为方便使用,可以在.h上设置
typedef bool (*LOGDBGFUNC)(const TCHAR *pszFmtStr, ...);
const LOGDBGFUNC DV = &CDBLog::Debug;