对轻量级C++日志类的增强
来源:互联网 发布:微博股票组合数据说明 编辑:程序博客网 时间:2024/05/10 02:10
对轻量级C++日志类的增强
这是网上找到的一个轻量级C++日志类的实现,主要应用了Singleton模式,我增加一个函数tmWrite,主要用来进行前面带时间的行输出。
//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>
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;
}
};
#endif
//end of file
- 对轻量级C++日志类的增强
- 对轻量级C++日志类的增强
- c++对c的增强
- C++对C的增强
- C++对C的增强
- C++对C的增强
- C++对C的增强
- C++对C的增强
- C++对C的增强
- C++对C语言语法的增强
- C++对C的实用性增强
- C++对C语言register的增强
- C++ 对C语言的增强
- 对C语言register的增强
- 05-C++对C的增强
- c++对c语言上的增强
- c++对c对增强实用性”增强
- 轻量级日志类Log
- 使用J2SE1.4开发CORBA程序(一)
- 四川512 7.8级 地震图片
- windows2003计划任务不能启动,"指定的错误是:0x80070005: 拒绝访问"
- [编译原理课程设计] 程序示例一、词法分析器
- Eclipse3.4 has published
- 对轻量级C++日志类的增强
- 存储过程详解
- 完成 ajax.net 的cross domain ajax功能实现
- c++ 如何获得一个变量的类型名称?
- 程序要健壮和易调试
- Grails实战
- C#中的多态性
- Forrester研究报告:Information Fabric——企业数据虚拟化(Part VII、摘要翻译)
- 记忆中的函数