2024-08-13 17:48:35 +00:00
|
|
|
#ifndef LOGGING_H
|
|
|
|
#define LOGGING_H
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#define LOG_LEVEL (config.verbose)
|
|
|
|
|
|
|
|
#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
|
|
|
|
#define lgerror(msg, ret, ...) __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>
|
|
|
|
#define lgerror(msg, ret, ...) __extension__ ({ \
|
|
|
|
errno = -(ret); \
|
|
|
|
printf(msg ": %s\n", ##__VA_ARGS__, strerror(errno)); \
|
|
|
|
})
|
|
|
|
#endif /* PROGRAM_SPACE */
|
|
|
|
|
2024-08-27 16:27:27 +00:00
|
|
|
#define lgdebug(msg, ...) \
|
|
|
|
(LOG_LEVEL >= VERBOSE_DEBUG ? printf(msg, ##__VA_ARGS__) : 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, ...) \
|
|
|
|
(LOG_LEVEL >= VERBOSE_TRACE ? printf(msg, ##__VA_ARGS__) : 0)
|
|
|
|
|
|
|
|
#define lgtracemsg(msg, ...) lgtrace(msg "\n", __VA_ARGS__)
|
2024-08-13 17:48:35 +00:00
|
|
|
|
|
|
|
#define lgtrace_start(msg, ...) \
|
|
|
|
(LOG_LEVEL >= VERBOSE_TRACE ? printf("[TRACE] " msg " ( ", ##__VA_ARGS__) : 0)
|
|
|
|
|
|
|
|
#define lgtrace_addp(msg, ...) \
|
|
|
|
(LOG_LEVEL >= VERBOSE_TRACE ? printf(msg", ", ##__VA_ARGS__) : 0)
|
|
|
|
|
|
|
|
#define lgtrace_end() \
|
|
|
|
(LOG_LEVEL >= VERBOSE_TRACE ? printf(") \n") : 0)
|
|
|
|
|
|
|
|
#endif /* LOGGING_H */
|