cbase 1.46.11
C/C++ Static Template
Loading...
Searching...
No Matches
base_log.h
Go to the documentation of this file.
1
25
26#ifndef BASE_LOG_H
27#define BASE_LOG_H
28
29#include "base_macros.h"
30#include "base_types.h"
31#include <stdarg.h>
32#include <stdio.h>
33
35
40
51
53typedef struct LogEvent {
54 va_list ap;
55 const char *fmt;
56 const char *file;
57 int line;
60
62typedef void (*LogFn)(LogEvent *ev, void *user_data);
63
65typedef void (*LogLockFn)(void *user_data, b32 lock);
66
71void
73
78void
79log_set_quiet(b32 enable);
80
86void
87log_set_lock(LogLockFn fn, void *user_data);
88
94b32
95log_add_fp(FILE *fp, LogLevel min_level);
96
103b32
104log_add_callback(LogFn fn, void *user_data, LogLevel min_level);
105
110void
111log_message(LogLevel level, const char *file, int line, const char *fmt, ...);
112
114
115// Public Logging Macros
116
118#define LOG_TRACE(...) log_message(LOG_LEVEL_TRACE, __FILE__, __LINE__, __VA_ARGS__)
120#define LOG_DEBUG(...) log_message(LOG_LEVEL_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
122#define LOG_INFO(...) log_message(LOG_LEVEL_INFO, __FILE__, __LINE__, __VA_ARGS__)
124#define LOG_WARN(...) log_message(LOG_LEVEL_WARN, __FILE__, __LINE__, __VA_ARGS__)
126#define LOG_ERROR(...) log_message(LOG_LEVEL_ERROR, __FILE__, __LINE__, __VA_ARGS__)
128#define LOG_FATAL(...) log_message(LOG_LEVEL_FATAL, __FILE__, __LINE__, __VA_ARGS__)
129
131
132#endif // BASE_LOG_H
static void lock(void)
Acquires the logger lock if a locking function is configured.
Definition base_log.c:78
Context detection, utilities, compiler abstractions, and data structures.
Core type definitions and fixed-width aliases.
#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 log_add_fp(FILE *fp, LogLevel min_level)
Adds a standard C FILE* pointer as a logging destination.
Definition base_log.c:160
void log_set_level(LogLevel level)
Configures the active logging level. Messages below this level are ignored.
Definition base_log.c:141
void(* LogLockFn)(void *user_data, b32 lock)
Signature for the thread-synchronization callback.
Definition base_log.h:65
void log_set_lock(LogLockFn fn, void *user_data)
Configures thread-safety by providing a custom locking mechanism.
Definition base_log.c:153
void log_message(LogLevel level, const char *file, int line, const char *fmt,...)
Internal function that actually processes the log. DO NOT call directly.
Definition base_log.c:180
LogLevel
The severity level of a log message.
Definition base_log.h:42
b32 log_add_callback(LogFn fn, void *user_data, LogLevel min_level)
Adds a custom callback function as a logging destination.
Definition base_log.c:166
void(* LogFn)(LogEvent *ev, void *user_data)
Signature for custom logging destination callbacks.
Definition base_log.h:62
void log_set_quiet(b32 enable)
Mutes or unmutes all console (stdout/stderr) output.
Definition base_log.c:147
@ LOG_LEVEL_DEBUG
Definition base_log.h:44
@ LOG_LEVEL_ERROR
Definition base_log.h:47
@ LOG_LEVEL_FATAL
Definition base_log.h:48
@ LOG_LEVEL_TRACE
Definition base_log.h:43
@ LOG_LEVEL_WARN
Definition base_log.h:46
@ LOG_LEVEL_INFO
Definition base_log.h:45
int32_t b32
Definition base_types.h:75
A structured event containing all metadata for a single log message.
Definition base_log.h:53
const char * file
Definition base_log.h:56
LogLevel level
Definition base_log.h:58
const char * fmt
Definition base_log.h:55
va_list ap
Definition base_log.h:54
int line
Definition base_log.h:57