From cb85aa8a8d02a3d6dc16e3f32e78da9e70f9c7f5 Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期二, 02 二月 2021 17:49:21 +0800 Subject: [PATCH] update --- include/usgcommon/logger.h | 63 +++++++++++++++++-------------- 1 files changed, 34 insertions(+), 29 deletions(-) diff --git a/include/usgcommon/logger.h b/include/usgcommon/logger.h index 4afb855..ccf17cd 100644 --- a/include/usgcommon/logger.h +++ b/include/usgcommon/logger.h @@ -4,41 +4,46 @@ #include "usg_common.h" #include "usg_typedef.h" +struct LoggerConfig { + std::string logFile; + int level; + bool console; +}; + class Logger { - std::string configFile; - int level; +private: + std::string configFile; + LoggerConfig config; + FILE *logFile; - void dolog(const char *fmt, va_list ap) - { - char buf[MAXBUF]; - vsnprintf(buf, MAXBUF-1, fmt, ap); - strcat(buf, "\n"); - fflush(stdout); /* in case stdout and stderr are the same */ - fputs(buf, stdout); - fflush(NULL); /* flushes all stdio output streams */ - } + void dolog(const char *fmt, va_list ap, int level, int err = 0); + + + void init(); + +private: + static const char *LOGGER_LEVEL_STR[] ; public: - enum { - ALL , - DEBUG , - INFO , - WARN , - ERROR , - FATAL , - OFF - }; + enum LoggerLevel { ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF }; - Logger(int l = INFO): level(l) {} - Logger(std::string cf); - - void log(int _level, const char *fmt, ...); + Logger(int l = INFO); + Logger(std::string cf); + Logger(LoggerConfig & conf); - void debug(const char *fmt, ...); - void info(const char *fmt, ...); - void warn(const char *fmt, ...); - void error(const char *fmt, ...); - void fatal(const char *fmt, ...); + ~Logger(); + + void log(int _level, const char *fmt, ...); + + void debug(const char *fmt, ...); + void info(const char *fmt, ...); + void warn(const char *fmt, ...); + void error(const char *fmt, ...); + void error(int err, const char *fmt, ...); + void fatal(const char *fmt, ...); + void fatal(int err, const char *fmt, ...) ; + + static const char * strlevel(int level); }; #endif \ No newline at end of file -- Gitblit v1.8.0