• 工具类Log和Trace


    代码地址:https://github.com/hanxi/Log

    /*=============================================================================
    #     FileName: log.h
    #         Desc: 日志记录,只支持单线程,支持网页格式
    #       Author: hanxi
    #        Email: hanxi.com@gmail.com
    #     HomePage: http://hanxi.cnblogs.com
    #      Version: 0.0.1
    #   LastChange: 2013-03-07 18:24:21
    #      History:
    =============================================================================*/
    
    #ifndef __LOG_H_
    #define __LOG_H_
    
    //STD
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <ctime>
    #include <cstdlib>
    
    #define HTML_LOG   1     //输出为html格式
    #define TXT_LOG    2     //输出为txt格式
    
    class Log
    {
    private:
        static std::ofstream     ms_file;          //log文件流
        static const char       *ms_path;          //log文件路径
        static int               ms_logLevel;      //小于logLevel的log将被打印出来
        static int               ms_logFileType;   //log文件类型
    
        int                      m_nowLevel;
        std::string             *m_theFunctionName;//进入的函数名
    
    public:
        static void s_init(const char *i_path, int i_logLevel, int i_fileType);
        static void s_stop();
        static const char *endl;
    
        Log(const char *funcName, int logLevel);
        ~Log();
    
        template<typename Type>
        void debug(Type msg);
        template<typename Type>
        Log& operator<<(Type msg);
    };
    // 初始化静态成员变量
    std::ofstream     Log::ms_file;
    const char       *Log::ms_path = NULL;       //log文件路径
    int               Log::ms_logLevel = 0;      //小于logLevel的log将被打印出来
    int               Log::ms_logFileType = 0;   //log文件类型
    const char       *Log::endl = "\n";
    /*=============================================================================
    #     FileName: trace.h
    #         Desc: 调试类
    #       Author: hanxi
    #        Email: hanxi.com@gmail.com
    #     HomePage: http://hanxi.cnblogs.com
    #      Version: 0.0.1
    #   LastChange: 2013-03-08 13:05:03
    #      History:
    =============================================================================*/
    #ifndef __TRACE_H_ 
    #define __TRACE_H_ 
    
    #include <iostream>
    using namespace std;
    
    class Trace {
    public:
        Trace (const char *name);
        ~Trace ();
        void debug (const string &msg);
    
        static bool traceIsActive;
    
    private:
        string *theFunctionName;
    };
    bool Trace::traceIsActive = false;

    作者:涵曦www.hanxi.cc
    出处:hanxi.cnblogs.com
    GitHub:github.com/hanxi
    Email:im.hanxi@gmail.com
    文章版权归本人所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

    《 Skynet 游戏服务器开发实战》

  • 相关阅读:
    【测试技术】ant在测试中的使用@文件以及目录的读写删和复制
    【测试环境】java|jdk|ant
    【测试理论】入行7年,一点感悟
    home_work picture
    linux shell awk 语法
    linux shell 指令 诸如-d, -f, -e之类的判断表达式
    软件测试工作这两年来,我丢失了什么?(一)
    软件测试工作近两年来的感想和未来规划(一)
    用Python进行SQLite数据库操作
    python selenium xpath定位时使用变量
  • 原文地址:https://www.cnblogs.com/hanxi/p/2950093.html
Copyright © 2020-2023  润新知