cbase 1.50.0
C/C++ Static Template
Loading...
Searching...
No Matches
base_log.h
Go to the documentation of this file.
1
52
53#ifndef BASE_LOG_H
54#define BASE_LOG_H
55
56#include "base_macros.h"
57#include "base_types.h"
58#include <stdarg.h>
59#include <stdio.h>
60
62
67
78
80typedef struct BaseLogEvent {
81 va_list ap;
82 const char *fmt;
83 const char *file;
84 int line;
87
89typedef void (*BaseLogFn)(BaseLogEvent *ev, void *user_data);
90
92typedef void (*BaseLogLockFn)(void *user_data, b32 lock);
93
110void
112
129void
130base_log_set_quiet(b32 enable);
131
154void
155base_log_set_lock(BaseLogLockFn fn, void *user_data);
156
180b32
181base_log_add_fp(FILE *fp, BaseLogLevel min_level);
182
206b32
207base_log_add_callback(BaseLogFn fn, void *user_data, BaseLogLevel min_level);
208
225b32
227
232void
233base_log_message(BaseLogLevel level, const char *file, int line, const char *fmt, ...);
234
236
237// Public Logging Macros
238
240#define LOG_TRACE(...) base_log_message(BASE_LOG_LEVEL_TRACE, __FILE__, __LINE__, __VA_ARGS__)
242#define LOG_DEBUG(...) base_log_message(BASE_LOG_LEVEL_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
244#define LOG_INFO(...) base_log_message(BASE_LOG_LEVEL_INFO, __FILE__, __LINE__, __VA_ARGS__)
246#define LOG_WARN(...) base_log_message(BASE_LOG_LEVEL_WARN, __FILE__, __LINE__, __VA_ARGS__)
248#define LOG_ERROR(...) base_log_message(BASE_LOG_LEVEL_ERROR, __FILE__, __LINE__, __VA_ARGS__)
250#define LOG_FATAL(...) base_log_message(BASE_LOG_LEVEL_FATAL, __FILE__, __LINE__, __VA_ARGS__)
251
253
254#endif // BASE_LOG_H
static void lock(void)
Acquires the logger lock if a locking function is configured.
Definition base_log.c:92
Context detection, compiler abstractions, utility macros, and data structures.
Core fixed-width type aliases and memory size constants.
#define C_LINKAGE_END
Closes a C linkage block for C++ compilers (Empty in C).
#define C_LINKAGE_BEGIN
Opens a C linkage block for C++ compilers (Empty in C).
b32 base_log_add_fp(FILE *fp, BaseLogLevel min_level)
Adds a standard C FILE* pointer as a logging destination.
Definition base_log.c:172
void base_log_set_quiet(b32 enable)
Mutes or unmutes all console (stdout/stderr) output.
Definition base_log.c:159
void base_log_message(BaseLogLevel level, const char *file, int line, const char *fmt,...)
Internal function that actually processes the log. DO NOT call directly.
Definition base_log.c:206
b32 base_log_remove_callback(BaseLogFn fn)
Removes a previously registered callback from the logger.
Definition base_log.c:192
void base_log_set_lock(BaseLogLockFn fn, void *user_data)
Configures thread-safety by providing a custom locking mechanism.
Definition base_log.c:165
void(* BaseLogLockFn)(void *user_data, b32 lock)
Signature for the thread-synchronization callback.
Definition base_log.h:92
void base_log_set_level(BaseLogLevel level)
Configures the active logging level. Messages below this level are ignored.
Definition base_log.c:153
b32 base_log_add_callback(BaseLogFn fn, void *user_data, BaseLogLevel min_level)
Adds a custom callback function as a logging destination.
Definition base_log.c:178
void(* BaseLogFn)(BaseLogEvent *ev, void *user_data)
Signature for custom logging destination callbacks.
Definition base_log.h:89
BaseLogLevel
The severity level of a log message.
Definition base_log.h:69
@ BASE_LOG_LEVEL_ERROR
Definition base_log.h:74
@ BASE_LOG_LEVEL_INFO
Definition base_log.h:72
@ BASE_LOG_LEVEL_DEBUG
Definition base_log.h:71
@ BASE_LOG_LEVEL_WARN
Definition base_log.h:73
@ BASE_LOG_LEVEL_FATAL
Definition base_log.h:75
@ BASE_LOG_LEVEL_TRACE
Definition base_log.h:70
int32_t b32
Definition base_types.h:111
A structured event containing all metadata for a single log message.
Definition base_log.h:80
const char * fmt
Definition base_log.h:82
va_list ap
Definition base_log.h:81
const char * file
Definition base_log.h:83
BaseLogLevel level
Definition base_log.h:85