mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-10 02:40:40 +03:00
fixed building for --without-debug
make coap_log re-definable
This commit is contained in:
1 parent
7d674d9dcf
commit
a6fe6a30d3
2 files changed
+32
-28
No files matched your search
@@ -41,8 +41,6 @@ static char *loglevels[] = {
|
||||
"EMRG", "ALRT", "CRIT", "WARN", "NOTE", "INFO", "DEBG"
|
||||
};
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
||||
#ifdef HAVE_TIME_H
|
||||
|
||||
static inline size_t
|
||||
@@ -64,6 +62,8 @@ print_timestamp(char *s, size_t len, coap_tick_t t) {
|
||||
|
||||
#endif /* HAVE_TIME_H */
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
||||
/**
|
||||
* A length-safe strlen() fake.
|
||||
*
|
||||
@@ -80,31 +80,6 @@ strnlen(unsigned char *s, size_t maxlen) {
|
||||
return n;
|
||||
}
|
||||
|
||||
void
|
||||
coap_log(coap_log_t level, char *format, ...) {
|
||||
char timebuf[32];
|
||||
coap_tick_t now;
|
||||
va_list ap;
|
||||
FILE *log_fd;
|
||||
|
||||
if (maxlog < level)
|
||||
return;
|
||||
|
||||
log_fd = level <= LOG_CRIT ? COAP_ERR_FD : COAP_DEBUG_FD;
|
||||
|
||||
coap_ticks(&now);
|
||||
if (print_timestamp(timebuf,sizeof(timebuf), now))
|
||||
fprintf(log_fd, "%s ", timebuf);
|
||||
|
||||
if (level <= LOG_DEBUG)
|
||||
fprintf(log_fd, "%s ", loglevels[level]);
|
||||
|
||||
va_start(ap, format);
|
||||
vfprintf(log_fd, format, ap);
|
||||
va_end(ap);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
unsigned int
|
||||
print_readable( const unsigned char *data, unsigned int len,
|
||||
unsigned char *result, unsigned int buflen, int encode_always ) {
|
||||
@@ -222,3 +197,28 @@ coap_show_pdu(const coap_pdu_t *pdu) {
|
||||
}
|
||||
|
||||
#endif /* NDEBUG */
|
||||
|
||||
void
|
||||
coap_log_impl(coap_log_t level, char *format, ...) {
|
||||
char timebuf[32];
|
||||
coap_tick_t now;
|
||||
va_list ap;
|
||||
FILE *log_fd;
|
||||
|
||||
if (maxlog < level)
|
||||
return;
|
||||
|
||||
log_fd = level <= LOG_CRIT ? COAP_ERR_FD : COAP_DEBUG_FD;
|
||||
|
||||
coap_ticks(&now);
|
||||
if (print_timestamp(timebuf,sizeof(timebuf), now))
|
||||
fprintf(log_fd, "%s ", timebuf);
|
||||
|
||||
if (level <= LOG_DEBUG)
|
||||
fprintf(log_fd, "%s ", loglevels[level]);
|
||||
|
||||
va_start(ap, format);
|
||||
vfprintf(log_fd, format, ap);
|
||||
va_end(ap);
|
||||
fflush(stdout);
|
||||
}
|
||||
@@ -34,7 +34,11 @@ void coap_set_log_level(coap_log_t level);
|
||||
* text is output only when @p level is below or equal to the log
|
||||
* level that set by coap_set_log_level().
|
||||
*/
|
||||
void coap_log(coap_log_t level, char *format, ...);
|
||||
void coap_log_impl(coap_log_t level, char *format, ...);
|
||||
|
||||
#ifndef coap_log
|
||||
#define coap_log(...) coap_log_impl(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
||||
|
||||
Reference in new issue
Block a user