generallib/general/inc/loger.h

58 lines
1.6 KiB
C++

#ifndef CPP11FEATURETEST_LOGER_H
#define CPP11FEATURETEST_LOGER_H
#include <stdio.h>
#include <time.h>
#include <fstream>
#include <iostream>
#include <mutex>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;
typedef enum {
Mode_Daily, // 每天保存一次日志
MODE_Monthly, // 每个月保存一次日志
MODE_Weekly, // 每周保存一次日志
MODE_Size // 根据已存储的容量来保存日志
}Mode;
typedef enum {
LEVEL_DEBUG = 0, // 调试模式所有日志都会显示
LEVEL_INFO, // INFO和WARNING和ERROR
LEVEL_WARNING, // WARNING和ERROR
LEVEL_ERROR // 仅显示ERROR
}Level;
class Loger {
public:
Loger(string path,string prefix);
Loger(string path,string prefix,bool old);
~Loger();
#define FILE_POSITION __FILE__,__LINE__
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__);
int DumpOBJ(void *dst,int rowNum,int num,bool ifAsii,char *out);
void operator+(const string&);
void operator<<(const string&);
private:
string mPath;
string mPrefix;
string mCurrentPath;
FILE *mFile; // 日志文件
Mode mMode; // 工作模式
Level mLevel; // 最低调试输出
string mCurrentDate; // 当天
bool mValid;
std::mutex mMux;
};
#endif