kiba-engine
Macros | Typedefs | Enumerations | Functions
log.h File Reference

Logging system. More...

#include <kiba/core/config.h>
#include <assert.h>
Include dependency graph for log.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define KB_MAX_LOG_ENTRY_SIZE   8192
 
#define STATIC_ASSERT   static_assert
 Performs a static assert. More...
 
#define KB_ASSERT(expr, ...)
 Perform runtime assertion and log failures. More...
 
#define KB_FATAL(...)   write_log_entry(LOG_LEVEL_FATAL, __FILE__, __LINE__, __VA_ARGS__)
 Log entry with fatal log level. More...
 
#define KB_ERROR(...)   write_log_entry(LOG_LEVEL_ERROR, __FILE__, __LINE__, __VA_ARGS__)
 Log entry with error log level. More...
 
#define KB_WARN(...)
 Log entry with warn log level. More...
 
#define KB_INFO(...)
 Log entry with info log level. More...
 
#define KB_DEBUG(...)
 Log entry with debug log level. More...
 
#define KB_TRACE(...)
 Log entry with trace log level. More...
 
#define KB_ASSERT_DEBUG(expr, ...)
 Perform runtime debug assertion and log failures. More...
 

Typedefs

typedef enum log_level log_level
 Available log levels.
 

Enumerations

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.
 

Functions

KB_API void enable_stacktraces (log_level level)
 Enables output of the stacktrace. More...
 
KB_API void disable_stacktraces (void)
 Disables output of the stacktrace.
 
KB_API void log_set_active_level (log_level level)
 Set the minimum log level to log. More...
 
void write_log_entry (log_level level, const char *file, long int line, const char *msg,...)
 Create log entry and write to output channel. More...
 
void write_to_console (log_level level, const char *msg)
 Write string to console. More...
 

Detailed Description

Logging system.

Definition in file log.h.

Macro Definition Documentation

◆ 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
exprexpression 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
exprexpression to assert (true = good, false = error)
...message followed by optional arguments to be formatted

Definition at line 165 of file log.h.

◆ KB_DEBUG

#define 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

#define 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

#define 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

#define 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.

Function Documentation

◆ 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
levelthe 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
levelthe 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
levelseverity of the entry
filepath to the file the entry was created in
lineline in the file the entry was created in
msglog 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
levelseverity of the entry
msglog entry

Definition at line 49 of file log.c.