Kohi Game Engine
logger.h File Reference

This file contains structures and logic pertaining to the logging system. More...

#include "defines.h"

Go to the source code of this file.

Macros

#define LOG_WARN_ENABLED   1
 Indicates if warning level logging is enabled. More...
 
#define LOG_INFO_ENABLED   1
 Indicates if info level logging is enabled. More...
 
#define LOG_DEBUG_ENABLED   1
 Indicates if debug level logging is enabled. More...
 
#define LOG_TRACE_ENABLED   1
 Indicates if trace level logging is enabled. More...
 
#define KFATAL(message, ...)   _log_output(LOG_LEVEL_FATAL, message, ##__VA_ARGS__);
 Logs a fatal-level message. Should be used to stop the application when hit. More...
 
#define KERROR(message, ...)   _log_output(LOG_LEVEL_ERROR, message, ##__VA_ARGS__);
 Logs an error-level message. Should be used to indicate critical runtime problems that cause the application to run improperly or not at all. More...
 
#define KWARN(message, ...)   _log_output(LOG_LEVEL_WARN, message, ##__VA_ARGS__);
 Logs a warning-level message. Should be used to indicate non-critial problems with the application that cause it to run suboptimally. More...
 
#define KINFO(message, ...)   _log_output(LOG_LEVEL_INFO, message, ##__VA_ARGS__);
 Logs an info-level message. Should be used for non-erronuous informational purposes. More...
 
#define KDEBUG(message, ...)   _log_output(LOG_LEVEL_DEBUG, message, ##__VA_ARGS__);
 Logs a debug-level message. Should be used for debugging purposes. More...
 
#define KTRACE(message, ...)   _log_output(LOG_LEVEL_TRACE, message, ##__VA_ARGS__);
 Logs a trace-level message. Should be used for verbose debugging purposes. More...
 

Typedefs

typedef enum log_level log_level
 Represents levels of logging. More...
 
typedef void(* PFN_console_write) (log_level level, const char *message)
 

Enumerations

enum  log_level {
  LOG_LEVEL_FATAL = 0 , LOG_LEVEL_ERROR = 1 , LOG_LEVEL_WARN = 2 , LOG_LEVEL_INFO = 3 ,
  LOG_LEVEL_DEBUG = 4 , LOG_LEVEL_TRACE = 5
}
 Represents levels of logging. More...
 

Functions

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 forward messages to. If not set, logs go straight to the platform layer. If set, messages go to the hook instead, so it would be responsible for passing messages to the platform layer. NOTE: May only be set once - additional calls will overwrite. More...
 
KAPI void _log_output (log_level level, const char *message,...)
 Outputs logging at the given level. NOTE: This should not be called directly. More...
 

Detailed Description

This file contains structures and logic pertaining to the logging system.

Author
Travis Vroman (travi.nosp@m.s@ko.nosp@m.hieng.nosp@m.ine..nosp@m.com)
Version
2.0
Date
2024-04-02

Macro Definition Documentation

◆ KDEBUG

#define KDEBUG (   message,
  ... 
)    _log_output(LOG_LEVEL_DEBUG, message, ##__VA_ARGS__);

Logs a debug-level message. Should be used for debugging purposes.

Parameters
messageThe message to be logged.
...Any formatted data that should be included in the log entry.

◆ KERROR

#define KERROR (   message,
  ... 
)    _log_output(LOG_LEVEL_ERROR, message, ##__VA_ARGS__);

Logs an error-level message. Should be used to indicate critical runtime problems that cause the application to run improperly or not at all.

Parameters
messageThe message to be logged.
...Any formatted data that should be included in the log entry.

◆ KFATAL

#define KFATAL (   message,
  ... 
)    _log_output(LOG_LEVEL_FATAL, message, ##__VA_ARGS__);

Logs a fatal-level message. Should be used to stop the application when hit.

Parameters
messageThe message to be logged. Can be a format string for additional parameters.
...Additional parameters to be logged.

◆ KINFO

#define KINFO (   message,
  ... 
)    _log_output(LOG_LEVEL_INFO, message, ##__VA_ARGS__);

Logs an info-level message. Should be used for non-erronuous informational purposes.

Parameters
messageThe message to be logged.
...Any formatted data that should be included in the log entry.

◆ KTRACE

#define KTRACE (   message,
  ... 
)    _log_output(LOG_LEVEL_TRACE, message, ##__VA_ARGS__);

Logs a trace-level message. Should be used for verbose debugging purposes.

Parameters
messageThe message to be logged.
...Any formatted data that should be included in the log entry.

◆ KWARN

#define KWARN (   message,
  ... 
)    _log_output(LOG_LEVEL_WARN, message, ##__VA_ARGS__);

Logs a warning-level message. Should be used to indicate non-critial problems with the application that cause it to run suboptimally.

Parameters
messageThe message to be logged.
...Any formatted data that should be included in the log entry.

◆ LOG_DEBUG_ENABLED

#define LOG_DEBUG_ENABLED   1

Indicates if debug level logging is enabled.

◆ LOG_INFO_ENABLED

#define LOG_INFO_ENABLED   1

Indicates if info level logging is enabled.

◆ LOG_TRACE_ENABLED

#define LOG_TRACE_ENABLED   1

Indicates if trace level logging is enabled.

◆ LOG_WARN_ENABLED

#define LOG_WARN_ENABLED   1

Indicates if warning level logging is enabled.

Typedef Documentation

◆ log_level

typedef enum log_level log_level

Represents levels of logging.

◆ PFN_console_write

typedef void(* PFN_console_write) (log_level level, const char *message)

Enumeration Type Documentation

◆ log_level

enum log_level

Represents levels of logging.

Enumerator
LOG_LEVEL_FATAL 

Fatal log level, should be used to stop the application when hit.

LOG_LEVEL_ERROR 

Error log level, should be used to indicate critical runtime problems that cause the application to run improperly or not at all.

LOG_LEVEL_WARN 

Warning log level, should be used to indicate non-critial problems with the application that cause it to run suboptimally.

LOG_LEVEL_INFO 

Info log level, should be used for non-erronuous informational purposes.

LOG_LEVEL_DEBUG 

Debug log level, should be used for debugging purposes.

LOG_LEVEL_TRACE 

Trace log level, should be used for verbose debugging purposes.

Function Documentation

◆ _log_output()

KAPI void _log_output ( log_level  level,
const char *  message,
  ... 
)

Outputs logging at the given level. NOTE: This should not be called directly.

Parameters
levelThe log level to use.
messageThe message to be logged.
...Any formatted data that should be included in the log entry.

◆ logger_console_write_hook_set()

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 forward messages to. If not set, logs go straight to the platform layer. If set, messages go to the hook instead, so it would be responsible for passing messages to the platform layer. NOTE: May only be set once - additional calls will overwrite.

Parameters
hookA function pointer from the console hook.