libcoap  4.2.0rc3
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 #include "pdu.h"
129 
136 void coap_set_show_pdu_output(int use_fprintf);
137 
146 void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu);
147 
154 
164 char *coap_string_tls_version(char *buffer, size_t bufsize);
165 
166 struct coap_address_t;
167 
179 size_t coap_print_addr(const struct coap_address_t *address,
180  unsigned char *buffer, size_t size);
181 
197 int coap_debug_set_packet_loss(const char *loss_level);
198 
206 int coap_debug_send_packet(void);
207 
208 
209 #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
char * coap_string_tls_version(char *buffer, size_t bufsize)
Build a string containing the current (D)TLS library linked with and built for version.
Definition: debug.c:658
int coap_debug_set_packet_loss(const char *loss_level)
Set the packet loss level for testing.
Definition: debug.c:792
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:746
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
void coap_show_tls_version(coap_log_t level)
Display the current (D)TLS library linked with and built for version.
Definition: debug.c:651
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:741
int coap_debug_send_packet(void)
Check to see whether a packet should be sent or not.
Definition: debug.c:832
Emergency.
Definition: debug.h:42
Critical.
Definition: debug.h:44
Information.
Definition: debug.h:48
Alert.
Definition: debug.h:43