19#define LOG(level, ...) log(level, std::source_location::current(), __VA_ARGS__)
27#include <source_location>
55 using Callback = void (*)(
Level level,
const std::string& line,
void* user_data);
86 void log(
Level level, const std::
string& message,
87 const std::source_location& location = std::source_location::current()) noexcept;
98 template <typename... Args>
99 void log(const
Level level, const std::source_location& location, const std::
string& formatStr,
100 Args&&... args) noexcept
104 const std::string message = std::vformat(formatStr, std::make_format_args(args...));
105 log(level, message, location);
115 std::expected<void, std::string>
logToFile(
const std::string& filePath)
noexcept;
119 std::optional<std::ofstream> _log_file;
121 void* _callback_user_data =
nullptr;
122 std::mutex _log_mutex;
129 static std::string getCurrentTimestamp() noexcept;
175 template <
typename... Args>
176 void log(
Level level,
const std::source_location& location,
const std::string& formatStr, Args&&... args)
noexcept
178 logger.
log(level, location, formatStr, std::forward<Args>(args)...);
Enum class representing the log levels.
Thread-safe logger class for handling logging operations.
void log(Level level, const std::string &message, const std::source_location &location=std::source_location::current()) noexcept
Logs a message with a specific log level and source location.
std::expected< void, std::string > logToFile(const std::string &filePath) noexcept
Sets the log file path to log messages to a file.
void setCallback(Callback callback, void *user_data) noexcept
Sets an optional callback that receives each formatted log line.
void setLevel(Level level) noexcept
Sets the logging level.
void(*)(Level level, const std::string &line, void *user_data) Callback
Level getLevel() const noexcept
Gets the current logging level.
@ WARNING
Warning level for potentially harmful situations.
@ FATAL
Fatal level for severe error events.
@ TRACE
Trace level for detailed debugging information.
@ INFO
Info level for informational messages.
@ OFF
Special level to disable all logging.
@ ERROR
Error level for error events.
@ DEBUG
Debug level for general debugging information.
std::string getLevelString(const Level level) noexcept
Converts a log level enum value to its string representation.
Logger logger
Externally available logger object.