zoukankan      html  css  js  c++  java
  • 对轻量级C++日志类[转]

    //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()
             {      
                       pfnewofstream ("inmstrace.log"ios::app);
             }
     
             static CLog_instance;
             ofstreampf;
    public:
             ~CLog()
             {
                      _instance=0;                  
                      pf->close();
             }
     
             static CLogGetPtr()
             {
                      if(!_instance)
                                _instance=newCLog;
                      return(_instance);
             }
     
             static CLogGetObj()
             {
                      if(!_instance)
                                _instance=newCLog;
                      return(*_instance);
             }
     
             template<classT> inline CLogWrite(Tval)
             {
                       (*pf) << val ;
                      pf->flush();
                       return *this;
             }
            
             template<classT> inline CLogtmWrite(Tval)
             {
            charstrBuf[50];       
            time_tltime;
            time( &ltime );
            struct tm *today = localtime( &ltime );
            sprintf(strBuf"%4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d ",
                today->tm_year+1900, today->tm_mon+1, today->tm_mdaytoday->tm_hour,
                today->tm_mintoday->tm_sec);
           
                       (*pf) << strBuf << val << "/r/n";
                      pf->flush();
                       return *this;
             }
     
             template<classT> inline CLog& operator<< (Tval)
             {
                       (*pf) << val ;
                      pf->flush();
                       return *this;
             }
     
    };
     
    #endif
  • 相关阅读:
    ie标题修改
    求两个数的商在单元格内设置公示显示#ERROR
    明细报表汇总使用说明
    学习了GDI+ 做了个简单的折线图。
    C#读写文本文件,字符串截取
    C#winform去除btn按钮的边框
    观江南大学设计学院2011届迎新晚会有感
    c++的一个程序源码记录
    c#中委托的概念一个总结demo
    《平凡的世界》中田晓霞和孙少平的爱情
  • 原文地址:https://www.cnblogs.com/rooney/p/2595432.html
Copyright © 2011-2022 走看看