Skip to content

Commit 2302666

Browse files
authored
Merge pull request #649 from hdijkema/log-handling
Add functionality to use a custom log handler
2 parents 63fb9fc + b4e9202 commit 2302666

File tree

2 files changed

+626
-552
lines changed

2 files changed

+626
-552
lines changed

include/webui.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ typedef struct webui_event_t {
210210
char* cookies; // Client's full cookies
211211
} webui_event_t;
212212

213+
enum webui_logger_level {
214+
WEBUI_LOGGER_LEVEL_DEBUG = 0, // 0. All logs with all details
215+
WEBUI_LOGGER_LEVEL_INFO, // 1. Only general logs
216+
WEBUI_LOGGER_LEVEL_ERROR, // 2. Only fatal error logs
217+
};
218+
213219
// -- Definitions ---------------------
214220

215221
/**
@@ -929,6 +935,17 @@ WEBUI_EXPORT bool webui_set_port(size_t window, size_t port);
929935
*/
930936
WEBUI_EXPORT size_t webui_get_free_port(void);
931937

938+
/**
939+
* @brief Set a custom logger function.
940+
*
941+
* @example
942+
* void myLogger(size_t level, const char* log, void* user_data) {
943+
* printf("myLogger (%d): %s", level, log);
944+
* }
945+
* webui_set_logger(myLogger, NULL);
946+
*/
947+
WEBUI_EXPORT void webui_set_logger(void (*func)(size_t level, const char* log, void* user_data), void *user_data);
948+
932949
/**
933950
* @brief Control the WebUI behaviour. It's recommended to be called at the beginning.
934951
*

0 commit comments

Comments
 (0)