|
Aegis2D
Modular C++26 2D game engine for networked games
|
Writes timestamped messages to the console (std::clog) and to an optional file.
More...
#include <aegis2d/core/log.hpp>
Public Member Functions | |
| Logger ()=default | |
Creates a logger at level Info, writing to the console only. | |
| Logger (const Logger &)=delete | |
| Logger & | operator= (const Logger &)=delete |
| Logger (Logger &&)=delete | |
| Logger & | operator= (Logger &&)=delete |
| ~Logger ()=default | |
| void | set_level (LogLevel level) noexcept |
| Sets the minimum level a message needs to be written. | |
| LogLevel | level () const noexcept |
| Current minimum level. | |
| bool | enabled (LogLevel level) const noexcept |
| Tells whether a message of this level would be written. | |
| void | set_console (bool enabled) |
| Turns console output on or off (on by default). | |
| bool | open_file (const std::filesystem::path &path) |
| Appends every following message to a file, closing the previous one. | |
| void | close_file () |
| Stops writing to the file opened by open_file(), if any. | |
| void | write (LogLevel level, std::string_view message) |
| Writes an already formatted message if its level is enabled. | |
| template<typename... Args> | |
| void | log (LogLevel level, std::format_string< Args... > format, Args &&... args) |
| Formats and writes a message if its level is enabled. | |
Static Public Member Functions | |
| static Logger & | global () |
| Process-wide logger used by log_debug(), log_info(), log_warn() and log_error(). | |
Writes timestamped messages to the console (std::clog) and to an optional file.
Every line has the form 2026-10-02T14:03:07.512Z [INFO ] message, in UTC. Messages below the current level are dropped before being formatted. All member functions can be called from several threads at once.
|
default |
Creates a logger at level Info, writing to the console only.
|
delete |
|
delete |
|
default |
| void aegis2d::core::Logger::close_file | ( | ) |
Stops writing to the file opened by open_file(), if any.
|
noexcept |
Tells whether a message of this level would be written.
| level | Level of the message. |
true if level is not Off and is at least the current level.
|
static |
Process-wide logger used by log_debug(), log_info(), log_warn() and log_error().
|
noexcept |
Current minimum level.
LogLevel::Info by default.
|
inline |
Formats and writes a message if its level is enabled.
| level | Level of the message. |
| format | std::format format string, checked at compile time. |
| args | Values to format. |
| bool aegis2d::core::Logger::open_file | ( | const std::filesystem::path & | path | ) |
Appends every following message to a file, closing the previous one.
| path | File to open; it is created if needed and never truncated. |
true if the file is open, false otherwise (console output goes on). | void aegis2d::core::Logger::set_console | ( | bool | enabled | ) |
Turns console output on or off (on by default).
| enabled | true to write messages to std::clog. |
|
noexcept |
Sets the minimum level a message needs to be written.
| level | New minimum level; LogLevel::Off disables the logger. |
| void aegis2d::core::Logger::write | ( | LogLevel | level, |
| std::string_view | message | ||
| ) |
Writes an already formatted message if its level is enabled.
| level | Level of the message. |
| message | Text of the message, without trailing newline. |