class final
#include <core/log.hpp>
Logger Singleton which holds the logging state.
Public types
- struct Entry
- Data created by a call to log.
- struct Location
- Identifies a location in the code.
- struct Timestamp
- A timestamp used to identify when a logging message was written.
- enum class Level { Trace = CUBOS_LOG_LEVEL_TRACE, Debug = CUBOS_LOG_LEVEL_DEBUG, Info = CUBOS_LOG_LEVEL_INFO, Warn = CUBOS_LOG_LEVEL_WARN, Error = CUBOS_LOG_LEVEL_ERROR, Critical = CUBOS_LOG_LEVEL_CRITICAL, Off = CUBOS_LOG_LEVEL_OFF }
- Represents a logging level.
Public static functions
- static void level(Level level)
- Sets the log level.
- static auto level() -> Level
- Gets the current log level.
- static auto logToFile(const std::string& filePath) -> bool
- Sets a file path where logs will be saved.
- static auto logToFile() -> bool
- Mounts a standard archive on the
/logs/
directory, and callslogToFile
to a timestamped log file on that directory. - static void write(Level level, Location location, std::string message)
- Creates a new entry in the logs, as long as the log level is high enough.
-
template<typename... TArgs>static void writeFormat(Level level, Location location, const char* format, TArgs... args)
- Wrapper for write() with message formatting.
- static auto read(std::size_t& cursor, Entry& entry) -> bool
- Reads a log entry, if there's a new one.
Constructors, destructors, conversion operators
- Logger() deleted
- Deleted constructor.
Enum documentation
enum class cubos:: core:: Logger:: Level
Represents a logging level.
Enumerators | |
---|---|
Trace |
Trace log level, lowest log level. Very verbose. |
Debug |
Debug log level. Contains messages useful for debugging, but which are not necessary in release builds. |
Info |
Information log level. Contains important events that are not errors. |
Warn |
Warn log level. Contains events that are not errors, but which are unexpected and may be problematic. |
Error |
Error log level. Contains errors which are recoverable from. |
Critical |
Critical log level, highest log level. Contains errors which are unrecoverable from. |
Off |
Off log level, disables all logging. |
Function documentation
static void cubos:: core:: Logger:: level(Level level)
Sets the log level.
Parameters | |
---|---|
level | New logging level. |
If CUBOS_
static bool cubos:: core:: Logger:: logToFile(const std::string& filePath)
Sets a file path where logs will be saved.
Parameters | |
---|---|
filePath | Path to file in the virtual file system. |
Returns | Whether the file could be opened for logging. |
static bool cubos:: core:: Logger:: logToFile()
Mounts a standard archive on the /logs/
directory, and calls logToFile
to a timestamped log file on that directory.
Returns | Whether the file could be mounted and opened for logging. |
---|
template<typename... TArgs>
static void cubos:: core:: Logger:: writeFormat(Level level,
Location location,
const char* format,
TArgs... args)
Wrapper for write() with message formatting.
Template parameters | |
---|---|
TArgs | Message format argument types. |
Parameters | |
level | Log level. |
location | Code location. |
format | Message format string. |
args | Message format arguments. |