libcoap  4.2.0rc1
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 
19 #ifndef COAP_DEBUG_FD
20 
23 #define COAP_DEBUG_FD stdout
24 #endif
25 
26 #ifndef COAP_ERR_FD
27 
30 #define COAP_ERR_FD stderr
31 #endif
32 
33 #ifdef HAVE_SYSLOG_H
34 #include <syslog.h>
38 typedef short coap_log_t;
39 #else
40 
41 typedef enum {
50 } coap_log_t;
51 #endif
52 
59 
65 void coap_set_log_level(coap_log_t level);
66 
73 typedef void (*coap_log_handler_t) (coap_log_t level, const char *message);
74 
81 
87 const char *coap_package_name(void);
88 
94 const char *coap_package_version(void);
95 
106 #if (defined(__GNUC__))
107 void coap_log_impl(coap_log_t level,
108  const char *format, ...) __attribute__ ((format(printf, 2, 3)));
109 #else
110 void coap_log_impl(coap_log_t level, const char *format, ...);
111 #endif
112 
113 #ifndef coap_log
114 
122 #define coap_log(level, ...) do { \
123  if ((int)((level))<=(int)coap_get_log_level()) \
124  coap_log_impl((level), __VA_ARGS__); \
125 } while(0)
126 #endif
127 
128 /* A set of convenience macros for common log levels. */
133 #define info(...) coap_log(LOG_INFO, __VA_ARGS__)
134 
138 #define warn(...) coap_log(LOG_WARNING, __VA_ARGS__)
139 
143 #define debug(...) coap_log(LOG_DEBUG, __VA_ARGS__)
144 
145 #include "pdu.h"
146 
153 void coap_set_show_pdu_output(int use_fprintf);
154 
163 void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu);
164 
165 struct coap_address_t;
166 
178 size_t coap_print_addr(const struct coap_address_t *address,
179  unsigned char *buffer, size_t size);
180 
196 int coap_debug_set_packet_loss(const char *loss_level);
197 
205 int coap_debug_send_packet(void);
206 
207 
208 #endif /* _COAP_DEBUG_H_ */
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu)
Display the contents of the specified pdu.
Definition: debug.c:461
multi-purpose address abstraction
Definition: address.h:62
const char * coap_package_name(void)
Get the library package name.
Definition: debug.c:57
size_t coap_print_addr(const struct coap_address_t *address, unsigned char *buffer, size_t size)
Print the address into the defined buffer.
Definition: debug.c:171
Debug.
Definition: debug.h:49
int coap_debug_set_packet_loss(const char *loss_level)
Set the packet loss level for testing.
Definition: debug.c:704
void coap_set_log_level(coap_log_t level)
Sets the log level to the specified value.
Definition: debug.c:76
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_ERR)...
Definition: debug.c:658
void(* coap_log_handler_t)(coap_log_t level, const char *message)
Logging call-back handler definition.
Definition: debug.h:73
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
Definition: pdu.h:287
Warning.
Definition: debug.h:46
Notice.
Definition: debug.h:47
Error.
Definition: debug.h:45
void coap_set_show_pdu_output(int use_fprintf)
Defines the output mode for the coap_show_pdu() function.
Definition: debug.c:66
Pre-defined constants that reflect defaults for CoAP.
coap_log_t
Pre-defined log levels akin to what is used in syslog.
Definition: debug.h:41
const char * coap_package_version(void)
Get the library package version.
Definition: debug.c:61
coap_log_t coap_get_log_level(void)
Get the current logging level.
Definition: debug.c:71
socklen_t size
size of addr
Definition: address.h:63
void coap_set_log_handler(coap_log_handler_t handler)
Add a custom log callback handler.
Definition: debug.c:653
int coap_debug_send_packet(void)
Check to see whether a packet should be sent or not.
Definition: debug.c:744
Emergency.
Definition: debug.h:42
Critical.
Definition: debug.h:44
Information.
Definition: debug.h:48
Alert.
Definition: debug.h:43