libcoap  4.1.2
debug.h
Go to the documentation of this file.
1 /*
2  * debug.h -- debug utilities
3  *
4  * Copyright (C) 2010-2011,2014 Olaf Bergmann <bergmann@tzi.org>
5  *
6  * This file is part of the CoAP library libcoap. Please see README for terms
7  * of use.
8  */
9 
10 #ifndef _COAP_DEBUG_H_
11 #define _COAP_DEBUG_H_
12 
13 #ifndef COAP_DEBUG_FD
14 #define COAP_DEBUG_FD stdout
15 #endif
16 
17 #ifndef COAP_ERR_FD
18 #define COAP_ERR_FD stderr
19 #endif
20 
21 #ifdef HAVE_SYSLOG_H
22 #include <syslog.h>
23 typedef short coap_log_t;
24 #else
25 
26 typedef enum {
35 } coap_log_t;
36 #endif
37 
40 
42 void coap_set_log_level(coap_log_t level);
43 
45 const char *coap_package_name(void);
46 
48 const char *coap_package_version(void);
49 
55 void coap_log_impl(coap_log_t level, const char *format, ...);
56 
57 #ifndef coap_log
58 #define coap_log(...) coap_log_impl(__VA_ARGS__)
59 #endif
60 
61 #ifndef NDEBUG
62 
63 /* A set of convenience macros for common log levels. */
64 #define info(...) coap_log(LOG_INFO, __VA_ARGS__)
65 #define warn(...) coap_log(LOG_WARNING, __VA_ARGS__)
66 #define debug(...) coap_log(LOG_DEBUG, __VA_ARGS__)
67 
68 #include "pdu.h"
69 void coap_show_pdu(const coap_pdu_t *);
70 
71 struct coap_address_t;
72 size_t coap_print_addr(const struct coap_address_t *, unsigned char *, size_t);
73 
74 #else
75 
76 #define debug(...)
77 #define info(...)
78 #define warn(...)
79 
80 #define coap_show_pdu(x)
81 #define coap_print_addr(...)
82 
83 #endif /* NDEBUG */
84 
85 #endif /* _COAP_DEBUG_H_ */
Definition: debug.h:33
coap_log_t coap_get_log_level(void)
Returns the current log level.
Definition: debug.c:60
multi-purpose address abstraction
Definition: address.h:59
void coap_show_pdu(const coap_pdu_t *)
Definition: debug.c:375
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:483
void coap_set_log_level(coap_log_t level)
Sets the log level to the specified value.
Definition: debug.c:65
Header structure for CoAP PDUs.
Definition: pdu.h:227
coap_log_t
Pre-defined log levels akin to what is used in syslog.
Definition: debug.h:26
const char * coap_package_name(void)
Returns a zero-terminated string with the name of this library.
Definition: debug.c:51
Definition: debug.h:29
Pre-defined constants that reflect defaults for CoAP.
Definition: debug.h:30
const char * coap_package_version(void)
Returns a zero-terminated string with the library version.
Definition: debug.c:55
size_t coap_print_addr(const struct coap_address_t *, unsigned char *, size_t)
Definition: debug.c:162