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