mqtt_wss_log.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright: SPDX-License-Identifier: GPL-3.0-only
  2. #ifndef MQTT_WSS_LOG_H
  3. #define MQTT_WSS_LOG_H
  4. typedef enum mqtt_wss_log_type {
  5. MQTT_WSS_LOG_DEBUG = 0x01,
  6. MQTT_WSS_LOG_INFO = 0x02,
  7. MQTT_WSS_LOG_WARN = 0x03,
  8. MQTT_WSS_LOG_ERROR = 0x81,
  9. MQTT_WSS_LOG_FATAL = 0x88
  10. } mqtt_wss_log_type_t;
  11. typedef void (*mqtt_wss_log_callback_t)(mqtt_wss_log_type_t, const char*);
  12. typedef struct mqtt_wss_log_ctx *mqtt_wss_log_ctx_t;
  13. /** Creates logging context with optional prefix and optional callback
  14. * @param ctx_prefix String to be prefixed to every log message.
  15. * This is useful if multiple clients are instantiated to be able to
  16. * know which one this message belongs to. Can be `NULL` for no prefix.
  17. * @param log_callback Callback to be called instead of logging to
  18. * `STDOUT` or `STDERR` (if debug enabled otherwise silent). Callback has to be
  19. * pointer to function of `void function(mqtt_wss_log_type_t, const char*)` type.
  20. * If `NULL` default will be used (silent or STDERR/STDOUT).
  21. * @return mqtt_wss_log_ctx_t or `NULL` on error */
  22. mqtt_wss_log_ctx_t mqtt_wss_log_ctx_create(const char *ctx_prefix, mqtt_wss_log_callback_t log_callback);
  23. /** Destroys logging context and cleans up the memory
  24. * @param ctx Context to destroy */
  25. void mqtt_wss_log_ctx_destroy(mqtt_wss_log_ctx_t ctx);
  26. void mws_fatal(mqtt_wss_log_ctx_t ctx, const char *fmt, ...);
  27. void mws_error(mqtt_wss_log_ctx_t ctx, const char *fmt, ...);
  28. void mws_warn (mqtt_wss_log_ctx_t ctx, const char *fmt, ...);
  29. void mws_info (mqtt_wss_log_ctx_t ctx, const char *fmt, ...);
  30. void mws_debug(mqtt_wss_log_ctx_t ctx, const char *fmt, ...);
  31. #endif /* MQTT_WSS_LOG_H */