Browse Source

New --debuglog option to include debug info in stderr logfile even if not in the console

Luke Dashjr 13 years ago
parent
commit
7fe5cc4f0a
4 changed files with 24 additions and 10 deletions
  1. 1 0
      README
  2. 11 6
      cgminer.c
  3. 11 4
      logging.c
  4. 1 0
      logging.h

+ 1 - 0
README

@@ -143,6 +143,7 @@ Options for both config file and command line:
 --auto-gpu          Automatically adjust all GPU engine clock speeds to maintain a target temperature
 --benchmark         Run cgminer in benchmark mode - produces no shares
 --debug|-D          Enable debug output
+--debuglog          Enable debug logging
 --expiry|-E <arg>   Upper bound on how many seconds after getting work we consider a share from it stale (default: 120)
 --failover-only     Don't leak work to backup pools when primary pool is lagging
 --kernel-path|-K <arg> Specify a path to where bitstream and kernel files are (default: "/usr/local/bin")

+ 11 - 6
cgminer.c

@@ -607,6 +607,7 @@ static char *set_userpass(const char *arg)
 static char *enable_debug(bool *flag)
 {
 	*flag = true;
+	opt_debug_console = true;
 	/* Turn on verbose output, too. */
 	opt_log_output = true;
 	return NULL;
@@ -802,6 +803,9 @@ static struct opt_table opt_config_table[] = {
 	OPT_WITHOUT_ARG("--debug|-D",
 		     enable_debug, &opt_debug,
 		     "Enable debug output"),
+	OPT_WITHOUT_ARG("--debuglog",
+		     opt_set_bool, &opt_debug,
+		     "Enable debug logging"),
 	OPT_WITH_ARG("--device|-d",
 		     set_devices, NULL, NULL,
 	             "Select device to use, (Use repeat -d for multiple devices, default: all)"),
@@ -3223,7 +3227,7 @@ static void display_options(void)
 retry:
 	wlogprint("[N]ormal [C]lear [S]ilent mode (disable all output)\n");
 	wlogprint("[D]ebug:%s\n[P]er-device:%s\n[Q]uiet:%s\n[V]erbose:%s\n[R]PC debug:%s\n[L]og interval:%d\n",
-		opt_debug ? "on" : "off",
+		opt_debug_console ? "on" : "off",
 	        want_per_device_stats? "on" : "off",
 		opt_quiet ? "on" : "off",
 		opt_log_output ? "on" : "off",
@@ -3243,18 +3247,19 @@ retry:
 		goto retry;
 	} else if (!strncasecmp(&input, "n", 1)) {
 		opt_log_output = false;
-		opt_debug = false;
+		opt_debug_console = false;
 		opt_quiet = false;
 		opt_protocol = false;
 		want_per_device_stats = false;
 		wlogprint("Output mode reset to normal\n");
 		goto retry;
 	} else if (!strncasecmp(&input, "d", 1)) {
-		opt_debug ^= true;
-		opt_log_output = opt_debug;
-		if (opt_debug)
+		opt_debug = true;
+		opt_debug_console ^= true;
+		opt_log_output = opt_debug_console;
+		if (opt_debug_console)
 			opt_quiet = false;
-		wlogprint("Debug mode %s\n", opt_debug ? "enabled" : "disabled");
+		wlogprint("Debug mode %s\n", opt_debug_console ? "enabled" : "disabled");
 		goto retry;
 	} else if (!strncasecmp(&input, "p", 1)) {
 		want_per_device_stats ^= true;

+ 11 - 4
logging.c

@@ -13,6 +13,7 @@
 #include "miner.h"
 
 bool opt_debug = false;
+bool opt_debug_console = false;  // Only used if opt_debug is also enabled
 bool opt_log_output = false;
 
 /* per default priorities higher than LOG_NOTICE are logged */
@@ -46,8 +47,8 @@ void vapplog(int prio, const char *fmt, va_list ap)
 {
 	if (!opt_debug && prio == LOG_DEBUG)
 		return;
-	if (use_syslog || opt_log_output || prio <= LOG_NOTICE)
-		log_generic(prio, fmt, ap);
+
+	log_generic(prio, fmt, ap);
 }
 
 void applog(int prio, const char *fmt, ...)
@@ -76,6 +77,11 @@ static void log_generic(int prio, const char *fmt, va_list ap)
 	if (0) {}
 #endif
 	else {
+		bool writetocon = opt_debug_console || (opt_log_output && prio != LOG_DEBUG) || prio <= LOG_NOTICE;
+		bool writetofile = !isatty(fileno((FILE *)stderr));
+		if (!(writetocon || writetofile))
+			return;
+
 		char *f;
 		int len;
 		struct timeval tv = {0, 0};
@@ -96,7 +102,7 @@ static void log_generic(int prio, const char *fmt, va_list ap)
 			tm->tm_sec,
 			fmt);
 		/* Only output to stderr if it's not going to the screen as well */
-		if (!isatty(fileno((FILE *)stderr))) {
+		if (writetofile) {
 			va_list apc;
 
 			va_copy(apc, ap);
@@ -104,7 +110,8 @@ static void log_generic(int prio, const char *fmt, va_list ap)
 			fflush(stderr);
 		}
 
-		my_log_curses(prio, f, ap);
+		if (writetocon)
+			my_log_curses(prio, f, ap);
 	}
 }
 /* we can not generalize variable argument list */

+ 1 - 0
logging.h

@@ -19,6 +19,7 @@ enum {
 
 /* original / legacy debug flags */
 extern bool opt_debug;
+extern bool opt_debug_console;
 extern bool opt_log_output;
 
 /* global log_level, messages with lower or equal prio are logged */