19#define LOG(level, ...) log(level, std::source_location::current(), __VA_ARGS__)
25#include <source_location>
66 void log(
Level level,
const std::string& message,
67 const std::source_location& location = std::source_location::current()) noexcept;
78 template <typename... Args>
79 void log(const
Level level, const std::source_location& location, const std::
string& formatStr,
80 Args&&... args) noexcept
82 if (level >= _log_level)
84 const std::string message = std::vformat(formatStr, std::make_format_args(args...));
85 log(level, message, location);
95 std::expected<void, std::string>
logToFile(
const std::string& filePath)
noexcept;
99 std::optional<std::ofstream> _log_file;
100 std::mutex _log_mutex;
107 static std::string getCurrentTimestamp() noexcept;
151 template <
typename... Args>
152 void log(
Level level,
const std::source_location& location,
const std::string& formatStr, Args&&... args)
noexcept
154 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 setLevel(const Level level) noexcept
Sets the 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.
@ 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.