mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-31 00:44:19 +00:00
Write to both stderr and console within same console lock "session"
From 7dd230cd8f
This commit is contained in:
parent
2d66c44b42
commit
363f52df47
39
logging.c
39
logging.c
@ -24,28 +24,18 @@ int opt_log_show_date = false;
|
||||
/* 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, bool force)
|
||||
static void _my_log_curses(int prio, const char *datetime, const char *str)
|
||||
{
|
||||
if (opt_quiet && prio != LOG_ERR)
|
||||
return;
|
||||
|
||||
/* Mutex could be locked by dead thread on shutdown so forcelog will
|
||||
* invalidate any console lock status. */
|
||||
if (force) {
|
||||
mutex_trylock(&console_lock);
|
||||
mutex_unlock(&console_lock);
|
||||
}
|
||||
#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
|
||||
{
|
||||
mutex_lock(&console_lock);
|
||||
printf("%s%s%s", datetime, str, " \n");
|
||||
mutex_unlock(&console_lock);
|
||||
}
|
||||
}
|
||||
|
||||
void applog(int prio, const char* fmt, ...)
|
||||
@ -131,14 +121,25 @@ void _applog(int prio, const char *str, bool force)
|
||||
tm->tm_sec);
|
||||
}
|
||||
|
||||
/* Only output to stderr if it's not going to the screen as well */
|
||||
if (write_stderr) {
|
||||
fprintf(stderr, "%s%s\n", datetime, str); /* atomic write to stderr */
|
||||
fflush(stderr);
|
||||
}
|
||||
if (write_console || write_stderr) {
|
||||
/* Mutex could be locked by dead thread on shutdown so forcelog will
|
||||
* invalidate any console lock status. */
|
||||
if (force) {
|
||||
mutex_trylock(&console_lock);
|
||||
mutex_unlock(&console_lock);
|
||||
}
|
||||
|
||||
if (write_console) {
|
||||
my_log_curses(prio, datetime, str, force);
|
||||
mutex_lock(&console_lock);
|
||||
/* Only output to stderr if it's not going to the screen as well */
|
||||
if (write_stderr) {
|
||||
fprintf(stderr, "%s%s\n", datetime, str); /* atomic write to stderr */
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
if (write_console) {
|
||||
_my_log_curses(prio, datetime, str);
|
||||
}
|
||||
mutex_unlock(&console_lock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2
miner.h
2
miner.h
@ -1460,7 +1460,7 @@ extern void remove_pool(struct pool *pool);
|
||||
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);
|
||||
|
@ -2624,13 +2624,13 @@ static void switch_logsize(bool __maybe_unused newdevs)
|
||||
#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) {
|
||||
@ -2638,7 +2638,6 @@ bool log_curses_only(int prio, const char *datetime, const char *str)
|
||||
wrefresh(logwin);
|
||||
}
|
||||
}
|
||||
unlock_curses();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user