mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-10 14:58:01 +00:00
Use log_generic for vapplog to cut down on code duplication
This commit is contained in:
parent
1097aefbad
commit
d2195bd04e
45
logging.c
45
logging.c
@ -39,49 +39,14 @@ static void my_log_curses(__maybe_unused int prio, char *f, va_list ap)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void log_generic(int prio, const char *fmt, va_list ap);
|
||||||
|
|
||||||
void vapplog(int prio, const char *fmt, va_list ap)
|
void vapplog(int prio, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
if (!opt_debug && prio == LOG_DEBUG)
|
if (!opt_debug && prio == LOG_DEBUG)
|
||||||
return;
|
return;
|
||||||
|
if (use_syslog || opt_log_output || prio <= LOG_NOTICE)
|
||||||
#ifdef HAVE_SYSLOG_H
|
log_generic(prio, fmt, ap);
|
||||||
if (use_syslog) {
|
|
||||||
vsyslog(prio, fmt, ap);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (0) {}
|
|
||||||
#endif
|
|
||||||
else if (opt_log_output || prio <= LOG_NOTICE) {
|
|
||||||
char *f;
|
|
||||||
int len;
|
|
||||||
struct timeval tv = {0, 0};
|
|
||||||
struct tm *tm;
|
|
||||||
|
|
||||||
gettimeofday(&tv, NULL);
|
|
||||||
|
|
||||||
tm = localtime(&tv.tv_sec);
|
|
||||||
|
|
||||||
len = 40 + strlen(fmt) + 22;
|
|
||||||
f = alloca(len);
|
|
||||||
sprintf(f, " [%d-%02d-%02d %02d:%02d:%02d] %s\n",
|
|
||||||
tm->tm_year + 1900,
|
|
||||||
tm->tm_mon + 1,
|
|
||||||
tm->tm_mday,
|
|
||||||
tm->tm_hour,
|
|
||||||
tm->tm_min,
|
|
||||||
tm->tm_sec,
|
|
||||||
fmt);
|
|
||||||
/* Only output to stderr if it's not going to the screen as well */
|
|
||||||
if (!isatty(fileno((FILE *)stderr))) {
|
|
||||||
va_list apc;
|
|
||||||
|
|
||||||
va_copy(apc, ap);
|
|
||||||
vfprintf(stderr, f, apc); /* atomic write to stderr */
|
|
||||||
fflush(stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
my_log_curses(prio, f, ap);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void applog(int prio, const char *fmt, ...)
|
void applog(int prio, const char *fmt, ...)
|
||||||
@ -100,7 +65,7 @@ void applog(int prio, const char *fmt, ...)
|
|||||||
* generic log function used by priority specific ones
|
* generic log function used by priority specific ones
|
||||||
* equals vapplog() without additional priority checks
|
* equals vapplog() without additional priority checks
|
||||||
*/
|
*/
|
||||||
static void __maybe_unused log_generic(int prio, const char *fmt, va_list ap)
|
static void log_generic(int prio, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SYSLOG_H
|
#ifdef HAVE_SYSLOG_H
|
||||||
if (use_syslog) {
|
if (use_syslog) {
|
||||||
|
Loading…
Reference in New Issue
Block a user