From 20cb29c2f8c5c87bc590896854a20b1473ceb358 Mon Sep 17 00:00:00 2001 From: "info@mode42.com" Date: Sat, 8 Aug 2026 03:54:55 +0000 Subject: #2 --- include/hybbx/log.h | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 include/hybbx/log.h (limited to 'include/hybbx/log.h') diff --git a/include/hybbx/log.h b/include/hybbx/log.h new file mode 100644 index 0000000..aa70b5b --- /dev/null +++ b/include/hybbx/log.h @@ -0,0 +1,64 @@ +#ifndef HYBBX_LOG_H +#define HYBBX_LOG_H + +#include "hybbx/types.h" +#include "hybbx/limits.h" + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * File + console log severity (least to most severe for filtering): + * debug → stats → info → warn (default threshold). + * Messages at or above the configured [log] level are emitted. + */ +typedef enum hybbx_log_level { + HYBBX_LOG_DEBUG = 0, + HYBBX_LOG_STATS = 1, + HYBBX_LOG_INFO = 2, + HYBBX_LOG_WARN = 3 +} hybbx_log_level_t; + +typedef struct hybbx_log_config { + int enabled; + char dir[HYBBX_PATH_MAX]; + hybbx_log_level_t level; +} hybbx_log_config_t; + +void hybbx_log_config_defaults(hybbx_log_config_t *cfg); +void hybbx_log_config_apply(const struct hybbx_config *config); +const hybbx_log_config_t *hybbx_log_config_get(void); + +/** Non-zero when file logging is active. */ +int hybbx_log_enabled(void); + +/** + * Copy absolute path of the current hybbx log file into @p out. + * Returns HYBBX_OK when logging is enabled and a path is available. + */ +hybbx_result_t hybbx_log_current_path(char *out, size_t out_len); + +const char *hybbx_log_level_name(hybbx_log_level_t level); +hybbx_log_level_t hybbx_log_parse_level(const char *value); + +/** Non-zero when @p level would be written (console and file). */ +int hybbx_log_level_visible(hybbx_log_level_t level); + +void hybbx_log_write(hybbx_log_level_t level, const char *fmt, ...) + __attribute__((format(printf, 2, 3))); + +void hybbx_log_shutdown(void); + +#define hybbx_log_debug(...) hybbx_log_write(HYBBX_LOG_DEBUG, __VA_ARGS__) +#define hybbx_log_stats(...) hybbx_log_write(HYBBX_LOG_STATS, __VA_ARGS__) +#define hybbx_log_info(...) hybbx_log_write(HYBBX_LOG_INFO, __VA_ARGS__) +#define hybbx_log_warn(...) hybbx_log_write(HYBBX_LOG_WARN, __VA_ARGS__) + +#ifdef __cplusplus +} +#endif + +#endif /* HYBBX_LOG_H */ -- cgit v1.3.1