-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebug.h
74 lines (56 loc) · 1.7 KB
/
debug.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* debug.h -- debug utilities
*
* Copyright (C) 2010,2011 Olaf Bergmann <[email protected]>
*
* This file is part of the CoAP library libcoap. Please see
* README for terms of use.
*/
#ifndef _COAP_DEBUG_H_
#define _COAP_DEBUG_H_
#include "config.h"
#ifndef COAP_DEBUG_FD
#define COAP_DEBUG_FD stdout
#endif
#ifndef COAP_ERR_FD
#define COAP_ERR_FD stderr
#endif
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
typedef short coap_log_t;
#else
/** Pre-defined log levels akin to what is used in \b syslog. */
typedef enum { LOG_EMERG=0, LOG_ALERT, LOG_CRIT, LOG_WARNING,
LOG_NOTICE, LOG_INFO, LOG_DEBUG
} coap_log_t;
#endif
/** Returns the current log level. */
coap_log_t coap_get_log_level();
/** Sets the log level to the specified value. */
void coap_set_log_level(coap_log_t level);
/**
* Writes the given text to @c COAP_ERR_FD (for @p level <= @c
* LOG_CRIT) or @c COAP_DEBUG_FD (for @p level >= @c LOG_WARNING). The
* text is output only when @p level is below or equal to the log
* level that set by coap_set_log_level().
*/
void coap_log_impl(coap_log_t level, const char *format, ...);
#ifndef coap_log
#define coap_log(...) coap_log_impl(__VA_ARGS__)
#endif
#ifndef NDEBUG
/* A set of convenience macros for common log levels. */
#define info(...) coap_log(LOG_INFO, __VA_ARGS__)
#define warn(...) coap_log(LOG_WARNING, __VA_ARGS__)
#define debug(...) coap_log(LOG_DEBUG, __VA_ARGS__)
#include "pdu.h"
void coap_show_pdu(const coap_pdu_t *);
struct coap_address_t;
size_t coap_print_addr(const struct coap_address_t *, unsigned char *, size_t);
#else
#define debug(...)
#define info(...)
#define warn(...)
#define coap_show_pdu(x)
#define coap_print_addr(...)
#endif
#endif /* _COAP_DEBUG_H_ */