Loading...
Searching...
No Matches
coap_debug.h
Go to the documentation of this file.
/*
* coap_debug.h -- debug utilities
*
* Copyright (C) 2010-2011,2014-2023 Olaf Bergmann <bergmann@tzi.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
#ifndef COAP_DEBUG_H_
#define COAP_DEBUG_H_
#ifndef COAP_DEBUG_FD
#define COAP_DEBUG_FD stdout
#endif
#ifndef COAP_ERR_FD
#define COAP_ERR_FD stderr
#endif
#ifndef COAP_MAX_LOGGING_LEVEL
#define COAP_MAX_LOGGING_LEVEL 8
#endif /* ! COAP_MAX_LOGGING_LEVEL */
typedef enum {
COAP_LOG_EMERG = 0, /* 0 */
COAP_LOG_ALERT, /* 1 */
COAP_LOG_CRIT, /* 2 */
COAP_LOG_ERR, /* 3 */
COAP_LOG_WARN, /* 4 */
COAP_LOG_NOTICE, /* 5 */
COAP_LOG_INFO, /* 6 */
COAP_LOG_DEBUG, /* 7 */
COAP_LOG_OSCORE, /* 8 */
COAP_LOG_DTLS_BASE,
#define COAP_LOG_CIPHERS COAP_LOG_DTLS_BASE /* For backward compatability */
} coap_log_t;
/*
* These have the same values, but can be used in #if tests for better
* readability
*/
#define _COAP_LOG_EMERG 0
#define _COAP_LOG_ALERT 1
#define _COAP_LOG_CRIT 2
#define _COAP_LOG_ERR 3
#define _COAP_LOG_WARN 4
#define _COAP_LOG_NOTICE 5
#define _COAP_LOG_INFO 6
#define _COAP_LOG_DEBUG 7
#define _COAP_LOG_OSCORE 8
COAP_STATIC_INLINE void
coap_no_log(void) { }
#define coap_log_emerg(...) coap_log(COAP_LOG_EMERG, __VA_ARGS__)
#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_ALERT)
#define coap_log_alert(...) coap_log(COAP_LOG_ALERT, __VA_ARGS__)
#else
#define coap_log_alert(...) coap_no_log()
#endif
#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_CRIT)
#define coap_log_crit(...) coap_log(COAP_LOG_CRIT, __VA_ARGS__)
#else
#define coap_log_crit(...) coap_no_log()
#endif
#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_ERR)
#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
#else
#define coap_log_err(...) coap_no_log()
#endif
#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_WARN)
#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
#else
#define coap_log_warn(...) coap_no_log()
#endif
#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_INFO)
#define coap_log_info(...) coap_log(COAP_LOG_INFO, __VA_ARGS__)
#else
#define coap_log_info(...) coap_no_log()
#endif
#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_NOTICE)
#define coap_log_notice(...) coap_log(COAP_LOG_NOTICE, __VA_ARGS__)
#else
#define coap_log_notice(...) coap_no_log()
#endif
#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_DEBUG)
#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
#else
#define coap_log_debug(...) coap_no_log()
#endif
#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_OSCORE)
#define coap_log_oscore(...) coap_log(COAP_LOG_OSCORE, __VA_ARGS__)
#else
#define coap_log_oscore(...) coap_no_log()
#endif
/*
* These entries are left here for backward compatability in applications
* (which should really "#include <syslog.h>").
* and MUST NOT be used anywhere within the libcoap code.
*
* If clashes occur during a particilar OS port, they can be safely deleted.
*
* In a future update, they will get removed.
*/
#if !defined(RIOT_VERSION) && !defined(WITH_LWIP) && !defined(WITH_CONTIKI)
#ifndef LOG_EMERG
# define LOG_EMERG COAP_LOG_EMERG
#endif
#ifndef LOG_ALERT
# define LOG_ALERT COAP_LOG_ALERT
#endif
#ifndef LOG_CRIT
# define LOG_CRIT COAP_LOG_CRIT
#endif
#ifndef LOG_ERR
# define LOG_ERR COAP_LOG_ERR
#endif
#ifndef LOG_WARNING
# define LOG_WARNING COAP_LOG_WARN
#endif
#ifndef LOG_NOTICE
# define LOG_NOTICE COAP_LOG_NOTICE
#endif
#ifndef LOG_INFO
# define LOG_INFO COAP_LOG_INFO
#endif
#ifndef LOG_DEBUG
# define LOG_DEBUG COAP_LOG_DEBUG
#endif
#endif /* ! RIOT_VERSION && ! WITH_LWIP && ! WITH_CONTIKI */
coap_log_t coap_get_log_level(void);
void coap_set_log_level(coap_log_t level);
void coap_dtls_set_log_level(coap_log_t level);
coap_log_t coap_dtls_get_log_level(void);
typedef void (*coap_log_handler_t)(coap_log_t level, const char *message);
void coap_set_log_handler(coap_log_handler_t handler);
const char *coap_package_name(void);
const char *coap_package_version(void);
const char *coap_package_build(void);
#if (defined(__GNUC__))
void coap_log_impl(coap_log_t level,
const char *format, ...) __attribute__((format(printf, 2, 3)));
#else
void coap_log_impl(coap_log_t level, const char *format, ...);
#endif
#ifndef coap_log
#ifdef WITH_CONTIKI
#include <stdio.h>
#ifndef LOG_CONF_LEVEL_COAP
#define LOG_CONF_LEVEL_COAP 0 /* = LOG_LEVEL_NONE */
#endif
void coap_print_contiki_prefix(coap_log_t level);
#define coap_log(level, ...) do { \
if (LOG_CONF_LEVEL_COAP && \
((int)((level)) <= (int)coap_get_log_level())) { \
coap_print_contiki_prefix(level); \
printf(__VA_ARGS__); \
} \
} while(0)
#else /* !WITH_CONTIKI */
#define coap_log(level, ...) do { \
if ((int)((level))<=(int)coap_get_log_level()) \
coap_log_impl((level), __VA_ARGS__); \
} while(0)
#endif /* !WITH_CONTIKI */
#endif
#ifndef coap_dtls_log
#define coap_dtls_log(level, ...) do { \
if ((int)((level))<=(int)coap_dtls_get_log_level()) \
coap_log_impl((level)+COAP_LOG_DTLS_BASE, __VA_ARGS__); \
} while(0)
#endif
#include "coap_pdu.h"
void coap_set_show_pdu_output(int use_fprintf);
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu);
void coap_show_tls_version(coap_log_t level);
char *coap_string_tls_version(char *buffer, size_t bufsize);
char *coap_string_tls_support(char *buffer, size_t bufsize);
size_t coap_print_addr(const coap_address_t *address,
unsigned char *buffer, size_t size);
const char *coap_print_ip_addr(const coap_address_t *address,
char *buffer, size_t size);
int coap_debug_set_packet_loss(const char *loss_level);
#endif /* COAP_DEBUG_H_ */
coap_debug_set_packet_loss
int coap_debug_set_packet_loss(const char *loss_level)
Set the packet loss level for testing.
Definition coap_debug.c:1244
coap_pdu.h
Pre-defined constants that reflect defaults for CoAP.
coap_set_log_handler
void coap_set_log_handler(coap_log_handler_t handler)
Add a custom log callback handler.
Definition coap_debug.c:1182
coap_get_log_level
coap_log_t coap_get_log_level(void)
Get the current logging level.
Definition coap_debug.c:91
coap_string_tls_version
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 coap_debug.c:1060
coap_show_pdu
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu)
Display the contents of the specified pdu.
Definition coap_debug.c:703
coap_string_tls_support
char * coap_string_tls_support(char *buffer, size_t bufsize)
Build a string containing the current (D)TLS library support.
Definition coap_debug.c:1152
coap_log_t
coap_log_t
Logging type.
Definition coap_debug.h:50
coap_dtls_get_log_level
coap_log_t coap_dtls_get_log_level(void)
Get the current (D)TLS logging.
Definition coap_notls.c:140
coap_package_version
const char * coap_package_version(void)
Get the library package version.
Definition coap_debug.c:72
coap_set_log_level
void coap_set_log_level(coap_log_t level)
Sets the log level to the specified value.
Definition coap_debug.c:96
coap_dtls_set_log_level
void coap_dtls_set_log_level(coap_log_t level)
Sets the (D)TLS logging level to the specified level.
Definition coap_notls.c:135
coap_log_impl
void coap_log_impl(coap_log_t level, const char *format,...)
Writes the given text to COAP_ERR_FD (for level <= COAP_LOG_CRIT) or COAP_DEBUG_FD (for level >= COAP...
Definition coap_debug.c:1187
coap_print_addr
size_t coap_print_addr(const coap_address_t *address, unsigned char *buffer, size_t size)
Print the address into the defined buffer.
Definition coap_debug.c:218
coap_package_build
const char * coap_package_build(void)
Get the library package build.
Definition coap_debug.c:77
coap_print_ip_addr
const char * coap_print_ip_addr(const coap_address_t *address, char *buffer, size_t size)
Print the IP address into the defined buffer.
Definition coap_debug.c:364
coap_show_tls_version
void coap_show_tls_version(coap_log_t level)
Display the current (D)TLS library linked with and built for version.
Definition coap_debug.c:1053
coap_set_show_pdu_output
void coap_set_show_pdu_output(int use_fprintf)
Defines the output mode for the coap_show_pdu() function.
Definition coap_debug.c:86
coap_no_log
COAP_STATIC_INLINE void coap_no_log(void)
Definition coap_debug.h:79
coap_package_name
const char * coap_package_name(void)
Get the library package name.
Definition coap_debug.c:67
coap_log_handler_t
void(* coap_log_handler_t)(coap_log_t level, const char *message)
Logging callback handler definition.
Definition coap_debug.h:202
COAP_LOG_INFO
@ COAP_LOG_INFO
Definition coap_debug.h:57
COAP_LOG_OSCORE
@ COAP_LOG_OSCORE
Definition coap_debug.h:59
COAP_LOG_EMERG
@ COAP_LOG_EMERG
Definition coap_debug.h:51
COAP_LOG_DTLS_BASE
@ COAP_LOG_DTLS_BASE
Definition coap_debug.h:60
COAP_LOG_NOTICE
@ COAP_LOG_NOTICE
Definition coap_debug.h:56
COAP_LOG_DEBUG
@ COAP_LOG_DEBUG
Definition coap_debug.h:58
COAP_LOG_ALERT
@ COAP_LOG_ALERT
Definition coap_debug.h:52
COAP_LOG_CRIT
@ COAP_LOG_CRIT
Definition coap_debug.h:53
COAP_LOG_ERR
@ COAP_LOG_ERR
Definition coap_debug.h:54
COAP_LOG_WARN
@ COAP_LOG_WARN
Definition coap_debug.h:55
COAP_STATIC_INLINE
#define COAP_STATIC_INLINE
Definition libcoap.h:53
coap_address_t
Multi-purpose address abstraction.
Definition coap_address.h:109
coap_pdu_t
structure for CoAP PDUs
Definition coap_pdu_internal.h:119