Skip to content

Commit 0703905

Browse files
committed
Add functionality to use a custom log handler, which facilitates
the integration of webui in software. Debug logging of webui can now be integrated in logging systems of software that uses webui. Signed-off-by: Hans Dijkema <hans@dijkewijk.nl>
1 parent 0758da5 commit 0703905

2 files changed

Lines changed: 660 additions & 550 deletions

File tree

include/webui.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,18 @@ typedef struct webui_event_t {
206206
char* cookies; // Client's full cookies
207207
} webui_event_t;
208208

209+
// custom log handler type
210+
typedef enum {
211+
log_debug_detail = 1,
212+
log_debug,
213+
log_info,
214+
log_warning,
215+
log_error,
216+
log_fatal
217+
} webui_log_level_t;
218+
219+
typedef void(*webui_custom_log_handler_t)(webui_log_level_t level, const char *, void *data);
220+
209221
// -- Definitions ---------------------
210222

211223
/**
@@ -909,6 +921,21 @@ WEBUI_EXPORT size_t webui_get_free_port(void);
909921
*/
910922
WEBUI_EXPORT void webui_set_config(webui_config option, bool status);
911923

924+
/**
925+
* @brief Set a custom logger function. The standard logger uses 'printf' to log debug information.
926+
*
927+
* @param logger function of type void (*custom_logger)(webui_log_level_t, const char *msg, void *user_data).
928+
*
929+
* a value of NULL for logger_f, will reset the webui logger to the default log handler.
930+
*
931+
* @example void my_logger(webui_log_level_t level, const char *msg, void *user_data) {
932+
* FILE *log_fh = static_cast<FILE *>(user_data);
933+
* fprintf(log_fh, "%d:%s", level, msg);
934+
* }
935+
* webui_set_custom_logger(my_logger);
936+
*/
937+
WEBUI_EXPORT void webui_set_custom_logger(webui_custom_log_handler_t logger_f, void *user_data);
938+
912939
/**
913940
* @brief Control if UI events comming from this window should be processed
914941
* one a time in a single blocking thread `True`, or process every event in

0 commit comments

Comments
 (0)