//log.h
//hujinshan@2004.1.3 Airforce Engineering University
/*
//CLog* CLog::_instance = NULL;
CLog::GetObj().Write( "******* 初始化完成 *******" );
CLog::GetObj().tmWrite( "******* 开始渲染No1. *******" );
CLog::GetObj();
在Clog文件中有 #define CLog /##/ 的语句,
这是为了使日志在release版无效,
使用单行注释,所以如果调用时如果要换行,
请务必在换行最后加上 / 符号,
*/
/*#ifndef _DEBUG
#define CLog /##/
#define _CLOG_H
#endif*/
#ifndef _CLOG_H
#define _CLOG_H
#include <fstream>
#include <ctime>
classCLog
{
CLog()
{
pf= newofstream ("inmstrace.log", ios::app);
}
static CLog* _instance;
ofstream* pf;
public:
~CLog()
{
_instance=0;
pf->close();
}
static CLog* GetPtr()
{
if(!_instance)
_instance=newCLog;
return(_instance);
}
static CLog& GetObj()
{
if(!_instance)
_instance=newCLog;
return(*_instance);
}
template<classT> inline CLog& Write(Tval)
{
(*pf) << val ;
pf->flush();
return *this;
}
template<classT> inline CLog& tmWrite(Tval)
{
charstrBuf[50];
time_tltime;
time( <ime );
struct tm *today = localtime( <ime );
sprintf(strBuf, "%4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d ",
today->tm_year+1900, today->tm_mon+1, today->tm_mday, today->tm_hour,
today->tm_min, today->tm_sec);
(*pf) << strBuf << val << "/r/n";
pf->flush();
return *this;
}
template<classT> inline CLog& operator<< (Tval)
{
(*pf) << val ;
pf->flush();
return *this;
}
};