summaryrefslogtreecommitdiff
path: root/include/hybbx/log.h
blob: aa70b5b2dd455754c8a96cc9799e9cbf8141a77a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef HYBBX_LOG_H
#define HYBBX_LOG_H

#include "hybbx/types.h"
#include "hybbx/limits.h"

#include <stddef.h>

#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 */
git clone -b <branch> https://cgit.mode42.com/<repo>.git
git clone -b <branch> git://cgit.mode42.com/<repo>.git

info@mode42.com