From 3afe38168c44b59f1732f2d55ec08b8f81d879bc Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期五, 17 七月 2020 11:54:08 +0800
Subject: [PATCH] commit -a

---
 include/usgcommon/logger.h |   57 ++++++++++++++++++++++++++++-----------------------------
 1 files changed, 28 insertions(+), 29 deletions(-)

diff --git a/include/usgcommon/logger.h b/include/usgcommon/logger.h
index 4afb855..a9e4de4 100644
--- a/include/usgcommon/logger.h
+++ b/include/usgcommon/logger.h
@@ -5,40 +5,39 @@
 #include "usg_typedef.h"
 
 class Logger {
-	std::string configFile;
-	int level;
+  std::string configFile;
+  int level;
 
-	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) {
+    char buf[MAXBUF];
+
+    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);
+
+    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 */
+  }
+
 public:
-	enum {
-		ALL ,
-		DEBUG ,
-		INFO ,
-		WARN ,
-		ERROR ,
-		FATAL ,
-		OFF
-	};
+  enum { ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF };
 
-	Logger(int l = INFO): level(l) {}
-	Logger(std::string cf);
-	
+  Logger(int l = INFO) : level(l) {}
+  Logger(std::string cf);
 
-	void log(int _level,  const char *fmt,  ...);
+  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 fatal(const char *fmt, ...);
+  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, ...);
 };
 
 #endif
\ No newline at end of file

--
Gitblit v1.8.0