Amit Pundir | d477f82 | 2020-02-07 22:26:08 +0530 | [diff] [blame^] | 1 | #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 | |
| 14 | void qlog_setup(const char *tag, bool use_syslog); |
| 15 | void qlog_set_min_priority(int priority); |
| 16 | |
| 17 | void 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 |