16#ifndef YASMIN__LOGS_HPP
17#define YASMIN__LOGS_HPP
67 int line,
const char *text);
104 const char *function,
int line,
const char *text);
123template <yasmin::LogLevel LEVEL>
124void log_helper(
const char *file,
const char *function,
int line,
125 const char *text, ...) {
127 va_start(args, text);
130 int size = vsnprintf(
nullptr, 0, text, args) + 1;
133 std::string buffer(size,
'\0');
134 va_start(args, text);
135 vsnprintf(&buffer[0], buffer.size(), text, args);
151 const char *filename = std::strrchr(path,
'/');
153 filename = std::strrchr(path,
'\\');
155 return filename ? filename + 1 : path;
159#define YASMIN_LOG_ERROR(text, ...) \
160 if (yasmin::log_level >= yasmin::ERROR) \
161 yasmin::log_helper<yasmin::ERROR>(::yasmin::extract_filename(__FILE__), \
162 __FUNCTION__, __LINE__, text, \
164#define YASMIN_LOG_WARN(text, ...) \
165 if (yasmin::log_level >= yasmin::WARN) \
166 yasmin::log_helper<yasmin::WARN>(::yasmin::extract_filename(__FILE__), \
167 __FUNCTION__, __LINE__, text, \
169#define YASMIN_LOG_INFO(text, ...) \
170 if (yasmin::log_level >= yasmin::INFO) \
171 yasmin::log_helper<yasmin::INFO>(::yasmin::extract_filename(__FILE__), \
172 __FUNCTION__, __LINE__, text, \
174#define YASMIN_LOG_DEBUG(text, ...) \
175 if (yasmin::log_level >= yasmin::DEBUG) \
176 yasmin::log_helper<yasmin::DEBUG>(::yasmin::extract_filename(__FILE__), \
177 __FUNCTION__, __LINE__, text, \
Definition blackboard.hpp:29
void default_log_message(LogLevel level, const char *file, const char *function, int line, const char *text)
Default logging function.
Definition logs.cpp:22
void set_loggers(LogFunction log_message)
Sets custom logging functions for different log levels.
Definition logs.cpp:58
void(* LogFunction)(LogLevel level, const char *file, const char *function, int line, const char *text)
Type definition for a logging function.
Definition logs.hpp:103
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:124
LogLevel log_level
The current log level for the application.
Definition logs.cpp:29
void set_log_level(LogLevel new_log_level)
Sets the log level for the logs.
Definition logs.cpp:33
LogFunction log_message
Pointer to the logging function.
Definition logs.cpp:31
const char * log_level_to_name(LogLevel level)
Parse LogLevel to string.
Definition logs.cpp:35
const char * extract_filename(const char *path)
Extracts the filename from a given file path.
Definition logs.hpp:150
void set_default_loggers()
Sets the default logging function for all log levels.
Definition logs.cpp:60
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