libcoap  4.1.1
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
debug.h
Go to the documentation of this file.
1 /* debug.h -- debug utilities
2  *
3  * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
4  *
5  * This file is part of the CoAP library libcoap. Please see
6  * README for terms of use.
7  */
8 
9 #ifndef _COAP_DEBUG_H_
10 #define _COAP_DEBUG_H_
11 
12 #include "config.h"
13 
14 #ifndef COAP_DEBUG_FD
15 #define COAP_DEBUG_FD stdout
16 #endif
17 
18 #ifndef COAP_ERR_FD
19 #define COAP_ERR_FD stderr
20 #endif
21 
22 #ifdef HAVE_SYSLOG_H
23 #include <syslog.h>
24 typedef short coap_log_t;
25 #else
26 
27 typedef enum { LOG_EMERG=0, LOG_ALERT, LOG_CRIT, LOG_WARNING,
28  LOG_NOTICE, LOG_INFO, LOG_DEBUG
29 } coap_log_t;
30 #endif
31 
34 
36 void coap_set_log_level(coap_log_t level);
37 
44 void coap_log_impl(coap_log_t level, const char *format, ...);
45 
46 #ifndef coap_log
47 #define coap_log(...) coap_log_impl(__VA_ARGS__)
48 #endif
49 
50 #ifndef NDEBUG
51 
52 /* A set of convenience macros for common log levels. */
53 #define info(...) coap_log(LOG_INFO, __VA_ARGS__)
54 #define warn(...) coap_log(LOG_WARNING, __VA_ARGS__)
55 #define debug(...) coap_log(LOG_DEBUG, __VA_ARGS__)
56 
57 #include "pdu.h"
58 void coap_show_pdu(const coap_pdu_t *);
59 
60 struct coap_address_t;
61 size_t coap_print_addr(const struct coap_address_t *, unsigned char *, size_t);
62 
63 #else
64 
65 #define debug(...)
66 #define info(...)
67 #define warn(...)
68 
69 #define coap_show_pdu(x)
70 #define coap_print_addr(...)
71 
72 #endif
73 
74 #endif /* _COAP_DEBUG_H_ */
void coap_show_pdu(const coap_pdu_t *)
Definition: debug.c:231
short coap_log_t
Definition: debug.h:24
void coap_log_impl(coap_log_t level, const char *format,...)
Writes the given text to COAP_ERR_FD (for level <= LOG_CRIT) or COAP_DEBUG_FD (for level >= LOG_WARNI...
Definition: debug.c:325
void coap_set_log_level(coap_log_t level)
Sets the log level to the specified value.
Definition: debug.c:46
Header structure for CoAP PDUs.
Definition: pdu.h:206
coap_log_t coap_get_log_level()
Returns the current log level.
Definition: debug.c:41
size_t coap_print_addr(const struct coap_address_t *, unsigned char *, size_t)
Definition: debug.c:140