Browse Source

Write to both stderr and console within same console lock "session"

Luke Dashjr 12 years ago
parent
commit
7dd230cd8f
3 changed files with 18 additions and 17 deletions
  1. 14 13
      logging.c
  2. 3 3
      miner.c
  3. 1 1
      miner.h

+ 14 - 13
logging.c

@@ -25,22 +25,18 @@ bool opt_log_microseconds;
 /* per default priorities higher than LOG_NOTICE are logged */
 int opt_log_level = LOG_NOTICE;
 
-static void my_log_curses(int prio, const char *datetime, const char *str)
+static void _my_log_curses(int prio, const char *datetime, const char *str)
 {
 	if (opt_quiet && prio != LOG_ERR)
 		return;
 
 #ifdef HAVE_CURSES
 	extern bool use_curses;
-	if (use_curses && log_curses_only(prio, datetime, str))
+	if (use_curses && _log_curses_only(prio, datetime, str))
 		;
 	else
 #endif
-	{
-		bfg_console_lock();
 		printf(" %s %s%s", datetime, str, "                    \n");
-		bfg_console_unlock();
-	}
 }
 
 /* high-level logging function, based on global opt_log_level */
@@ -86,15 +82,20 @@ void _applog(int prio, const char *str)
 		else
 			get_now_datestamp(datetime);
 
-		/* Only output to stderr if it's not going to the screen as well */
-		if (writetofile) {
+		if (writetofile || writetocon)
+		{
 			bfg_console_lock();
-			fprintf(stderr, " %s %s\n", datetime, str);	/* atomic write to stderr */
-			fflush(stderr);
+			
+			/* Only output to stderr if it's not going to the screen as well */
+			if (writetofile) {
+				fprintf(stderr, " %s %s\n", datetime, str);	/* atomic write to stderr */
+				fflush(stderr);
+			}
+
+			if (writetocon)
+				_my_log_curses(prio, datetime, str);
+			
 			bfg_console_unlock();
 		}
-
-		if (writetocon)
-			my_log_curses(prio, datetime, str);
 	}
 }

+ 3 - 3
miner.c

@@ -2838,13 +2838,14 @@ void _wlogprint(const char *str)
 #endif
 
 #ifdef HAVE_CURSES
-bool log_curses_only(int prio, const char *datetime, const char *str)
+bool _log_curses_only(int prio, const char *datetime, const char *str)
 {
 	bool high_prio;
 
 	high_prio = (prio == LOG_WARNING || prio == LOG_ERR);
 
-	if (curses_active_locked()) {
+	if (curses_active)
+	{
 		if (!opt_loginput || high_prio) {
 			wprintw(logwin, " %s %s\n", datetime, str);
 			if (high_prio) {
@@ -2852,7 +2853,6 @@ bool log_curses_only(int prio, const char *datetime, const char *str)
 				wrefresh(logwin);
 			}
 		}
-		unlock_curses();
 		return true;
 	}
 	return false;

+ 1 - 1
miner.h

@@ -1308,7 +1308,7 @@ extern void write_config(FILE *fcfg);
 extern void zero_bestshare(void);
 extern void zero_stats(void);
 extern void default_save_file(char *filename);
-extern bool log_curses_only(int prio, const char *datetime, const char *str);
+extern bool _log_curses_only(int prio, const char *datetime, const char *str);
 extern void clear_logwin(void);
 extern void logwin_update(void);
 extern bool pool_tclear(struct pool *pool, bool *var);