1 #ifndef NDNDPDK_CORE_LOGGER_H
2 #define NDNDPDK_CORE_LOGGER_H
8 #undef RTE_LOG_DP_LEVEL
10 #define RTE_LOG_DP_LEVEL N_LOG_LEVEL
12 #define RTE_LOG_DP_LEVEL RTE_LOG_DEBUG
15 #define N_LOG_INIT(module) \
16 static int RTE_LOGTYPE_NDN = -1; \
17 RTE_INIT(Logger_Init_##module) { \
18 RTE_LOGTYPE_NDN = rte_log_register_type_and_pick_level("NDN." #module, RTE_LOG_INFO); \
20 struct AllowTrailingSemicolon_
22 #define N_LOG(lvl, fmt, ...) RTE_LOG_DP(lvl, NDN, fmt "\n", ##__VA_ARGS__)
24 #define N_LOGV(...) N_LOG(DEBUG, __VA_ARGS__)
25 #define N_LOGD(...) N_LOG(INFO, __VA_ARGS__)
26 #define N_LOGI(...) N_LOG(NOTICE, __VA_ARGS__)
27 #define N_LOGW(...) N_LOG(WARNING, __VA_ARGS__)
28 #define N_LOGE(...) N_LOG(ERR, __VA_ARGS__)
30 #define N_LOG_ERROR(s) " ERROR={" s "}"
31 #define N_LOG_ERROR_BLANK N_LOG_ERROR("-")
32 #define N_LOG_ERROR_ERRNO N_LOG_ERROR("errno<%d>")
33 #define N_LOG_ERROR_STR N_LOG_ERROR("%s")
39 #define N_LOG_ENABLED(lvl) \
40 (RTE_LOG_DP_LEVEL >= RTE_LOG_##lvl && rte_log_get_level(RTE_LOGTYPE_NDN) >= (int)RTE_LOG_##lvl)
42 __attribute__((nonnull))
int
45 __attribute__((nonnull))
void
46 Logger_Spdk(
int level,
const char* restrict file,
const int line,
const char* restrict func,
47 const char* restrict format, va_list args);
54 __attribute__((nonnull))
void
72 #define DebugString_Use(capacity) DebugString* myDebugString = DebugString_Get((capacity))
78 #define DebugString_Append(fn, ...) \
80 myDebugString->pos += fn(RTE_PTR_ADD(myDebugString->buffer, myDebugString->pos), \
81 myDebugString->cap - myDebugString->pos, __VA_ARGS__); \
85 #define DebugString_Return() \
87 NDNDPDK_ASSERT(myDebugString->pos < myDebugString->cap); \
88 return myDebugString->buffer; \
DebugString * DebugString_Get(size_t capacity)
Obtain a buffer for populating a debug string.
Definition: logger.c:68
struct DebugString DebugString
void Logger_Spdk(int level, const char *restrict file, const int line, const char *restrict func, const char *restrict format, va_list args)
Definition: logger.c:35
int Logger_Dpdk_Init(FILE *output)
Definition: logger.c:15
void Logger_HexDump(const uint8_t *b, size_t count)
Print buffer in hexadecimal to stderr.
Definition: logger.c:51
uint32_t cap
Definition: logger.h:59
uint32_t pos
Definition: logger.h:58
char buffer[8]
Definition: logger.h:60