libcoap  4.2.0
Logging Support

API functions for logging support. More...

Macros

#define COAP_DEBUG_FD   stdout
 Used for output for LOG_DEBUG to LOG_ERR. More...
 
#define COAP_ERR_FD   stderr
 Used for output for LOG_CRIT to LOG_EMERG. More...
 
#define coap_log(level, ...)
 Logging function. More...
 

Typedefs

typedef void(* coap_log_handler_t) (coap_log_t level, const char *message)
 Logging call-back handler definition. More...
 

Enumerations

enum  coap_log_t {
  LOG_EMERG =0, LOG_ALERT, LOG_CRIT, LOG_ERR,
  LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG
}
 Pre-defined log levels akin to what is used in syslog. More...
 

Functions

coap_log_t coap_get_log_level (void)
 Get the current logging level. More...
 
void coap_set_log_level (coap_log_t level)
 Sets the log level to the specified value. More...
 
void coap_set_log_handler (coap_log_handler_t handler)
 Add a custom log callback handler. More...
 
const char * coap_package_name (void)
 Get the library package name. More...
 
const char * coap_package_version (void)
 Get the library package version. More...
 
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). More...
 
void coap_set_show_pdu_output (int use_fprintf)
 Defines the output mode for the coap_show_pdu() function. More...
 
void coap_show_pdu (coap_log_t level, const coap_pdu_t *pdu)
 Display the contents of the specified pdu. More...
 
void coap_show_tls_version (coap_log_t level)
 Display the current (D)TLS library linked with and built for version. More...
 
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. More...
 
size_t coap_print_addr (const struct coap_address_t *address, unsigned char *buffer, size_t size)
 Print the address into the defined buffer. More...
 
void coap_dtls_set_log_level (int level)
 Sets the (D)TLS logging level to the specified level. More...
 
int coap_dtls_get_log_level (void)
 Get the current (D)TLS logging. More...
 
const char * coap_session_str (const coap_session_t *session)
 Get session description. More...
 
const char * coap_endpoint_str (const coap_endpoint_t *endpoint)
 Get endpoint description. More...
 

Detailed Description

API functions for logging support.

Macro Definition Documentation

◆ COAP_DEBUG_FD

#define COAP_DEBUG_FD   stdout

Used for output for LOG_DEBUG to LOG_ERR.

Definition at line 23 of file coap_debug.h.

◆ COAP_ERR_FD

#define COAP_ERR_FD   stderr

Used for output for LOG_CRIT to LOG_EMERG.

Definition at line 30 of file coap_debug.h.

◆ coap_log

#define coap_log (   level,
  ... 
)
Value:
do { \
if ((int)((level))<=(int)coap_get_log_level()) \
coap_log_impl((level), __VA_ARGS__); \
} while(0)
coap_log_t coap_get_log_level(void)
Get the current logging level.
Definition: coap_debug.c:71

Logging function.

Writes the given text to COAP_ERR_FD (for level <= LOG_CRIT) or COAP_DEBUG_FD (for level >= LOG_ERR). The text is output only when level is below or equal to the log level that set by coap_set_log_level().

Parameters
levelOne of the LOG_* values.

Definition at line 122 of file coap_debug.h.

Typedef Documentation

◆ coap_log_handler_t

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

Logging call-back handler definition.

Parameters
levelOne of the LOG_* values.
messageZero-terminated string message to log.

Definition at line 73 of file coap_debug.h.

Enumeration Type Documentation

◆ coap_log_t

enum coap_log_t

Pre-defined log levels akin to what is used in syslog.

Enumerator
LOG_EMERG 

Emergency.

LOG_ALERT 

Alert.

LOG_CRIT 

Critical.

LOG_ERR 

Error.

LOG_WARNING 

Warning.

LOG_NOTICE 

Notice.

LOG_INFO 

Information.

LOG_DEBUG 

Debug.

Definition at line 41 of file coap_debug.h.

Function Documentation

◆ coap_dtls_get_log_level()

int coap_dtls_get_log_level ( void  )

Get the current (D)TLS logging.

Returns
The current log level (one of LOG_*).

Get the current (D)TLS logging.

Definition at line 135 of file coap_dtls_gnutls.c.

◆ coap_dtls_set_log_level()

void coap_dtls_set_log_level ( int  level)

Sets the (D)TLS logging level to the specified level.

Note: coap_log_level() will influence output if at a specified level.

Parameters
levelThe logging level to use - LOG_*

Sets the (D)TLS logging level to the specified level.

Definition at line 128 of file coap_dtls_gnutls.c.

◆ coap_endpoint_str()

const char* coap_endpoint_str ( const coap_endpoint_t endpoint)

Get endpoint description.

Parameters
endpointThe CoAP endpoint.
Returns
description string.

Definition at line 980 of file coap_session.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_get_log_level()

coap_log_t coap_get_log_level ( void  )

Get the current logging level.

Returns
One of the LOG_* values.

Definition at line 71 of file coap_debug.c.

+ Here is the caller graph for this function:

◆ coap_log_impl()

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).

The text is output only when level is below or equal to the log level that set by coap_set_log_level().

Internal function.

Parameters
levelOne of the LOG_* values. &
formatThe format string to use.

Definition at line 747 of file coap_debug.c.

+ Here is the call graph for this function:

◆ coap_package_name()

const char* coap_package_name ( void  )

Get the library package name.

Returns
Zero-terminated string with the name of this library.

Definition at line 57 of file coap_debug.c.

◆ coap_package_version()

const char* coap_package_version ( void  )

Get the library package version.

Returns
Zero-terminated string with the library version.

Definition at line 61 of file coap_debug.c.

◆ coap_print_addr()

size_t coap_print_addr ( const struct coap_address_t address,
unsigned char *  buffer,
size_t  size 
)

Print the address into the defined buffer.

Internal Function.

Parameters
addressThe address to print.
bufferThe buffer to print into.
sizeThe size of the buffer to print into.
Returns
The amount written into the buffer.

Definition at line 171 of file coap_debug.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_session_str()

const char* coap_session_str ( const coap_session_t session)

Get session description.

Parameters
sessionThe CoAP session.
Returns
description string.

Definition at line 943 of file coap_session.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_set_log_handler()

void coap_set_log_handler ( coap_log_handler_t  handler)

Add a custom log callback handler.

Parameters
handlerThe logging handler to use or NULL to use default handler.

Definition at line 742 of file coap_debug.c.

◆ coap_set_log_level()

void coap_set_log_level ( coap_log_t  level)

Sets the log level to the specified value.

Parameters
levelOne of the LOG_* values.

Definition at line 76 of file coap_debug.c.

◆ coap_set_show_pdu_output()

void coap_set_show_pdu_output ( int  use_fprintf)

Defines the output mode for the coap_show_pdu() function.

Parameters
use_fprintf1 if the output is to use fprintf() (the default) 0 if the output is to use coap_log().

Definition at line 66 of file coap_debug.c.

◆ coap_show_pdu()

void coap_show_pdu ( coap_log_t  level,
const coap_pdu_t pdu 
)

Display the contents of the specified pdu.

Note: The output method of coap_show_pdu() is dependent on the setting of coap_set_show_pdu_output().

Parameters
levelThe required minimum logging level.
pduThe PDU to decode.

Definition at line 461 of file coap_debug.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

Parameters
levelThe required minimum logging level.

Definition at line 651 of file coap_debug.c.

+ Here is the call graph for this function:

◆ 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.

Parameters
bufferThe buffer to put the string into.
bufsizeThe size of the buffer to put the string into.
Returns
A pointer to the provided buffer.

Definition at line 658 of file coap_debug.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: