cubos::core::Logger class final

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 calls logToFile 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_LOG_LEVEL is higher than the set level, entries below it are still not registered.

static Level cubos::core::Logger::level()

Gets the current log level.

Returns Log level.

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.

static void cubos::core::Logger::write(Level level, Location location, std::string message)

Creates a new entry in the logs, as long as the log level is high enough.

Parameters
level Log level.
location Code location.
message Log message.

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.

static bool cubos::core::Logger::read(std::size_t& cursor, Entry& entry)

Reads a log entry, if there's a new one.

Parameters
cursor out Index of the entry to be read. Automatically increased.
entry out Entry to read into.
Returns Whether an entry was red.