16#ifndef YASMIN__LOGS_HPP
17#define YASMIN__LOGS_HPP
91 const char *function,
int line,
const char *text);
111template <yasmin::LogLevel LEVEL>
112void log_helper(
const char *file,
const char *function,
int line,
113 const char *text, ...) {
115 va_start(args, text);
118 int size = vsnprintf(
nullptr, 0, text, args) + 1;
121 std::string buffer(size,
'\0');
122 va_start(args, text);
123 vsnprintf(&buffer[0], buffer.size(), text, args);
139 const char *filename = std::strrchr(path,
'/');
141 filename = std::strrchr(path,
'\\');
143 return filename ? filename + 1 : path;
147#define YASMIN_LOG_ERROR(text, ...) \
148 if (yasmin::log_level >= yasmin::ERROR) \
149 yasmin::log_helper<yasmin::ERROR>(extract_filename(__FILE__), __FUNCTION__, \
150 __LINE__, text, ##__VA_ARGS__)
151#define YASMIN_LOG_WARN(text, ...) \
152 if (yasmin::log_level >= yasmin::WARN) \
153 yasmin::log_helper<yasmin::WARN>(extract_filename(__FILE__), __FUNCTION__, \
154 __LINE__, text, ##__VA_ARGS__)
155#define YASMIN_LOG_INFO(text, ...) \
156 if (yasmin::log_level >= yasmin::INFO) \
157 yasmin::log_helper<yasmin::INFO>(extract_filename(__FILE__), __FUNCTION__, \
158 __LINE__, text, ##__VA_ARGS__)
159#define YASMIN_LOG_DEBUG(text, ...) \
160 if (yasmin::log_level >= yasmin::DEBUG) \
161 yasmin::log_helper<yasmin::DEBUG>(extract_filename(__FILE__), __FUNCTION__, \
162 __LINE__, text, ##__VA_ARGS__)
Definition blackboard.hpp:29
void set_log_level(LogLevel level)
Sets the log level for the logs.
Definition logs.cpp:45
void set_loggers(LogFunction log_message)
Sets custom logging functions for different log levels.
Definition logs.cpp:70
void(* LogFunction)(LogLevel level, const char *file, const char *function, int line, const char *text)
Type definition for a logging function.
Definition logs.hpp:90
void log_helper(const char *file, const char *function, int line, const char *text,...)
Variadic template function to log messages at different levels.
Definition logs.hpp:112
LogLevel log_level
The current log level for the application.
Definition logs.cpp:41
LogFunction log_message
Pointer to the logging function.
Definition logs.cpp:43
const char * log_level_to_name(LogLevel level)
Parse LogLevel to string.
Definition logs.cpp:47
const char * extract_filename(const char *path)
Extracts the filename from a given file path.
Definition logs.hpp:138
void set_default_loggers()
Sets the default logging function for all log levels.
Definition logs.cpp:72
LogLevel
Enum representing different log levels for controlling log verbosity.
Definition logs.hpp:33
@ INFO
Definition logs.hpp:41
@ WARN
Definition logs.hpp:38
@ DEBUG
Definition logs.hpp:44
@ ERROR
Log level for error messages. Only critical errors should be logged.
Definition logs.hpp:35