Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / resource / csdk / connectivity / lib / 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 #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 /** Pre-defined log levels akin to what is used in \b syslog. */
27 typedef enum
28 {   LOG_EMERG=0, LOG_ALERT, LOG_CRIT, LOG_WARNING,
29     LOG_NOTICE, LOG_INFO, LOG_DEBUG
30 }coap_log_t;
31 #endif
32
33 /** Returns the current log level. */
34 coap_log_t coap_get_log_level();
35
36 /** Sets the log level to the specified value. */
37 void coap_set_log_level(coap_log_t level);
38
39 /**
40  * Writes the given text to @c COAP_ERR_FD (for @p level <= @c
41  * LOG_CRIT) or @c COAP_DEBUG_FD (for @p level >= @c LOG_WARNING). The
42  * text is output only when @p level is below or equal to the log
43  * level that set by coap_set_log_level().
44  */
45 void coap_log_impl(coap_log_t level, const char *format, ...);
46
47 #ifndef coap_log
48 #define coap_log(...) coap_log_impl(__VA_ARGS__)
49 #endif
50
51 #ifndef NDEBUG
52
53 /* A set of convenience macros for common log levels. */
54 #define info(...) coap_log(LOG_INFO, __VA_ARGS__)
55 #define warn(...) coap_log(LOG_WARNING, __VA_ARGS__)
56 #define debug(...) coap_log(LOG_DEBUG, __VA_ARGS__)
57
58 #include "pdu.h"
59 void coap_show_pdu(const coap_pdu_t *);
60
61 struct coap_address_t;
62 unsigned int print_readable(const unsigned char *data, unsigned int len, unsigned char *result,
63         unsigned int buflen, int encode_always);
64 size_t coap_print_addr(const struct coap_address_t *, unsigned char *, size_t);
65
66 #else
67
68 #define debug(...)
69 #define info(...)
70 #define warn(...)
71
72 #define coap_show_pdu(x)
73 #define coap_print_addr(...)
74
75 #endif
76
77 #endif /* _COAP_DEBUG_H_ */