Browse Source

Include microseconds in log output with new --log-microseconds option

Luke Dashjr 12 years ago
parent
commit
2c2167dc98
4 changed files with 19 additions and 1 deletions
  1. 1 0
      README
  2. 14 1
      logging.c
  3. 1 0
      logging.h
  4. 3 0
      miner.c

+ 1 - 0
README

@@ -178,6 +178,7 @@ Options for both config file and command line:
 --kernel-path|-K <arg> Specify a path to where bitstream and kernel files are (default: "/usr/local/bin")
 --load-balance      Change multipool strategy from failover to efficiency based balance
 --log|-l <arg>      Interval in seconds between log output (default: 5)
+--log-microseconds  Include microseconds in log output
 --monitor|-m <arg>  Use custom pipe cmd for output messages
 --net-delay         Impose small delays in networking to not overload slow routers
 --no-gbt            Disable getblocktemplate support

+ 14 - 1
logging.c

@@ -20,6 +20,7 @@
 bool opt_debug = false;
 bool opt_debug_console = false;  // Only used if opt_debug is also enabled
 bool opt_log_output = false;
+bool opt_log_microseconds;
 
 /* per default priorities higher than LOG_NOTICE are logged */
 int opt_log_level = LOG_NOTICE;
@@ -104,8 +105,20 @@ static void log_generic(int prio, const char *fmt, va_list ap)
 
 		localtime_r(&tv.tv_sec, tm);
 
-		len = 40 + strlen(fmt) + 22;
+		// NOTE: my_log_curses appends 20 spaces
+		len = 40 + strlen(fmt) + 22  + 7 /* microseconds */;
 		f = alloca(len);
+		if (opt_log_microseconds)
+			sprintf(f, " [%d-%02d-%02d %02d:%02d:%02d.%06ld] %s\n",
+				tm->tm_year + 1900,
+				tm->tm_mon + 1,
+				tm->tm_mday,
+				tm->tm_hour,
+				tm->tm_min,
+				tm->tm_sec,
+				(long)tv.tv_usec,
+				fmt);
+		else
 		sprintf(f, " [%d-%02d-%02d %02d:%02d:%02d] %s\n",
 			tm->tm_year + 1900,
 			tm->tm_mon + 1,

+ 1 - 0
logging.h

@@ -30,6 +30,7 @@ enum {
 extern bool opt_debug;
 extern bool opt_debug_console;
 extern bool opt_log_output;
+extern bool opt_log_microseconds;
 extern bool opt_realquiet;
 extern bool want_per_device_stats;
 

+ 3 - 0
miner.c

@@ -1371,6 +1371,9 @@ static struct opt_table opt_config_table[] = {
 	OPT_WITH_ARG("--log|-l",
 		     set_int_0_to_9999, opt_show_intval, &opt_log_interval,
 		     "Interval in seconds between log output"),
+	OPT_WITHOUT_ARG("--log-microseconds",
+	                opt_set_bool, &opt_log_microseconds,
+	                "Include microseconds in log output"),
 #if defined(unix)
 	OPT_WITH_ARG("--monitor|-m",
 		     opt_set_charp, NULL, &opt_stderr_cmd,