14#define LOG_CRITICAL(...) logger << Logger::Level::CRITICAL << __VA_ARGS__ << std::endl
15#define LOG_ERROR(...) logger << Logger::Level::ERROR << __VA_ARGS__ << std::endl
16#define LOG_WARNING(...) logger << Logger::Level::WARNING << __VA_ARGS__ << std::endl
17#define LOG_INFO(...) logger << Logger::Level::INFO << __VA_ARGS__ << std::endl
18#define LOG_DEBUG(...) logger << Logger::Level::DEBUG << __VA_ARGS__ << std::endl
19#define LOG_TRACE(...) logger << Logger::Level::TRACE << __VA_ARGS__ << std::endl
21#define LOG_CRITICAL_FMT(fmt, ...) logger << Logger::Level::CRITICAL << ft_format(fmt, __VA_ARGS__) << std::endl
22#define LOG_ERROR_FMT(fmt, ...) logger << Logger::Level::ERROR << ft_format(fmt, __VA_ARGS__) << std::endl
23#define LOG_WARNING_FMT(fmt, ...) logger << Logger::Level::WARNING << ft_format(fmt, __VA_ARGS__) << std::endl
24#define LOG_INFO_FMT(fmt, ...) logger << Logger::Level::INFO << ft_format(fmt, __VA_ARGS__) << std::endl
25#define LOG_DEBUG_FMT(fmt, ...) logger << Logger::Level::DEBUG << ft_format(fmt, __VA_ARGS__) << std::endl
26#define LOG_TRACE_FMT(fmt, ...) logger << Logger::Level::TRACE << ft_format(fmt, __VA_ARGS__) << std::endl
45 FileOutput(
const std::filesystem::path & path);
94 Logger(
const std::filesystem::path & path);
103 void configure(
const std::filesystem::path & path);
145 template <
typename T>
148 m_current_msg << arg;
157 bool m_file_initialized =
false;
162 std::stringstream m_current_msg;
167 std::unique_ptr<FileOutput> m_log_files[
static_cast<int>(
Level::MAX)];
182 bool m_timestamp_enabled =
true;
189 inline static std::string
const m_level_to_string[
static_cast<uint32_t
>(
MAX)] =
202 inline static std::string
const m_level_to_color[
static_cast<uint32_t
>(
MAX)] =
225 void _writeToConsole(std::string
const & message);
230 void _writeToFile(std::string
const & message);
235 std::string _levelHeader(
Level level,
bool color =
true);
240 std::string _timestamp();
A class that represents a file used for output with RAII.
Definition: logger.hpp:34
~FileOutput()
Destroy the FileOutput object and close the file.
Definition: logger.cpp:23
A class for logging messages to the console and to files.
Definition: logger.hpp:63
Logger & operator<<(T const &arg)
Transfer a argument to the stringstream buffer waiting to be flushed.
Definition: logger.hpp:146
Logger & operator<<(Level level)
Set the message level.
Definition: logger.cpp:70
void configure(const std::filesystem::path &path)
Open 5 different files for logging. If the files exist, they will be overwritten.
Definition: logger.cpp:44
void setTimestamp(bool enabled)
Enable or disable timestamps.
Definition: logger.cpp:65
void setLevel(Level level)
Set the minimum level of messages to log to the console.
Definition: logger.cpp:55
Logger()
Construct a new Logger object.
Definition: logger.cpp:37
Level
The different levels of logging.
Definition: logger.hpp:71
@ ERROR
Definition: logger.hpp:73
@ CRITICAL
Definition: logger.hpp:72
@ INFO
Definition: logger.hpp:75
@ TRACE
Definition: logger.hpp:77
@ MAX
Definition: logger.hpp:78
@ DEBUG
Definition: logger.hpp:76
@ WARNING
Definition: logger.hpp:74
Level level() const
Return the minimum level of messages to log to the console.
Definition: logger.cpp:60
Logger logger
Definition: logger.cpp:35