COAP_LOGGING(3)

πŸ’… coap_logging β€” the libcoap logging glow-up (libcoap Manual, bestie) πŸŽ€

okay so this whole page is about logging in libcoap, and honestly it's a lot, but we're gonna get through it together ✨

🌸 NAME 🌸

coap_logging, coap_log, coap_log_emerg, coap_log_alert, coap_log_crit, coap_log_err, coap_log_warn, coap_log_info, coap_log_notice, coap_log_debug, coap_log_oscore, coap_get_log_level, coap_set_log_level, coap_dtls_log, coap_dtls_get_log_level, coap_dtls_set_log_level, coap_set_log_handler, coap_log_level_desc, coap_package_name, coap_package_version, coap_package_build, coap_set_show_pdu_output, coap_show_pdu, coap_endpoint_str, coap_session_str, coap_print_addr, coap_print_ip_addr β€” all of them, together, working with CoAP logging 🫢


✨ SYNOPSIS ✨

#include <coap3/coap.h>

void coap_log(coap_log_t level, const char *format, ...);

void coap_log_emerg(const char *format, ...);

void coap_log_alert(const char *format, ...);

void coap_log_crit(const char *format, ...);

void coap_log_err(const char *format, ...);

void coap_log_warn(const char *format, ...);

void coap_log_info(const char *format, ...);

void coap_log_notice(const char *format, ...);

void coap_log_debug(const char *format, ...);

void coap_log_oscore(const char *format, ...);

void coap_set_log_level(coap_log_t level);

coap_log_t coap_get_log_level(void);

void coap_dtls_log(coap_log_t level, const char *format, ...);

void coap_dtls_set_log_level(coap_log_t level);

coap_log_t coap_dtls_get_log_level(void);

void coap_set_log_handler(coap_log_handler_t handler);

const char *coap_log_level_desc(coap_log_t level);

const char *coap_package_name(void);

const char *coap_package_version(void);

const char *coap_package_build(void);

void coap_set_show_pdu_output(int use_fprintf);

void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu);

const char *coap_endpoint_str(const coap_endpoint_t *endpoint);

const char *coap_session_str(const coap_session_t *session);

size_t coap_print_addr(const coap_address_t *address, unsigned char
*buffer, size_t length);

const char *coap_print_ip_addr(const coap_address_t *address, char
*buffer, size_t length);

and bestie, for specific (D)TLS library support you link with -lcoap-3-notls, -lcoap-3-gnutls, -lcoap-3-openssl, -lcoap-3-mbedtls, -lcoap-3-wolfssl or -lcoap-3-tinydtls. Otherwise you link with -lcoap-3 and get the default (D)TLS library support. iykyk πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

The logging sub-system is literally built so you can log at different levels, and depending on which logging level you picked, it outputs the appropriate info. vibe check passed βœ…

By default logging goes to stderr or stdout, depending on the logging level of the log entry. But you can also send all your logging info to an application logging callback handler so your app can process it itself. main character energy for your app πŸŽ€

The logging levels (coap_log_t) are defined like this β€” and yes they're based on the syslog() names and values, no cap:

  • COAP_LOG_EMERG β€” Emergency level (0). 🚨
  • COAP_LOG_ALERT β€” Alert level (1).
  • COAP_LOG_CRIT β€” Critical level (2).
  • COAP_LOG_ERR β€” Error level (3).
  • COAP_LOG_WARN β€” Warning level (the default) (4).
  • COAP_LOG_NOTICE β€” Notice level (5).
  • COAP_LOG_INFO β€” Information level (6).
  • COAP_LOG_DEBUG β€” Debug level (7).

and then there's one extra level:

  • COAP_LOG_OSCORE β€” Debug OSCORE information (8). 🧚
⚠️ NOTE: the maximum logging level in the libcoap library may have been updated by the use of ./configure --enable-max-logging-level=X (where X is 0 to 8 inclusive), which may disable some of the higher logging levels to save code space. so like… don't be shook if a level is missing, it was on purpose πŸ’€

πŸ”₯ FUNCTIONS πŸ”₯

Function: coap_log()

coap_log() logs your info at the appropriate level. The rest of the parameters follow the standard printf() function format. Where possible though, the coap_log_*() functions should be used instead β€” they're the moment, fr fr.

Function: coap_log_emerg()

coap_log_emerg() is a wrapper to coap_log() with level set to COAP_LOG_EMERG. The parameters follow the standard printf() function format.

Function: coap_log_alert()

coap_log_alert() is a wrapper to coap_log() with level set to COAP_LOG_ALERT. The parameters follow the standard printf() function format.

Function: coap_log_crit()

coap_log_crit() is a wrapper to coap_log() with level set to COAP_LOG_CRIT. The parameters follow the standard printf() function format.

Function: coap_log_err()

coap_log_err() is a wrapper to coap_log() with level set to COAP_LOG_ERR. The parameters follow the standard printf() function format.

Function: coap_log_warn()

coap_log_warn() is a wrapper to coap_log() with level set to COAP_LOG_WARN. The parameters follow the standard printf() function format.

Function: coap_log_notice()

coap_log_notice() is a wrapper to coap_log() with level set to COAP_LOG_NOTICE. The parameters follow the standard printf() function format.

Function: coap_log_info()

coap_log_info() is a wrapper to coap_log() with level set to COAP_LOG_INFO. The parameters follow the standard printf() function format.

Function: coap_log_debug()

coap_log_debug() is a wrapper to coap_log() with level set to COAP_LOG_DEBUG. The parameters follow the standard printf() function format.

Function: coap_log_oscore()

coap_log_oscore() is a wrapper to coap_log() with level set to COAP_LOG_OSCORE. The parameters follow the standard printf() function format.

Function: coap_set_log_level()

coap_set_log_level() sets the current logging level for output by any subsequent coap_log() calls. And here's the tea β˜•: output is only logged if the coap_log() level definition is smaller than or equal to the current logging level.

Function: coap_get_log_level()

coap_get_log_level() gets the current logging level. that's it, that's the function πŸ’–

Function: coap_dtls_log()

coap_dtls_log() logs (D)TLS library information at the appropriate level. The rest of the parameters follow the standard printf() function format.

Function: coap_dtls_set_log_level()

coap_dtls_set_log_level() sets the current logging level for output by any subsequent coap_dtls_log() calls. Output is only logged if the coap_dtls_log() level definition is smaller than or equal to the current DTLS logging level.

Function: coap_dtls_get_log_level()

coap_dtls_get_log_level() gets the current logging level for the DTLS library.

Function: coap_set_log_handler()

The coap_set_log_handler()* function lets you define an alternative logging handler for processing any logging messages. The logging handler prototype is defined as:

typedef void (*coap_log_handler_t) (coap_log_t level, const char *message);

Function: coap_log_level_desc()

The coap_log_level_desc()* function returns a 4 character ascii description for the logging level. four whole characters, she's concise πŸ‘‘

Function: coap_package_name()

coap_package_name() returns the name of this library.

Function: coap_package_version()

coap_package_version() returns the version of this library.

Function: coap_package_build()

coap_package_build() returns the git information (as in "git describe --tags") for the build of this library, or the version of this library if git is not used.

Function: coap_set_show_pdu_output()

coap_set_show_pdu_output() decides whether the output from coap_show_pdu() goes to stdout/stderr, or gets output using coap_log(). Set use_fprintf to 1 for stdout/stderr (the default), and set use_fprintf to 0 for coap_log(). choose your fighter πŸ₯Š

Function: coap_show_pdu()

coap_show_pdu() decodes the pdu, outputting as appropriate for logging level. Where the output actually goes depends on coap_set_show_pdu_output().

⚠️ NOTE: if pdu has not been associated with a CoAP session (i.e. not a received PDU, or coap_send() not yet called), then the output assumes that this pdu is of type unreliable. just so you know 🫢

Function: coap_endpoint_str()

coap_endpoint_str() returns a description string of the endpoint.

Function: coap_session_str()

coap_session_str() gets you a string containing the information about the session.

Function: coap_print_addr()

coap_print_addr() returns the length of the description string containing the IP address and port from address, and updates buffer, which has a maximum length length.

Function: coap_print_ip_addr()

coap_print_ip_addr() returns a description string of the IP address only for address. buffer gets updated, and it has a maximum length of length.


🌈 RETURN VALUES 🌈

  • coap_package_name(), coap_package_version() and coap_package_build() return the appropriate zero-terminated character string.
  • coap_get_log_level() returns the current logging level.
  • coap_dtls_get_log_level() returns the current logging level for the DTLS library specifics.
  • coap_log_level_desc() returns a description string of the logging level.
  • coap_endpoint_str() returns a description string of the endpoint.
  • coap_session_str() returns a description string of the session.
  • coap_print_addr() returns the length of buffer that has been updated with an ascii readable IP address and port for address.
  • coap_print_ip_addr() returns a pointer to the ascii readable IP address only for address.

πŸ’œ SEE ALSO πŸ’œ

coap_context(3) and coap_session(3) β€” go read those next bestie, they're iconic too 🌸


⭐ FURTHER INFORMATION ⭐

See

"RFC7252: The Constrained Application Protocol (CoAP)"

for further information. yes, the actual RFC, go get that knowledge πŸ“š


πŸ™ˆ BUGS πŸ™ˆ

Please raise an issue on GitHub at https://github.com/obgm/libcoap/issues to report any bugs.

Please raise a Pull Request at https://github.com/obgm/libcoap/pulls for any fixes. we love a contributor πŸ’…


πŸ‘‘ AUTHORS πŸ‘‘

The libcoap project <libcoap-developers@lists.sourceforge.net>


okay that's the whole page, you ate that πŸ“ this was coap_logging, version 4.3.5, dated 08/24/2026 β€” mwah, go log something pretty πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from