log.h
来自「试某些程序的时候需要一个轻量级的日志文件作记录」· C头文件 代码 · 共 86 行
H
86 行
//log.h
//hujinshan@2004.1.3 Airforce Engineering University
/*
//CLog* CLog::_instance = NULL;
CLog::GetObj().Write( "******* 初始化完成 *******" ) <<endl;
CLog::GetObj().tmWrite( "******* 开始渲染No1. *******" ) <<endl ;
CLog::GetObj()<< "******* 注销钩子 *******" <<endl;
在Clog文件中有 #define CLog /##/ 的语句,
这是为了使日志在release版无效,
使用单行注释,所以如果调用时如果要换行,
请务必在换行最后加上 \ 符号,
*/
#ifndef _DEBUG
#define CLog /##/
#define _CLOG_H
#endif
#ifndef _CLOG_H
#define _CLOG_H
#pragma once
#include <fstream.h>
#include <ctime>
class CLog
{
CLog()
{
pf= new ofstream ("dbg_log.log" /*, ios::app */);
}
static CLog* _instance;
ofstream* pf;
public:
~CLog()
{
_instance=0;
pf->close();
}
static CLog* GetPtr()
{
if(!_instance)
_instance=new CLog;
return(_instance);
}
static CLog& GetObj()
{
if(!_instance)
_instance=new CLog;
return(*_instance);
}
template<class T> inline CLog& Write(T val)
{
(*pf) << val ;
pf->flush();
return *this;
}
template<class T> inline CLog& tmWrite(T val)
{
time_t ltime;
time( <ime );
(*pf) << "--- "<< ctime( <ime ) << val ;
pf->flush();
return *this;
}
template<class T> inline CLog& operator<< (T val)
{
(*pf) << val ;
pf->flush();
return *this;
}
};
#endif
//end of file
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?