2019-12-21 10:50:15 +00:00
|
|
|
#ifndef CPP11FEATURETEST_LOGER_H
|
|
|
|
#define CPP11FEATURETEST_LOGER_H
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
2021-12-16 03:01:39 +00:00
|
|
|
#include <mutex>
|
2023-06-05 11:43:30 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <string>
|
|
|
|
|
2019-12-21 10:50:15 +00:00
|
|
|
|
|
|
|
using namespace std;
|
2021-12-16 03:01:39 +00:00
|
|
|
typedef enum {
|
2021-12-15 08:19:59 +00:00
|
|
|
Mode_Daily, // 每天保存一次日志
|
|
|
|
MODE_Monthly, // 每个月保存一次日志
|
2021-12-15 09:34:02 +00:00
|
|
|
MODE_Weekly, // 每周保存一次日志
|
|
|
|
MODE_Size // 根据已存储的容量来保存日志
|
2021-12-16 03:01:39 +00:00
|
|
|
}Mode;
|
2021-12-15 08:19:59 +00:00
|
|
|
|
2021-12-16 03:01:39 +00:00
|
|
|
typedef enum {
|
|
|
|
LEVEL_DEBUG = 0, // 调试模式所有日志都会显示
|
|
|
|
LEVEL_INFO, // INFO和WARNING和ERROR
|
|
|
|
LEVEL_WARNING, // WARNING和ERROR
|
|
|
|
LEVEL_ERROR // 仅显示ERROR
|
|
|
|
}Level;
|
2021-12-15 08:19:59 +00:00
|
|
|
|
2021-12-15 09:34:02 +00:00
|
|
|
class Loger {
|
2021-12-15 08:19:59 +00:00
|
|
|
public:
|
2021-12-15 09:34:02 +00:00
|
|
|
Loger(string path,string prefix);
|
2021-12-16 03:01:39 +00:00
|
|
|
Loger(string path,string prefix,bool old);
|
|
|
|
~Loger();
|
2021-12-16 03:18:22 +00:00
|
|
|
#define FILE_POSITION __FILE__,__LINE__
|
2021-12-16 03:01:39 +00:00
|
|
|
void SetMinimalLevel(Level);
|
|
|
|
void SetWorkMode(Mode);
|
|
|
|
int Debug(string,string file = __FILE__,int line = __LINE__);
|
|
|
|
int Info(string,string file = __FILE__,int line = __LINE__);
|
|
|
|
int Warning(string,string file = __FILE__,int line = __LINE__);
|
|
|
|
int Error(string,string file = __FILE__,int line = __LINE__);
|
2023-06-05 11:43:30 +00:00
|
|
|
int DumpOBJ(void *dst,int rowNum,int num,bool ifAsii,char *out);
|
2021-12-16 03:01:39 +00:00
|
|
|
|
2021-12-15 08:19:59 +00:00
|
|
|
void operator+(const string&);
|
|
|
|
void operator<<(const string&);
|
2021-12-15 09:34:02 +00:00
|
|
|
private:
|
|
|
|
string mPath;
|
|
|
|
string mPrefix;
|
|
|
|
string mCurrentPath;
|
|
|
|
FILE *mFile; // 日志文件
|
2021-12-16 03:01:39 +00:00
|
|
|
Mode mMode; // 工作模式
|
|
|
|
Level mLevel; // 最低调试输出
|
2021-12-15 09:34:02 +00:00
|
|
|
string mCurrentDate; // 当天
|
|
|
|
bool mValid;
|
2021-12-16 03:01:39 +00:00
|
|
|
std::mutex mMux;
|
2021-12-15 09:34:02 +00:00
|
|
|
};
|
2019-12-21 10:50:15 +00:00
|
|
|
|
2021-12-16 03:01:39 +00:00
|
|
|
#endif
|