Kohi Game Engine
logger.h
Go to the documentation of this file.
1 
12 #pragma once
13 
14 #include "defines.h"
15 
17 #define LOG_WARN_ENABLED 1
19 #define LOG_INFO_ENABLED 1
20 
21 // Disable debug and trace logging for release builds.
22 #if KRELEASE == 1
23 #define LOG_DEBUG_ENABLED 0
24 #define LOG_TRACE_ENABLED 0
25 #else
27 #define LOG_DEBUG_ENABLED 1
29 #define LOG_TRACE_ENABLED 1
30 #endif
31 
33 typedef enum log_level {
45  LOG_LEVEL_TRACE = 5
47 
48 // A function pointer for a console to hook into the logger.
49 typedef void (*PFN_console_write)(log_level level, const char* message);
50 
61 
68 KAPI void _log_output(log_level level, const char* message, ...);
69 
75 #define KFATAL(message, ...) _log_output(LOG_LEVEL_FATAL, message, ##__VA_ARGS__);
76 
77 #ifndef KERROR
84 #define KERROR(message, ...) _log_output(LOG_LEVEL_ERROR, message, ##__VA_ARGS__);
85 #endif
86 
87 #if LOG_WARN_ENABLED == 1
94 #define KWARN(message, ...) _log_output(LOG_LEVEL_WARN, message, ##__VA_ARGS__);
95 #else
102 #define KWARN(message, ...)
103 #endif
104 
105 #if LOG_INFO_ENABLED == 1
111 #define KINFO(message, ...) _log_output(LOG_LEVEL_INFO, message, ##__VA_ARGS__);
112 #else
119 #define KINFO(message, ...)
120 #endif
121 
122 #if LOG_DEBUG_ENABLED == 1
128 #define KDEBUG(message, ...) _log_output(LOG_LEVEL_DEBUG, message, ##__VA_ARGS__);
129 #else
136 #define KDEBUG(message, ...)
137 #endif
138 
139 #if LOG_TRACE_ENABLED == 1
145 #define KTRACE(message, ...) _log_output(LOG_LEVEL_TRACE, message, ##__VA_ARGS__);
146 #else
153 #define KTRACE(message, ...)
154 #endif
This file contains global type definitions which are used throughout the entire engine and applicatio...
#define KAPI
Import/export qualifier.
Definition: defines.h:205
KAPI void _log_output(log_level level, const char *message,...)
Outputs logging at the given level. NOTE: This should not be called directly.
void(* PFN_console_write)(log_level level, const char *message)
Definition: logger.h:49
KAPI void logger_console_write_hook_set(PFN_console_write hook)
Provides a hook to a console (perhaps from Kohi Runtime or elsewhere) that the logging system can for...
log_level
Represents levels of logging.
Definition: logger.h:33
@ LOG_LEVEL_DEBUG
Debug log level, should be used for debugging purposes.
Definition: logger.h:43
@ LOG_LEVEL_ERROR
Error log level, should be used to indicate critical runtime problems that cause the application to r...
Definition: logger.h:37
@ LOG_LEVEL_FATAL
Fatal log level, should be used to stop the application when hit.
Definition: logger.h:35
@ LOG_LEVEL_TRACE
Trace log level, should be used for verbose debugging purposes.
Definition: logger.h:45
@ LOG_LEVEL_WARN
Warning log level, should be used to indicate non-critial problems with the application that cause it...
Definition: logger.h:39
@ LOG_LEVEL_INFO
Info log level, should be used for non-erronuous informational purposes.
Definition: logger.h:41