2014-04-03 16:12:35 +00:00
|
|
|
#ifndef LOGGING_H
|
|
|
|
#define LOGGING_H
|
2012-02-11 18:31:34 +00:00
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_SYSLOG_H
|
|
|
|
#include <syslog.h>
|
|
|
|
#else
|
|
|
|
enum {
|
2014-06-10 15:13:54 +00:00
|
|
|
LOG_ERR,
|
|
|
|
LOG_WARNING,
|
|
|
|
LOG_NOTICE,
|
|
|
|
LOG_INFO,
|
|
|
|
LOG_DEBUG,
|
2012-02-11 18:31:34 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2013-06-15 12:03:56 +00:00
|
|
|
/* debug flags */
|
2012-02-11 18:31:34 +00:00
|
|
|
extern bool opt_debug;
|
2014-07-05 23:07:32 +00:00
|
|
|
extern bool opt_debug_console;
|
2014-07-05 22:03:11 +00:00
|
|
|
extern bool opt_verbose;
|
2012-09-01 08:21:08 +00:00
|
|
|
extern bool opt_realquiet;
|
|
|
|
extern bool want_per_device_stats;
|
2012-02-11 18:31:34 +00:00
|
|
|
|
|
|
|
/* global log_level, messages with lower or equal prio are logged */
|
|
|
|
extern int opt_log_level;
|
|
|
|
|
2014-01-11 15:29:16 +00:00
|
|
|
extern int opt_log_show_date;
|
2014-01-09 20:41:03 +00:00
|
|
|
|
2014-06-10 14:36:53 +00:00
|
|
|
#define LOGBUFSIZ 512
|
2013-06-15 12:03:56 +00:00
|
|
|
|
2014-02-03 13:03:49 +00:00
|
|
|
void applog(int prio, const char* fmt, ...);
|
2014-06-10 14:36:53 +00:00
|
|
|
void applogsiz(int prio, int size, const char* fmt, ...);
|
|
|
|
void vapplogsiz(int prio, int size, const char* fmt, va_list args);
|
|
|
|
|
2013-10-18 12:30:05 +00:00
|
|
|
extern void _applog(int prio, const char *str, bool force);
|
2013-06-15 12:03:56 +00:00
|
|
|
|
2013-08-11 22:38:02 +00:00
|
|
|
#define IN_FMT_FFL " in %s %s():%d"
|
|
|
|
|
2013-10-18 12:30:05 +00:00
|
|
|
#define forcelog(prio, fmt, ...) do { \
|
2014-06-10 14:36:53 +00:00
|
|
|
if (opt_debug || prio != LOG_DEBUG) { \
|
2014-07-05 23:07:32 +00:00
|
|
|
char tmp42[LOGBUFSIZ]; \
|
|
|
|
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
|
|
|
|
_applog(prio, tmp42, true); \
|
2014-06-10 14:36:53 +00:00
|
|
|
} \
|
2013-08-31 03:41:37 +00:00
|
|
|
} while (0)
|
|
|
|
|
2013-06-15 12:03:56 +00:00
|
|
|
#define quit(status, fmt, ...) do { \
|
2014-06-10 14:36:53 +00:00
|
|
|
if (fmt) { \
|
|
|
|
char tmp42[LOGBUFSIZ]; \
|
|
|
|
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
|
|
|
|
_applog(LOG_ERR, tmp42, true); \
|
|
|
|
} \
|
|
|
|
_quit(status); \
|
2013-06-15 12:03:56 +00:00
|
|
|
} while (0)
|
|
|
|
|
2013-08-11 22:38:02 +00:00
|
|
|
#define quithere(status, fmt, ...) do { \
|
2014-06-10 14:36:53 +00:00
|
|
|
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); \
|
2013-08-11 22:38:02 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define quitfrom(status, _file, _func, _line, fmt, ...) do { \
|
2014-06-10 14:36:53 +00:00
|
|
|
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); \
|
2013-08-11 22:38:02 +00:00
|
|
|
} while (0)
|
|
|
|
|
2013-06-15 12:03:56 +00:00
|
|
|
#ifdef HAVE_CURSES
|
|
|
|
|
|
|
|
#define wlog(fmt, ...) do { \
|
2014-06-10 14:36:53 +00:00
|
|
|
char tmp42[LOGBUFSIZ]; \
|
|
|
|
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
|
|
|
|
_wlog(tmp42); \
|
2013-05-02 12:50:25 +00:00
|
|
|
} while (0)
|
2012-02-11 18:31:34 +00:00
|
|
|
|
2013-06-15 12:03:56 +00:00
|
|
|
#define wlogprint(fmt, ...) do { \
|
2014-06-10 14:36:53 +00:00
|
|
|
char tmp42[LOGBUFSIZ]; \
|
|
|
|
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
|
|
|
|
_wlogprint(tmp42); \
|
2013-06-15 12:03:56 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#endif
|
2012-02-11 18:31:34 +00:00
|
|
|
|
2014-11-04 04:38:13 +00:00
|
|
|
extern void __debug(const char *filename, const char *fmt, ...);
|
|
|
|
|
|
|
|
|
2014-04-03 16:12:35 +00:00
|
|
|
#endif /* LOGGING_H */
|