summaryrefslogtreecommitdiffstats
path: root/mqtt_websockets/src/include/mqtt_wss_log.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 02:57:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 02:57:58 +0000
commitbe1c7e50e1e8809ea56f2c9d472eccd8ffd73a97 (patch)
tree9754ff1ca740f6346cf8483ec915d4054bc5da2d /mqtt_websockets/src/include/mqtt_wss_log.h
parentInitial commit. (diff)
downloadnetdata-be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97.tar.xz
netdata-be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97.zip
Adding upstream version 1.44.3.upstream/1.44.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mqtt_websockets/src/include/mqtt_wss_log.h')
-rw-r--r--mqtt_websockets/src/include/mqtt_wss_log.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/mqtt_websockets/src/include/mqtt_wss_log.h b/mqtt_websockets/src/include/mqtt_wss_log.h
new file mode 100644
index 00000000..a33c460c
--- /dev/null
+++ b/mqtt_websockets/src/include/mqtt_wss_log.h
@@ -0,0 +1,37 @@
+#ifndef MQTT_WSS_LOG_H
+#define MQTT_WSS_LOG_H
+
+typedef enum mqtt_wss_log_type {
+ MQTT_WSS_LOG_DEBUG = 0x01,
+ MQTT_WSS_LOG_INFO = 0x02,
+ MQTT_WSS_LOG_WARN = 0x03,
+ MQTT_WSS_LOG_ERROR = 0x81,
+ MQTT_WSS_LOG_FATAL = 0x88
+} mqtt_wss_log_type_t;
+
+typedef void (*mqtt_wss_log_callback_t)(mqtt_wss_log_type_t, const char*);
+
+typedef struct mqtt_wss_log_ctx *mqtt_wss_log_ctx_t;
+
+/** Creates logging context with optional prefix and optional callback
+ * @param ctx_prefix String to be prefixed to every log message.
+ * This is useful if multiple clients are instantiated to be able to
+ * know which one this message belongs to. Can be `NULL` for no prefix.
+ * @param log_callback Callback to be called instead of logging to
+ * `STDOUT` or `STDERR` (if debug enabled otherwise silent). Callback has to be
+ * pointer to function of `void function(mqtt_wss_log_type_t, const char*)` type.
+ * If `NULL` default will be used (silent or STDERR/STDOUT).
+ * @return mqtt_wss_log_ctx_t or `NULL` on error */
+mqtt_wss_log_ctx_t mqtt_wss_log_ctx_create(const char *ctx_prefix, mqtt_wss_log_callback_t log_callback);
+
+/** Destroys logging context and cleans up the memory
+ * @param ctx Context to destroy */
+void mqtt_wss_log_ctx_destroy(mqtt_wss_log_ctx_t ctx);
+
+void mws_fatal(mqtt_wss_log_ctx_t ctx, const char *fmt, ...);
+void mws_error(mqtt_wss_log_ctx_t ctx, const char *fmt, ...);
+void mws_warn (mqtt_wss_log_ctx_t ctx, const char *fmt, ...);
+void mws_info (mqtt_wss_log_ctx_t ctx, const char *fmt, ...);
+void mws_debug(mqtt_wss_log_ctx_t ctx, const char *fmt, ...);
+
+#endif /* MQTT_WSS_LOG_H */