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 /** Pre-defined log levels akin to what is used in \b syslog. */
26 typedef enum {
27   LOG_EMERG=0,
28   LOG_ALERT,
29   LOG_CRIT,
30   LOG_WARNING,
31   LOG_NOTICE,
32   LOG_INFO,
33   LOG_DEBUG
34 } coap_log_t;
35 #endif
36 
37 /** Returns the current log level. */
38 coap_log_t coap_get_log_level(void);
39 
40 /** Sets the log level to the specified value. */
41 void coap_set_log_level(coap_log_t level);
42 
43 /** Returns a zero-terminated string with the name of this library. */
44 const char *coap_package_name(void);
45 
46 /** Returns a zero-terminated string with the library version. */
47 const char *coap_package_version(void);
48 
49 /**
50  * Writes the given text to @c COAP_ERR_FD (for @p level <= @c LOG_CRIT) or @c
51  * COAP_DEBUG_FD (for @p level >= @c LOG_WARNING). The text is output only when
52  * @p level is below or equal to the log level that set by coap_set_log_level().
53  */
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_ */
85