blob: 90ada7a4fc8fa0f8589948aba92947465a408782 [file] [log] [blame]
Eric Carusof64c25c2018-04-30 16:33:18 -07001#ifndef _QRTR_LOGGING_H_
2#define _QRTR_LOGGING_H_
3
4#include <stdlib.h>
5#include <syslog.h>
6
7#if defined(__GNUC__) || defined(__clang__)
8#define __PRINTF__(fmt, args) __attribute__((format(__printf__, fmt, args)))
9#else
10#define __PRINTF__(fmt, args)
11#endif
12
13void qlog_setup(const char *tag);
14
15void qlog(int priority, const char *format, ...) __PRINTF__(2, 3);
16
17#define LOGW(fmt, ...) qlog(LOG_WARNING, fmt, ##__VA_ARGS__)
18#define PLOGW(fmt, ...) \
19 qlog(LOG_WARNING, fmt ": %s", ##__VA_ARGS__, strerror(errno))
20
21#define LOGE(fmt, ...) qlog(LOG_ERR, fmt, ##__VA_ARGS__)
22#define PLOGE(fmt, ...) qlog(LOG_ERR, fmt ": %s", ##__VA_ARGS__, strerror(errno))
23#define LOGE_AND_EXIT(fmt, ...) do { \
24 qlog(LOG_ERR, fmt, ##__VA_ARGS__); \
25 exit(1); \
26 } while(0)
27#define PLOGE_AND_EXIT(fmt, ...) do { \
28 qlog(LOG_ERR, fmt ": %s", ##__VA_ARGS__, strerror(errno)); \
29 exit(1); \
30 } while(0)
31
32#endif