12#include <common/version.h>
17using namespace MaxOS::common;
18using namespace MaxOS::console;
19using namespace MaxOS::processes;
20using namespace MaxOS::system;
29 s_active_logger =
this;
32 s_progress_total = 15;
37Logger::~Logger() =
default;
51 m_log_writers[m_log_writer_count] = log_writer;
52 m_log_writers_enabled[m_log_writer_count] =
true;
56 *
this << LogLevel::INFO <<
"Logger setup: " << m_log_writer_count <<
"\n";
57 *
this << LogLevel::HEADER <<
"MaxOS v" << VERSION_STRING <<
" [ build " << BUILD_NUMBER <<
" ]\n";
69 if (m_log_writer_count == 0)
73 for (
int i = 0; i < m_log_writer_count; i++)
74 if (m_log_writers[i] == log_writer)
75 m_log_writers_enabled[i] =
false;
86 if (m_log_writer_count == 0)
90 for (
int i = 0; i < m_log_writer_count; i++)
91 if (m_log_writers[i] == log_writer)
92 m_log_writers_enabled[i] =
true;
100 for (
int i = 0; i < m_log_writer_count; i++)
101 if (!m_log_writers_enabled[i])
102 m_log_writers_enabled[i] =
true;
113 m_log_level = log_level;
116 if (log_level == LogLevel::INFO) {
118 m_progress_current++;
124 case LogLevel::HEADER:
125 *
this << ANSI_COLOURS[FG_Blue] <<
"[ BOOT ] ";
129 *
this << ANSI_COLOURS[FG_Cyan] <<
"[ INFO ]" << ANSI_COLOURS[FG_White] <<
" ";
133 *
this << ANSI_COLOURS[FG_Green] <<
"[ TEST ]" << ANSI_COLOURS[FG_White] <<
" ";
136 case LogLevel::DEBUG:
137 *
this << ANSI_COLOURS[FG_Yellow] <<
"[ DEBUG ]" << ANSI_COLOURS[Reset] <<
" ";
140 case LogLevel::WARNING:
141 *
this << ANSI_COLOURS[BG_Yellow] << ANSI_COLOURS[FG_White] <<
"[ WARNING ]" << ANSI_COLOURS[Reset] <<
" ";
144 case LogLevel::ERROR:
145 *
this << ANSI_COLOURS[BG_Red] <<
"[ ERROR ]" << ANSI_COLOURS[Reset] <<
" ";
165 for (
int i = 0; i < m_log_writer_count; i++)
166 if (m_log_writers_enabled[i])
167 m_log_writers[i]->write_char(c);
178 return LogRecord(*s_active_logger, LogLevel::OUT);
187 return LogRecord(*s_active_logger, LogLevel::TEST);
196 return LogRecord(*s_active_logger, LogLevel::INFO);
205 return LogRecord(*s_active_logger, LogLevel::DEBUG);
214 return LogRecord(*s_active_logger, LogLevel::WARNING);
223 return LogRecord(*s_active_logger, LogLevel::ERROR);
232 return LogRecord(*s_active_logger, LogLevel::HEADER);
241 return s_active_logger;
255 va_start(parameters, format);
257 write(String::formatted(format, parameters));
274 va_start(parameters, message);
277 CPU::PANIC(String::formatted(message, parameters).c_str());
304 Logger::s_loggers_lock.lock();
305 if (level != LogLevel::OUT)
314 Logger::s_loggers_lock.unlock();
LogRecord(Logger &logger, LogLevel level)
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.
static void update_progress_bar(uint8_t percentage)
Updates the progress bar.
static void print_running_header()
Print the header for the running processes in the form ({name}:t{tid}c{core})
static void PANIC(const char *message, cpu_status_t *status=nullptr)
Puts the CPU into a panic state and halts it. Dumps the stack trace and registers.
Defines Central Processing Unit (CPU) structures and functions for managing CPU state and features.
Defines the VESABootConsole driver for handling console output during boot using an VESA framebuffer.
Defines a Logger class for logging messages with different severity levels to multiple output streams...
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.
Defines a GlobalScheduler and Scheduler for managing processes and threads.