2 Star 8 Fork 5

CodeDog / sample_log

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
logger.h 2.23 KB
一键复制 编辑 原始数据 按行查看 历史
ye ye ye ye 提交于 2023-09-15 21:36 . 优化
#pragma once
#include "logdef.h"
//NAMESPACE_BEG
enum LOG_MODE {
MODE_CONSL=1,
MODE_FILE=2,
MODE_CUST=4,
};
enum LOG_LEVEL {
INF = 1,
WAR = 2,
ERR = 4,
FAT = 8,
BUG = 16,
};
enum LOG_FORMAT {
DIS_FILE = 1,
DIS_FUN = 2,
DIS_LIN = 4,
DIS_COLOR = 8,
DIS_TIME = 16,
DIS_THID = 32,
DIS_LOG_LEVEL=64,
};
class Device {
public:
virtual void print(LOG_LEVEL level,const char* file, const char* fun, int64_t line_, uint64_t time, const char* log) = 0;
};
void addDevice(Device* dev);
struct ErrorTrace {
const char* file_;
const char* fun_;
int line_;
uint64_t thrad_id_;
uint64_t time_;
std::string log_;
};
void setLogConfig(const char* save_dir="./log",size_t max_file_size=1024*1024*50,bool open_log_que=true);
void setLogPrintMode(int mode =1);
void setLoggerLevel(int level=31);
void setLogFormat(int format=127);
std::ostream& Info(const char* file, const char* fun, int line);
void Infof(const char* file, const char* fun, int line, const char* format, ...);
std::ostream& Warn(const char* file, const char* fun, int line);
void Warnf(const char* file, const char* fun, int line,const char* format, ...);
std::ostream& Debug(const char* file, const char* fun, int len);
void Debugf(const char* file, const char* fun, int len, const char* format, ...);
std::ostream& Error(const char* file, const char* fun, int len);
void Errorf(const char* file, const char* fun, int len, const char* format, ...);
const ErrorTrace& GetLastErrorLog();
void LogEnd();
#define CLOG_ERR(format,...) Errorf(__FILE__,__FUNCTION__,__LINE__,format,__VA_ARGS__)
#define CLOG_INF(format,...) Infof(__FILE__,__FUNCTION__,__LINE__,format,__VA_ARGS__)
#define CLOG_WAR(format,...) Warnf(__FILE__,__FUNCTION__,__LINE__,format,__VA_ARGS__)
#define CLOG_BUG(format,...) Debugf(__FILE__,__FUNCTION__,__LINE__,format,__VA_ARGS__)
#if 1
#define LOG_ERR Error(__FILE__,__FUNCTION__,__LINE__)
#define LOG_INF Info(__FILE__,__FUNCTION__,__LINE__)
#define LOG_WAR Warn(__FILE__,__FUNCTION__,__LINE__)
#define LOG_BUG Debug(__FILE__,__FUNCTION__,__LINE__)
#else
#define LOG_ERR std::cerr
#define LOG_INF std::cerr
#define LOG_WAR std::cerr
#define LOG_BUG std::cerr
#endif
//NAMESPACE_END
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/codedoggg/sample_log.git
git@gitee.com:codedoggg/sample_log.git
codedoggg
sample_log
sample_log
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891