1 /* debug.h -- debug utilities
3 * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
5 * This file is part of the CoAP library libcoap. Please see
6 * README for terms of use.
10 #define _COAP_DEBUG_H_
19 #define COAP_DEBUG_FD stdout
23 #define COAP_ERR_FD stderr
28 typedef short coap_log_t;
30 /** Pre-defined log levels akin to what is used in \b syslog. */
31 typedef enum { LOG_EMERG=0, LOG_ALERT, LOG_CRIT, LOG_WARNING,
32 LOG_NOTICE, LOG_INFO, LOG_DEBUG
38 /** Returns the current log level. */
39 coap_log_t coap_get_log_level();
41 /** Sets the log level to the specified value. */
42 void coap_set_log_level(coap_log_t level);
45 * Writes the given text to @c COAP_ERR_FD (for @p level <= @c
46 * LOG_CRIT) or @c COAP_DEBUG_FD (for @p level >= @c LOG_WARNING). The
47 * text is output only when @p level is below or equal to the log
48 * level that set by coap_set_log_level().
50 void coap_log_impl(coap_log_t level, const char *format, ...);
53 #define coap_log(...) coap_log_impl(__VA_ARGS__)
56 #if !defined(TB_LOG) && !defined(NDEBUG)
62 /* A set of convenience macros for common log levels. */
63 #define info(...) coap_log(LOG_INFO, __VA_ARGS__)
64 #define warn(...) coap_log(LOG_WARNING, __VA_ARGS__)
65 #define debug(...) coap_log(LOG_DEBUG, __VA_ARGS__)
67 #define DO_PRAGMA(x) _Pragma (#x)
68 #define TODO(x) DO_PRAGMA(message ("TODO - " #x))
71 void coap_show_pdu(const coap_pdu_t *);
74 size_t coap_print_addr(const coap_address_t *, unsigned char *, size_t);
84 #define coap_show_pdu(x)
85 #define coap_print_addr(...)
93 #endif /* _COAP_DEBUG_H_ */