Logging system.
More...
#include <kiba/core/config.h>
#include <assert.h>
Go to the source code of this file.
|
enum | log_level {
LOG_LEVEL_FATAL
, LOG_LEVEL_ERROR
, LOG_LEVEL_WARN
, LOG_LEVEL_INFO
,
LOG_LEVEL_DEBUG
, LOG_LEVEL_TRACE
, LOG_LEVEL_MAX
} |
| Available log levels.
|
|
Logging system.
Definition in file log.h.
◆ KB_ASSERT
#define KB_ASSERT |
( |
|
expr, |
|
|
|
... |
|
) |
| |
Value: do { \
if (expr) { \
} else { \
write_log_entry(LOG_LEVEL_FATAL, __FILE__, __LINE__, "assertion for " #expr " failed: " __VA_ARGS__); \
DEBUG_BREAK; \
} \
} while (0)
Perform runtime assertion and log failures.
Logs a fatal error when the assertion fails.
- Parameters
-
expr | expression to assert (true = good, false = error) |
... | message followed by optional arguments to be formatted |
Definition at line 133 of file log.h.
◆ KB_ASSERT_DEBUG
#define KB_ASSERT_DEBUG |
( |
|
expr, |
|
|
|
... |
|
) |
| |
Value: do { \
b8 _res = expr; \
UNUSED(_res); \
} while (0)
Perform runtime debug assertion and log failures.
Logs a fatal error when the assertion fails. Only evaluated in debug builds.
- Parameters
-
expr | expression to assert (true = good, false = error) |
... | message followed by optional arguments to be formatted |
Definition at line 165 of file log.h.
◆ KB_DEBUG
Log entry with debug log level.
- Parameters
-
... | message followed by optional arguments to be formatted |
Definition at line 163 of file log.h.
◆ KB_ERROR
#define KB_ERROR |
( |
|
... | ) |
write_log_entry(LOG_LEVEL_ERROR, __FILE__, __LINE__, __VA_ARGS__) |
Log entry with error log level.
- Parameters
-
... | message followed by optional arguments to be formatted |
Definition at line 142 of file log.h.
◆ KB_FATAL
#define KB_FATAL |
( |
|
... | ) |
write_log_entry(LOG_LEVEL_FATAL, __FILE__, __LINE__, __VA_ARGS__) |
Log entry with fatal log level.
- Parameters
-
... | message followed by optional arguments to be formatted |
Definition at line 141 of file log.h.
◆ KB_INFO
Log entry with info log level.
- Parameters
-
... | message followed by optional arguments to be formatted |
Definition at line 162 of file log.h.
◆ KB_TRACE
Log entry with trace log level.
- Parameters
-
... | message followed by optional arguments to be formatted |
Definition at line 164 of file log.h.
◆ KB_WARN
Log entry with warn log level.
- Parameters
-
... | message followed by optional arguments to be formatted |
Definition at line 161 of file log.h.
◆ STATIC_ASSERT
#define STATIC_ASSERT static_assert |
Performs a static assert.
Tries to use a compiler instrinsic version where possible.
Definition at line 75 of file log.h.
◆ enable_stacktraces()
KB_API void enable_stacktraces |
( |
log_level |
level | ) |
|
Enables output of the stacktrace.
Stacktrace output is enabled for all logging calls equal or more severe than the level provided.
- Parameters
-
level | the highest level to enable stacktrace logging for |
Definition at line 25 of file log.c.
◆ log_set_active_level()
KB_API void log_set_active_level |
( |
log_level |
level | ) |
|
Set the minimum log level to log.
Every log call with this or a more severe level will be logged.
- Parameters
-
level | the minimum level to set |
Definition at line 29 of file log.c.
◆ write_log_entry()
void write_log_entry |
( |
log_level |
level, |
|
|
const char * |
file, |
|
|
long int |
line, |
|
|
const char * |
msg, |
|
|
|
... |
|
) |
| |
Create log entry and write to output channel.
- Parameters
-
level | severity of the entry |
file | path to the file the entry was created in |
line | line in the file the entry was created in |
msg | log message, can contain format character sequences |
... | arguments to be used for formatting |
Definition at line 31 of file log.c.
◆ write_to_console()
void write_to_console |
( |
log_level |
level, |
|
|
const char * |
msg |
|
) |
| |
Write string to console.
- Parameters
-
level | severity of the entry |
msg | log entry |
Definition at line 49 of file log.c.