Browse Source

Add a forcelog variant of applog which invalidates any console lock to force output.

nfactor-troky
Con Kolivas 11 years ago
parent
commit
8e9f32a81b
  1. 2
      cgminer.c
  2. 12
      logging.c
  3. 22
      logging.h
  4. 2
      usbutils.c

2
cgminer.c

@ -423,7 +423,7 @@ static void applog_and_exit(const char *fmt, ...) @@ -423,7 +423,7 @@ static void applog_and_exit(const char *fmt, ...)
va_start(ap, fmt);
vsnprintf(exit_buf, sizeof(exit_buf), fmt, ap);
va_end(ap);
_applog(LOG_ERR, exit_buf);
_applog(LOG_ERR, exit_buf, true);
exit(1);
}

12
logging.c

@ -21,11 +21,17 @@ bool opt_log_output = false; @@ -21,11 +21,17 @@ bool opt_log_output = 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)
static void my_log_curses(int prio, const char *datetime, const char *str, bool force)
{
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))
@ -44,7 +50,7 @@ static void my_log_curses(int prio, const char *datetime, const char *str) @@ -44,7 +50,7 @@ static void my_log_curses(int prio, const char *datetime, const char *str)
/*
* log function
*/
void _applog(int prio, const char *str)
void _applog(int prio, const char *str, bool force)
{
#ifdef HAVE_SYSLOG_H
if (use_syslog) {
@ -77,6 +83,6 @@ void _applog(int prio, const char *str) @@ -77,6 +83,6 @@ void _applog(int prio, const char *str)
fflush(stderr);
}
my_log_curses(prio, datetime, str);
my_log_curses(prio, datetime, str, force);
}
}

22
logging.h

@ -28,7 +28,7 @@ extern int opt_log_level; @@ -28,7 +28,7 @@ extern int opt_log_level;
#define LOGBUFSIZ 256
extern void _applog(int prio, const char *str);
extern void _applog(int prio, const char *str, bool force);
#define IN_FMT_FFL " in %s %s():%d"
@ -37,7 +37,7 @@ extern void _applog(int prio, const char *str); @@ -37,7 +37,7 @@ extern void _applog(int prio, const char *str);
if (use_syslog || opt_log_output || prio <= opt_log_level) { \
char tmp42[LOGBUFSIZ]; \
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
_applog(prio, tmp42); \
_applog(prio, tmp42, false); \
} \
} \
} while (0)
@ -47,7 +47,17 @@ extern void _applog(int prio, const char *str); @@ -47,7 +47,17 @@ extern void _applog(int prio, const char *str);
if (use_syslog || opt_log_output || prio <= opt_log_level) { \
char tmp42[_SIZ]; \
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
_applog(prio, tmp42); \
_applog(prio, tmp42, false); \
} \
} \
} while (0)
#define forcelog(prio, fmt, ...) do { \
if (opt_debug || prio != LOG_DEBUG) { \
if (use_syslog || opt_log_output || prio <= opt_log_level) { \
char tmp42[LOGBUFSIZ]; \
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
_applog(prio, tmp42, true); \
} \
} \
} while (0)
@ -56,7 +66,7 @@ extern void _applog(int prio, const char *str); @@ -56,7 +66,7 @@ extern void _applog(int prio, const char *str);
if (fmt) { \
char tmp42[LOGBUFSIZ]; \
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
_applog(LOG_ERR, tmp42); \
_applog(LOG_ERR, tmp42, true); \
} \
_quit(status); \
} while (0)
@ -66,7 +76,7 @@ extern void _applog(int prio, const char *str); @@ -66,7 +76,7 @@ extern void _applog(int prio, const char *str);
char tmp42[LOGBUFSIZ]; \
snprintf(tmp42, sizeof(tmp42), fmt IN_FMT_FFL, \
##__VA_ARGS__, __FILE__, __func__, __LINE__); \
_applog(LOG_ERR, tmp42); \
_applog(LOG_ERR, tmp42, true); \
} \
_quit(status); \
} while (0)
@ -76,7 +86,7 @@ extern void _applog(int prio, const char *str); @@ -76,7 +86,7 @@ extern void _applog(int prio, const char *str);
char tmp42[LOGBUFSIZ]; \
snprintf(tmp42, sizeof(tmp42), fmt IN_FMT_FFL, \
##__VA_ARGS__, _file, _func, _line); \
_applog(LOG_ERR, tmp42); \
_applog(LOG_ERR, tmp42, true); \
} \
_quit(status); \
} while (0)

2
usbutils.c

@ -933,7 +933,7 @@ void usb_all(int level) @@ -933,7 +933,7 @@ void usb_all(int level)
for (i = 0; i < count; i++)
usb_full(&j, list[i], &buf, &off, &len, level);
_applog(LOG_WARNING, buf);
_applog(LOG_WARNING, buf, false);
free(buf);

Loading…
Cancel
Save