工具类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;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值