11#ifndef MAXOS_COMMON_LOGGER_H
12#define MAXOS_COMMON_LOGGER_H
14#include <libcommon/outputStream.h>
15#include <libcommon/colour.h>
16#include <libcommon/spinlock.h>
51 class Logger :
public MaxOS::common::OutputStream {
58 uint8_t m_log_writer_count = 0;
59 OutputStream* m_log_writers[
MAX_LOG_WRITERS] = {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr };
60 bool m_log_writers_enabled[
MAX_LOG_WRITERS] = {
false,
false,
false,
false,
false };
63 static inline uint8_t s_progress_total = 100;
64 uint8_t m_progress_current = 0;
66 static inline Logger* s_active_logger =
nullptr;
67 inline static common::Spinlock s_loggers_lock = {};
69 LogLevel m_log_level = LogLevel::INFO;
83 void printf(
const char* format, ...);
85 static void assert(
bool condition,
const char* message, ...);
98 using OutputStream::operator <<;
123 m_logger.write(value);
LogRecord & operator<<(const T &value)
A class that handles logging messages to the console and files.
static LogRecord TEST()
Gets the active logger for testing logs.
static void assert(bool condition, const char *message,...)
Puts the system into a panic state if the condition is false, printing the message first.
static LogRecord ERROR()
Gets the active logger for error logs.
void enable_log_writer(OutputStream *log_writer)
Lets an output stream from be used.
void printf(const char *format,...)
Prints a formatted string to the logger (thread safe)
static Logger * active_logger()
Gets the active logger (to be used to modify the logger)
static LogRecord DEBUG()
Gets the active logger for debug logs.
void disable_log_writer(OutputStream *log_writer)
Prevents an output stream from being used.
static LogRecord HEADER()
Gets the active logger for headers.
void add_log_writer(OutputStream *log_writer)
Adds an output stream to the logger.
static LogRecord INFO()
Gets the active logger for info logs.
static LogRecord WARNING()
Gets the active logger for warnings.
void write_char(char c) final
Writes a character to the logger.
static LogRecord Out()
Gets the active logger.
Logger()
Constructs a Logger object and sets it as the active logger.
void set_log_level(LogLevel log_level)
Sets the log level of the logger.
void enable_all_log_writers()
Mark all log writes as allowed to output to.
Logger & operator<<(LogLevel log_level)
Sets the log level of the logger.
LogLevel
Priority levels for logging messages. Different levels may be used to filter messages based on their ...
constexpr LogLevel MAX_LOG_LEVEL
The maximum log level for this build (messages above this level will not be logged)
constexpr uint8_t MAX_LOG_WRITERS
The maximum number of log writers that can be added to the logger.