2024-08-13 17:48:35 +00:00
|
|
|
#ifndef LOGGING_H
|
|
|
|
#define LOGGING_H
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#define LOG_LEVEL (config.verbose)
|
2024-11-26 16:58:55 +00:00
|
|
|
#define USE_SYSLOG (config.syslog)
|
2024-08-13 17:48:35 +00:00
|
|
|
|
|
|
|
#ifdef KERNEL_SPACE
|
2024-09-20 19:32:30 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
2024-08-13 17:48:35 +00:00
|
|
|
#define printf pr_info
|
|
|
|
#define perror pr_err
|
2024-11-26 16:58:55 +00:00
|
|
|
|
|
|
|
#define log_message(level, msg, ...) \
|
|
|
|
(printf(msg, ##__VA_ARGS__))
|
|
|
|
|
|
|
|
#define lgerror(ret, msg, ...) __extension__ ({ \
|
2024-09-01 13:07:47 +00:00
|
|
|
pr_err(msg ": %d\n", ##__VA_ARGS__, ret); \
|
2024-08-13 17:48:35 +00:00
|
|
|
})
|
|
|
|
#else
|
|
|
|
#include <stdio.h> // IWYU pragma: export
|
|
|
|
#include <errno.h>
|
2024-11-26 16:58:55 +00:00
|
|
|
#include <syslog.h>
|
|
|
|
|
|
|
|
#define log_message(level, msg, ...) \
|
|
|
|
(config.syslog ? (void)(syslog((level), msg, ##__VA_ARGS__)) : (void)(printf(msg, ##__VA_ARGS__)))
|
|
|
|
|
|
|
|
#define lgerror(ret, msg, ...) __extension__ ({ \
|
2024-08-13 17:48:35 +00:00
|
|
|
errno = -(ret); \
|
2024-11-26 16:58:55 +00:00
|
|
|
log_message(LOG_ERR, msg ": %s\n", ##__VA_ARGS__, strerror(errno)); \
|
2024-08-13 17:48:35 +00:00
|
|
|
})
|
|
|
|
#endif /* PROGRAM_SPACE */
|
|
|
|
|
2024-11-26 16:58:55 +00:00
|
|
|
#define lgerr(msg, ...) \
|
|
|
|
(log_message(LOG_ERR, msg, ##__VA_ARGS__))
|
|
|
|
|
|
|
|
#define lgwarning(msg, ...) \
|
|
|
|
(log_message(LOG_WARN, msg, ##__VA_ARGS__))
|
|
|
|
|
|
|
|
|
|
|
|
#define lginfo(msg, ...) \
|
|
|
|
(log_message(LOG_INFO, msg, ##__VA_ARGS__))
|
|
|
|
|
|
|
|
#define print_message(...) \
|
|
|
|
(lginfo(__VA_ARGS__))
|
|
|
|
|
2024-08-27 16:27:27 +00:00
|
|
|
#define lgdebug(msg, ...) \
|
2024-11-26 16:58:55 +00:00
|
|
|
(LOG_LEVEL >= VERBOSE_DEBUG ? log_message(LOG_INFO, msg, ##__VA_ARGS__) : (void)0)
|
2024-08-13 17:48:35 +00:00
|
|
|
|
2024-08-27 16:27:27 +00:00
|
|
|
#define lgdebugmsg(msg, ...) lgdebug(msg "\n", ##__VA_ARGS__)
|
2024-08-13 17:48:35 +00:00
|
|
|
|
2024-08-21 09:25:13 +00:00
|
|
|
|
|
|
|
#define lgtrace(msg, ...) \
|
2024-11-26 16:58:55 +00:00
|
|
|
(LOG_LEVEL >= VERBOSE_TRACE ? log_message(LOG_INFO, msg, ##__VA_ARGS__) : (void)0)
|
2024-08-21 09:25:13 +00:00
|
|
|
|
|
|
|
#define lgtracemsg(msg, ...) lgtrace(msg "\n", __VA_ARGS__)
|
2024-08-13 17:48:35 +00:00
|
|
|
|
|
|
|
#define lgtrace_start(msg, ...) \
|
2024-11-26 16:58:55 +00:00
|
|
|
(LOG_LEVEL >= VERBOSE_TRACE ? log_message(LOG_INFO, "[TRACE] " msg " ( ", ##__VA_ARGS__) : (void)0)
|
2024-08-13 17:48:35 +00:00
|
|
|
|
|
|
|
#define lgtrace_addp(msg, ...) \
|
2024-11-26 16:58:55 +00:00
|
|
|
(LOG_LEVEL >= VERBOSE_TRACE ? log_message(LOG_INFO, msg", ", ##__VA_ARGS__) : (void)0)
|
2024-08-13 17:48:35 +00:00
|
|
|
|
|
|
|
#define lgtrace_end() \
|
2024-11-26 16:58:55 +00:00
|
|
|
(LOG_LEVEL >= VERBOSE_TRACE ? log_message(LOG_INFO, ") \n") : (void)0)
|
2024-08-13 17:48:35 +00:00
|
|
|
|
|
|
|
#endif /* LOGGING_H */
|