Skip to content

Commit

Permalink
Write to both stderr and console within same console lock "session"
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-jr committed Jul 15, 2013
1 parent dcfbb7b commit 7dd230c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
27 changes: 14 additions & 13 deletions logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -2838,21 +2838,21 @@ 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) {
touchwin(logwin);
wrefresh(logwin);
}
}
unlock_curses();
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7dd230c

Please sign in to comment.