工具类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 游戏服务器开发实战》
-
学习地址:
-
优惠推荐码:
2CZ2UA5u
-
可以先免费试学前 2 章内容