1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-09 14:28:12 +00:00
sgminer/logging.h
Martin Danielsen ba1c47781f log: Added a switch to the log date and time format.
It is possible to switch back to full date and time on each log line with "--log-dateformat 1". The short time-only format is default with the value of 0.

Log with short time-only format looks like:
 [23:59:59] Accepted 389c47d1 Diff 1.16K/512 GPU 0 pool 0
 [00:00:16] Log date is now 2013-12-22
 [00:00:16] Stratum from pool 0 detected new block
 [00:00:33] Accepted 7a4950a4 Diff 536/512 GPU 0 pool 0
2014-01-11 17:32:39 +02:00

113 lines
2.5 KiB
C

#ifndef __LOGGING_H__
#define __LOGGING_H__
#include "config.h"
#include <stdbool.h>
#include <stdarg.h>
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#else
enum {
LOG_ERR,
LOG_WARNING,
LOG_NOTICE,
LOG_INFO,
LOG_DEBUG,
};
#endif
/* debug flags */
extern bool opt_debug;
extern bool opt_log_output;
extern bool opt_realquiet;
extern bool want_per_device_stats;
/* global log_level, messages with lower or equal prio are logged */
extern int opt_log_level;
extern int opt_log_dateformat;
#define LOGBUFSIZ 256
extern void _applog(int prio, const char *str, bool force);
#define IN_FMT_FFL " in %s %s():%d"
#define applog(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, false); \
} \
} \
} while (0)
#define applogsiz(prio, _SIZ, fmt, ...) do { \
if (opt_debug || prio != LOG_DEBUG) { \
if (use_syslog || opt_log_output || prio <= opt_log_level) { \
char tmp42[_SIZ]; \
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
_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)
#define quit(status, fmt, ...) do { \
if (fmt) { \
char tmp42[LOGBUFSIZ]; \
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
_applog(LOG_ERR, tmp42, true); \
} \
_quit(status); \
} while (0)
#define quithere(status, fmt, ...) do { \
if (fmt) { \
char tmp42[LOGBUFSIZ]; \
snprintf(tmp42, sizeof(tmp42), fmt IN_FMT_FFL, \
##__VA_ARGS__, __FILE__, __func__, __LINE__); \
_applog(LOG_ERR, tmp42, true); \
} \
_quit(status); \
} while (0)
#define quitfrom(status, _file, _func, _line, fmt, ...) do { \
if (fmt) { \
char tmp42[LOGBUFSIZ]; \
snprintf(tmp42, sizeof(tmp42), fmt IN_FMT_FFL, \
##__VA_ARGS__, _file, _func, _line); \
_applog(LOG_ERR, tmp42, true); \
} \
_quit(status); \
} while (0)
#ifdef HAVE_CURSES
#define wlog(fmt, ...) do { \
char tmp42[LOGBUFSIZ]; \
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
_wlog(tmp42); \
} while (0)
#define wlogprint(fmt, ...) do { \
char tmp42[LOGBUFSIZ]; \
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
_wlogprint(tmp42); \
} while (0)
#endif
#endif /* __LOGGING_H__ */