NDN-DPDK
High-Speed Named Data Networking Forwarder
Loading...
Searching...
No Matches
logger.h
Go to the documentation of this file.
1#ifndef NDNDPDK_CORE_LOGGER_H
2#define NDNDPDK_CORE_LOGGER_H
3
5
6#include "common.h"
7
8#undef RTE_LOG_DP_LEVEL
9#ifdef N_LOG_LEVEL
10#define RTE_LOG_DP_LEVEL N_LOG_LEVEL
11#else
12#define RTE_LOG_DP_LEVEL RTE_LOG_DEBUG
13#endif
14
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); \
19 } \
20 struct AllowTrailingSemicolon_
21
22#define N_LOG(lvl, fmt, ...) RTE_LOG_DP(lvl, NDN, fmt "\n", ##__VA_ARGS__)
23
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__)
29
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")
34
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)
41
42__attribute__((nonnull)) int
43Logger_Dpdk_Init(FILE* output);
44
45__attribute__((nonnull)) void
46Logger_Spdk(int level, const char* restrict file, const int line, const char* restrict func,
47 const char* restrict format, va_list args);
48
54__attribute__((nonnull)) void
55Logger_HexDump(const uint8_t* b, size_t count);
56
57typedef struct DebugString {
58 uint32_t pos;
59 uint32_t cap;
60 char buffer[8]; // actual capacity is DebugString_MaxCapacity
62
68__attribute__((returns_nonnull)) DebugString*
69DebugString_Get(size_t capacity);
70
72#define DebugString_Use(capacity) DebugString* myDebugString = DebugString_Get((capacity))
73
78#define DebugString_Append(fn, ...) \
79 do { \
80 myDebugString->pos += fn(RTE_PTR_ADD(myDebugString->buffer, myDebugString->pos), \
81 myDebugString->cap - myDebugString->pos, __VA_ARGS__); \
82 } while (false)
83
85#define DebugString_Return() \
86 do { \
87 NDNDPDK_ASSERT(myDebugString->pos < myDebugString->cap); \
88 return myDebugString->buffer; \
89 } while (false)
90
91#endif // NDNDPDK_CORE_LOGGER_H
DebugString * DebugString_Get(size_t capacity)
Obtain a buffer for populating a debug string.
Definition logger.c:68
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
Definition logger.h:57
uint32_t cap
Definition logger.h:59
uint32_t pos
Definition logger.h:58
char buffer[8]
Definition logger.h:60