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_
15 #define COAP_DEBUG_FD stdout
19 #define COAP_ERR_FD stderr
24 typedef short coap_log_t;
26 /** Pre-defined log levels akin to what is used in \b syslog. */
27 typedef enum { LOG_EMERG=0, LOG_ALERT, LOG_CRIT, LOG_WARNING,
28 LOG_NOTICE, LOG_INFO, LOG_DEBUG
33 #define DO_PRAGMA(x) _Pragma (#x)
34 #define TODO(x) DO_PRAGMA(message ("TODO - " #x))
36 /** Returns the current log level. */
37 coap_log_t coap_get_log_level();
39 /** Sets the log level to the specified value. */
40 void coap_set_log_level(coap_log_t level);
43 * Writes the given text to @c COAP_ERR_FD (for @p level <= @c
44 * LOG_CRIT) or @c COAP_DEBUG_FD (for @p level >= @c LOG_WARNING). The
45 * text is output only when @p level is below or equal to the log
46 * level that set by coap_set_log_level().
48 void coap_log_impl(coap_log_t level, const char *format, ...);
51 #define coap_log(...) coap_log_impl(__VA_ARGS__)
56 /* A set of convenience macros for common log levels. */
57 #define info(...) coap_log(LOG_INFO, __VA_ARGS__)
58 #define warn(...) coap_log(LOG_WARNING, __VA_ARGS__)
59 #define debug(...) coap_log(LOG_DEBUG, __VA_ARGS__)
62 void coap_show_pdu(const coap_pdu_t *);
64 struct coap_address_t;
65 size_t coap_print_addr(const struct coap_address_t *, unsigned char *, size_t);
73 #define coap_show_pdu(x)
74 #define coap_print_addr(...)
78 #endif /* _COAP_DEBUG_H_ */