qrtr/lib/logging.h
Eric Caruso c1bdfb37db logging: add min priority and other cleanup
The dprintf macro shadows a real libc symbol which is called
differently, so we should change it to something else (in this
case LOGD) and change it to use the libqrtr logging facilities.
This also means we should add a minimum priority to the logging
library so we don't log DEBUG-level messages by default.

Additionally there were some warn/warnx calls left over that
have been changed to PLOGW/LOGW respectively.
2018-12-10 16:03:04 -08:00

37 lines
1.0 KiB
C

#ifndef _QRTR_LOGGING_H_
#define _QRTR_LOGGING_H_
#include <stdbool.h>
#include <stdlib.h>
#include <syslog.h>
#if defined(__GNUC__) || defined(__clang__)
#define __PRINTF__(fmt, args) __attribute__((format(__printf__, fmt, args)))
#else
#define __PRINTF__(fmt, args)
#endif
void qlog_setup(const char *tag, bool use_syslog);
void qlog_set_min_priority(int priority);
void qlog(int priority, const char *format, ...) __PRINTF__(2, 3);
#define LOGD(fmt, ...) qlog(LOG_DEBUG, fmt, ##__VA_ARGS__)
#define LOGW(fmt, ...) qlog(LOG_WARNING, fmt, ##__VA_ARGS__)
#define PLOGW(fmt, ...) \
qlog(LOG_WARNING, fmt ": %s", ##__VA_ARGS__, strerror(errno))
#define LOGE(fmt, ...) qlog(LOG_ERR, fmt, ##__VA_ARGS__)
#define PLOGE(fmt, ...) qlog(LOG_ERR, fmt ": %s", ##__VA_ARGS__, strerror(errno))
#define LOGE_AND_EXIT(fmt, ...) do { \
qlog(LOG_ERR, fmt, ##__VA_ARGS__); \
exit(1); \
} while(0)
#define PLOGE_AND_EXIT(fmt, ...) do { \
qlog(LOG_ERR, fmt ": %s", ##__VA_ARGS__, strerror(errno)); \
exit(1); \
} while(0)
#endif