Eric Caruso | f64c25c | 2018-04-30 16:33:18 -0700 | [diff] [blame] | 1 | #ifndef _QRTR_LOGGING_H_ |
| 2 | #define _QRTR_LOGGING_H_ |
| 3 | |
Eric Caruso | de5ee77 | 2018-04-30 17:07:41 -0700 | [diff] [blame^] | 4 | #include <stdbool.h> |
Eric Caruso | f64c25c | 2018-04-30 16:33:18 -0700 | [diff] [blame] | 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 | |
Eric Caruso | de5ee77 | 2018-04-30 17:07:41 -0700 | [diff] [blame^] | 14 | void qlog_setup(const char *tag, bool use_syslog); |
Eric Caruso | f64c25c | 2018-04-30 16:33:18 -0700 | [diff] [blame] | 15 | |
| 16 | void qlog(int priority, const char *format, ...) __PRINTF__(2, 3); |
| 17 | |
| 18 | #define LOGW(fmt, ...) qlog(LOG_WARNING, fmt, ##__VA_ARGS__) |
| 19 | #define PLOGW(fmt, ...) \ |
| 20 | qlog(LOG_WARNING, fmt ": %s", ##__VA_ARGS__, strerror(errno)) |
| 21 | |
| 22 | #define LOGE(fmt, ...) qlog(LOG_ERR, fmt, ##__VA_ARGS__) |
| 23 | #define PLOGE(fmt, ...) qlog(LOG_ERR, fmt ": %s", ##__VA_ARGS__, strerror(errno)) |
| 24 | #define LOGE_AND_EXIT(fmt, ...) do { \ |
| 25 | qlog(LOG_ERR, fmt, ##__VA_ARGS__); \ |
| 26 | exit(1); \ |
| 27 | } while(0) |
| 28 | #define PLOGE_AND_EXIT(fmt, ...) do { \ |
| 29 | qlog(LOG_ERR, fmt ": %s", ##__VA_ARGS__, strerror(errno)); \ |
| 30 | exit(1); \ |
| 31 | } while(0) |
| 32 | |
| 33 | #endif |