mirror of
https://github.com/obgm/libcoap.git
synced 2026-12-05 20:02:19 +03:00
New coap_logging(3) and updated Doxygen comments for logging
Documentation changes/updates only - no code changes. configure.ac include/coap/coap_dtls.h include/coap/coap_session.h include/coap/debug.h man/Makefile.am man/coap.txt.in man/coap_context.txt.in man/coap_logging.txt.in (new)
This commit is contained in:
1 parent
6bb40d5af3
commit
c695dea7cd
8 files changed
+316
-46
No files matched your search
+17
-15
@@ -56,21 +56,6 @@ typedef struct coap_tls_version_t {
|
||||
*/
|
||||
coap_tls_version_t *coap_get_tls_library_version(void);
|
||||
|
||||
/**
|
||||
* Sets the (D)TLS logging level to the specified @p level.
|
||||
* Note: coap_log_level() will influence output if at a specified level.
|
||||
*
|
||||
* @param level The logging level to use - LOG_*
|
||||
*/
|
||||
void coap_dtls_set_log_level(int level);
|
||||
|
||||
/**
|
||||
* Get the current (D)TLS logging.
|
||||
*
|
||||
* @return The current log level (one of LOG_*).
|
||||
*/
|
||||
int coap_dtls_get_log_level(void);
|
||||
|
||||
struct coap_dtls_pki_t;
|
||||
|
||||
/**
|
||||
@@ -605,5 +590,22 @@ void coap_dtls_startup(void);
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @ingroup logging
|
||||
* Sets the (D)TLS logging level to the specified @p level.
|
||||
* Note: coap_log_level() will influence output if at a specified level.
|
||||
*
|
||||
* @param level The logging level to use - LOG_*
|
||||
*/
|
||||
void coap_dtls_set_log_level(int level);
|
||||
|
||||
/**
|
||||
* @ingroup logging
|
||||
* Get the current (D)TLS logging.
|
||||
*
|
||||
* @return The current log level (one of LOG_*).
|
||||
*/
|
||||
int coap_dtls_get_log_level(void);
|
||||
|
||||
|
||||
#endif /* COAP_DTLS_H */
|
||||
@@ -284,10 +284,11 @@ ssize_t coap_session_send_pdu(coap_session_t *session, coap_pdu_t *pdu);
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup logging
|
||||
* Get session description.
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
* @return description string
|
||||
* @return description string.
|
||||
*/
|
||||
const char *coap_session_str(const coap_session_t *session);
|
||||
|
||||
@@ -332,10 +333,11 @@ void coap_free_endpoint(coap_endpoint_t *ep);
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup logging
|
||||
* Get endpoint description.
|
||||
*
|
||||
* @param endpoint The CoAP endpoint.
|
||||
* @return description string
|
||||
* @return description string.
|
||||
*/
|
||||
const char *coap_endpoint_str(const coap_endpoint_t *endpoint);
|
||||
|
||||
|
||||
+124
-19
@@ -10,52 +10,98 @@
|
||||
#ifndef _COAP_DEBUG_H_
|
||||
#define _COAP_DEBUG_H_
|
||||
|
||||
/**
|
||||
* @defgroup logging Logging Support
|
||||
* API functions for logging support
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef COAP_DEBUG_FD
|
||||
/**
|
||||
* Used for output for @c LOG_DEBUG to @c LOG_ERR.
|
||||
*/
|
||||
#define COAP_DEBUG_FD stdout
|
||||
#endif
|
||||
|
||||
#ifndef COAP_ERR_FD
|
||||
/**
|
||||
* Used for output for @c LOG_CRIT to @c LOG_EMERG.
|
||||
*/
|
||||
#define COAP_ERR_FD stderr
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
#include <syslog.h>
|
||||
/**
|
||||
* Logging type. One of LOG_* from @b syslog.
|
||||
*/
|
||||
typedef short coap_log_t;
|
||||
#else
|
||||
/** Pre-defined log levels akin to what is used in \b syslog. */
|
||||
typedef enum {
|
||||
LOG_EMERG=0,
|
||||
LOG_ALERT,
|
||||
LOG_CRIT,
|
||||
LOG_ERR,
|
||||
LOG_WARNING,
|
||||
LOG_NOTICE,
|
||||
LOG_INFO,
|
||||
LOG_DEBUG
|
||||
LOG_EMERG=0, /**< Emergency */
|
||||
LOG_ALERT, /**< Alert */
|
||||
LOG_CRIT, /**< Critical */
|
||||
LOG_ERR, /**< Error */
|
||||
LOG_WARNING, /**< Warning */
|
||||
LOG_NOTICE, /**< Notice */
|
||||
LOG_INFO, /**< Information */
|
||||
LOG_DEBUG /**< Debug */
|
||||
} coap_log_t;
|
||||
#endif
|
||||
|
||||
/** Returns the current log level. */
|
||||
/**
|
||||
* Get the current logging level.
|
||||
*
|
||||
* @return One of the LOG_* values.
|
||||
*/
|
||||
coap_log_t coap_get_log_level(void);
|
||||
|
||||
/** Sets the log level to the specified value. */
|
||||
/**
|
||||
* Sets the log level to the specified value.
|
||||
*
|
||||
* @param level One of the LOG_* values.
|
||||
*/
|
||||
void coap_set_log_level(coap_log_t level);
|
||||
|
||||
/**
|
||||
* Logging call-back handler definition.
|
||||
*
|
||||
* @param level One of the LOG_* values.
|
||||
* @param message Zero-terminated string message to log.
|
||||
*/
|
||||
typedef void (*coap_log_handler_t) (coap_log_t level, const char *message);
|
||||
|
||||
/** Add a custom log callback, use NULL to reset default handler */
|
||||
/**
|
||||
* Add a custom log callback handler.
|
||||
*
|
||||
* @param handler The logging handler to use or @p NULL to use default handler.
|
||||
*/
|
||||
void coap_set_log_handler(coap_log_handler_t handler);
|
||||
|
||||
/** Returns a zero-terminated string with the name of this library. */
|
||||
/**
|
||||
* Get the library package name.
|
||||
*
|
||||
* @return Zero-terminated string with the name of this library.
|
||||
*/
|
||||
const char *coap_package_name(void);
|
||||
|
||||
/** Returns a zero-terminated string with the library version. */
|
||||
/**
|
||||
* Get the library package version.
|
||||
*
|
||||
* @return Zero-terminated string with the library version.
|
||||
*/
|
||||
const char *coap_package_version(void);
|
||||
|
||||
/**
|
||||
* Writes the given text to @c COAP_ERR_FD (for @p level <= @c LOG_CRIT) or @c
|
||||
* COAP_DEBUG_FD (for @p level >= @c LOG_WARNING). The text is output only when
|
||||
* COAP_DEBUG_FD (for @p level >= @c LOG_ERR). The text is output only when
|
||||
* @p level is below or equal to the log level that set by coap_set_log_level().
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param level One of the LOG_* values.
|
||||
& @param format The format string to use.
|
||||
*/
|
||||
#if (defined(__GNUC__))
|
||||
void coap_log_impl(coap_log_t level,
|
||||
@@ -65,12 +111,32 @@ void coap_log_impl(coap_log_t level, const char *format, ...);
|
||||
#endif
|
||||
|
||||
#ifndef coap_log
|
||||
/**
|
||||
* Logging function.
|
||||
* Writes the given text to @c COAP_ERR_FD (for @p level <= @c LOG_CRIT) or @c
|
||||
* COAP_DEBUG_FD (for @p level >= @c LOG_ERR). The text is output only when
|
||||
* @p level is below or equal to the log level that set by coap_set_log_level().
|
||||
*
|
||||
* @param level One of the LOG_* values.
|
||||
*/
|
||||
#define coap_log(level, ...) do { if ((level)<=(int)coap_get_log_level()) coap_log_impl((level), __VA_ARGS__); } while(0)
|
||||
#endif
|
||||
|
||||
/* A set of convenience macros for common log levels. */
|
||||
/**
|
||||
* Obsoleted.
|
||||
* @deprecated Use coap_log(LOG_INFO, ...).
|
||||
*/
|
||||
#define info(...) coap_log(LOG_INFO, __VA_ARGS__)
|
||||
/**
|
||||
* Obsoleted.
|
||||
* @deprecated Use coap_log(LOG_WARNING, ...).
|
||||
*/
|
||||
#define warn(...) coap_log(LOG_WARNING, __VA_ARGS__)
|
||||
/**
|
||||
* Obsoleted.
|
||||
* @deprecated Use coap_log(LOG_DEBUG, ...).
|
||||
*/
|
||||
#define debug(...) coap_log(LOG_DEBUG, __VA_ARGS__)
|
||||
|
||||
#include "pdu.h"
|
||||
@@ -78,23 +144,62 @@ void coap_log_impl(coap_log_t level, const char *format, ...);
|
||||
/**
|
||||
* Defines the output mode for the coap_show_pdu() function.
|
||||
*
|
||||
* @param use_fprintf 1 if the output is to use fprintf() (the default)
|
||||
* 0 if the output is to use coap_log()
|
||||
* @param use_fprintf @p 1 if the output is to use fprintf() (the default)
|
||||
* @p 0 if the output is to use coap_log().
|
||||
*/
|
||||
void coap_set_show_pdu_output(int use_fprintf);
|
||||
|
||||
/**
|
||||
* Display the contents of the specified @p pdu.
|
||||
* Note: The output method of coap_show_pdu() is dependent on the setting of
|
||||
* coap_set_show_pdu_output().
|
||||
*
|
||||
* @param level The required minimum logging level
|
||||
* @param pdu The PDU to decode
|
||||
* @param level The required minimum logging level.
|
||||
* @param pdu The PDU to decode.
|
||||
*/
|
||||
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu);
|
||||
|
||||
struct coap_address_t;
|
||||
size_t coap_print_addr(const struct coap_address_t *, unsigned char *, size_t);
|
||||
|
||||
/**
|
||||
* Print the address into the defined buffer.
|
||||
*
|
||||
* Internal Function.
|
||||
*
|
||||
* @param address The address to print.
|
||||
* @param buffer The buffer to print into.
|
||||
* @param size The size of the buffer to print into.
|
||||
*
|
||||
* @return The amount written into the buffer.
|
||||
*/
|
||||
size_t coap_print_addr(const struct coap_address_t *address,
|
||||
unsigned char *buffer, size_t size);
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* Set the packet loss level for testing. This can be in one of two forms.
|
||||
*
|
||||
* Percentage : 0% to 100%. Use the specified probability.
|
||||
* 0% is send all packets, 100% is drop all packets.
|
||||
*
|
||||
* List: A comma seperated list of numbers or number ranges that are the
|
||||
* packets to drop.
|
||||
*
|
||||
* @param loss_level The defined loss level (percentage or list).
|
||||
*
|
||||
* @return @c 1 If loss level set, @c 0 if there is an error.
|
||||
*/
|
||||
int coap_debug_set_packet_loss(const char *loss_level);
|
||||
|
||||
/**
|
||||
* Check to see whether a packet should be sent or not.
|
||||
*
|
||||
* Internal function
|
||||
*
|
||||
* @return @c 1 if packet is to be sent, @c 0 if packet is to be dropped.
|
||||
*/
|
||||
int coap_debug_send_packet(void);
|
||||
|
||||
|
||||
#endif /* _COAP_DEBUG_H_ */
|
||||
Reference in new issue
Block a user