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 {
34 } coap_log_t;
35 #endif
36 
39 
41 void coap_set_log_level(coap_log_t level);
42 
44 const char *coap_package_name(void);
45 
47 const char *coap_package_version(void);
48 
54 void coap_log_impl(coap_log_t level, const char *format, ...);
55 
56 #ifndef coap_log
57 #define coap_log(...) coap_log_impl(__VA_ARGS__)
58 #endif
59 
60 #ifndef NDEBUG
61 
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__)
66 
67 #include "pdu.h"
68 void coap_show_pdu(const coap_pdu_t *);
69 
70 struct coap_address_t;
71 size_t coap_print_addr(const struct coap_address_t *, unsigned char *, size_t);
72 
73 #else
74 
75 #define debug(...)
76 #define info(...)
77 #define warn(...)
78 
79 #define coap_show_pdu(x)
80 #define coap_print_addr(...)
81 
82 #endif /* NDEBUG */
83 
84 #endif /* _COAP_DEBUG_H_ */
Definition: debug.h:32
coap_log_t coap_get_log_level(void)
Returns the current log level.
Definition: debug.c:60
multi-purpose address abstraction
Definition: address.h:57
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.
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