From 2b1f534ea407a8ec0b94e0389a360f6cdff54598 Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期三, 08 九月 2021 14:02:38 +0800 Subject: [PATCH] call C.BHFree after return success --- include/usgcommon/logger.h | 42 ++++++++++++++++++++++++------------------ 1 files changed, 24 insertions(+), 18 deletions(-) diff --git a/include/usgcommon/logger.h b/include/usgcommon/logger.h index a9e4de4..ccf17cd 100644 --- a/include/usgcommon/logger.h +++ b/include/usgcommon/logger.h @@ -4,32 +4,34 @@ #include "usg_common.h" #include "usg_typedef.h" +struct LoggerConfig { + std::string logFile; + int level; + bool console; +}; + class Logger { +private: std::string configFile; - int level; + LoggerConfig config; + FILE *logFile; - void dolog(const char *fmt, va_list ap) { - char buf[MAXBUF]; + void dolog(const char *fmt, va_list ap, int level, int err = 0); - struct timeval tv; - struct tm *info; - gettimeofday(&tv, NULL); - info = localtime(&tv.tv_sec); - strftime(buf, MAXLINE - 1, "%Y-%d-%m %H:%M:%S ", info); - snprintf(buf + strlen(buf), MAXLINE - strlen(buf) - 1, "(%ld) ", tv.tv_sec * 1000000 + tv.tv_usec); + + void init(); - vsnprintf(buf + strlen(buf), MAXLINE - strlen(buf) - 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 */ - } - +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(int l = INFO); Logger(std::string cf); + Logger(LoggerConfig & conf); + + ~Logger(); void log(int _level, const char *fmt, ...); @@ -37,7 +39,11 @@ 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