iotivity 0.9.0
[platform/upstream/iotivity.git] / resource / csdk / libcoap-4.1.1 / debug.h
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 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 #include "config.h"
17
18 #ifndef COAP_DEBUG_FD
19 #define COAP_DEBUG_FD stdout
20 #endif
21
22 #ifndef COAP_ERR_FD
23 #define COAP_ERR_FD stderr
24 #endif
25
26 #ifdef HAVE_SYSLOG_H
27 #include <syslog.h>
28 typedef short coap_log_t;
29 #else
30 /** Pre-defined log levels akin to what is used in \b syslog. */
31 typedef enum { LOG_EMERG=0, LOG_ALERT, LOG_CRIT, LOG_WARNING, 
32        LOG_NOTICE, LOG_INFO, LOG_DEBUG
33 } coap_log_t;
34 #endif
35
36
37
38 /** Returns the current log level. */
39 coap_log_t coap_get_log_level();
40
41 /** Sets the log level to the specified value. */
42 void coap_set_log_level(coap_log_t level);
43
44 /** 
45  * Writes the given text to @c COAP_ERR_FD (for @p level <= @c
46  * LOG_CRIT) or @c COAP_DEBUG_FD (for @p level >= @c LOG_WARNING). The
47  * text is output only when @p level is below or equal to the log
48  * level that set by coap_set_log_level().
49  */
50 void coap_log_impl(coap_log_t level, const char *format, ...);
51
52 #ifndef coap_log
53 #define coap_log(...) coap_log_impl(__VA_ARGS__)
54 #endif
55
56 #if !defined(TB_LOG) && !defined(NDEBUG)
57 #define NDEBUG
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 #define DO_PRAGMA(x) _Pragma (#x)
68 #define TODO(x) DO_PRAGMA(message ("TODO - " #x))
69
70 #include "pdu.h"
71 void coap_show_pdu(const coap_pdu_t *);
72
73 #include "address.h"
74 size_t coap_print_addr(const coap_address_t *, unsigned char *, size_t);
75
76
77 #else
78
79 #define debug(...)
80 #define info(...)
81 #define warn(...)
82
83 #define TODO(x)
84 #define coap_show_pdu(x)
85 #define coap_print_addr(...)
86
87 #endif
88
89 #ifdef __cplusplus
90 }
91 #endif
92
93 #endif /* _COAP_DEBUG_H_ */