Skip to content

Commit ba830a3

Browse files
benpiccoboaks
authored andcommitted
dtls_debug: mock dsrv_log() when NDEBUG is set
Setting NDEBUG already replaces dtls_dsrv_hexdump_log(), dtls_dsrv_log_addr() etc with dummy implementations. This extends this to also replace dsrv_log() and dtls_{get,set}_log_level() with a no-op implementation.
1 parent 7fd6414 commit ba830a3

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

dtls_debug.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ typedef int in_port_t;
5353
LOG_MODULE_REGISTER(TINYDTLS, CONFIG_TINYDTLS_LOG_LEVEL);
5454
#endif /* WITH_ZEPHYR */
5555

56-
static int maxlog = DTLS_LOG_WARN; /* default maximum log level */
57-
5856
const char *dtls_package_name(void) {
5957
return PACKAGE_NAME;
6058
}
@@ -63,6 +61,9 @@ const char *dtls_package_version(void) {
6361
return PACKAGE_VERSION;
6462
}
6563

64+
#ifndef NDEBUG
65+
static int maxlog = DTLS_LOG_WARN; /* default maximum log level */
66+
6667
log_t
6768
dtls_get_log_level(void) {
6869
return maxlog;
@@ -103,8 +104,6 @@ print_timestamp(char *s, size_t len, clock_time_t t) {
103104

104105
#endif /* HAVE_TIME_H */
105106

106-
#ifndef NDEBUG
107-
108107
/**
109108
* A length-safe strlen() fake.
110109
*
@@ -242,8 +241,6 @@ dsrv_print_addr(const session_t *addr, char *buf, size_t len) {
242241
#endif /* ! HAVE_INET_NTOP */
243242
}
244243

245-
#endif /* NDEBUG */
246-
247244
#if !defined(WITH_CONTIKI) && !defined(_MSC_VER)
248245

249246
static void
@@ -334,7 +331,6 @@ dsrv_log(log_t level, char *format, ...) {
334331
}
335332
#endif /* WITH_CONTIKI */
336333

337-
#ifndef NDEBUG
338334
/** dumps packets in usual hexdump format */
339335
void hexdump(const unsigned char *packet, int length) {
340336
int n = 0;
@@ -499,6 +495,16 @@ dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, s
499495

500496
#else /* NDEBUG */
501497

498+
log_t
499+
dtls_get_log_level(void) {
500+
return 0;
501+
}
502+
503+
void
504+
dtls_set_log_level(log_t level) {
505+
(void)level;
506+
}
507+
502508
void
503509
hexdump(const unsigned char *packet, int length) {
504510
(void)packet;
@@ -520,6 +526,12 @@ dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, s
520526
(void)extend;
521527
}
522528

529+
void
530+
dsrv_log(log_t level, const char *format, ...) {
531+
(void)level;
532+
(void)format;
533+
}
534+
523535
void
524536
dtls_dsrv_log_addr(log_t level, const char *name, const session_t *addr) {
525537
(void)level;

0 commit comments

Comments
 (0)