Add the ability to toggle loglevels in KernelLog

This commit is contained in:
apio 2022-09-15 18:42:38 +02:00
parent 18140a55ec
commit 9d19765b0e
2 changed files with 10 additions and 0 deletions

View File

@ -14,6 +14,7 @@ namespace KernelLog
{ {
void log(const char* function, LogLevel level, const char* message, ...) PRINTF_LIKE(3, 4); void log(const char* function, LogLevel level, const char* message, ...) PRINTF_LIKE(3, 4);
void logln(const char* function, LogLevel level, const char* message, ...) PRINTF_LIKE(3, 4); void logln(const char* function, LogLevel level, const char* message, ...) PRINTF_LIKE(3, 4);
void toggle_log_level(LogLevel level);
} }
#ifndef MODULE #ifndef MODULE

View File

@ -4,8 +4,11 @@
#include "std/stdio.h" #include "std/stdio.h"
#include <stdarg.h> #include <stdarg.h>
static int level_mask = 15;
void KernelLog::log(const char* function, LogLevel level, const char* message, ...) void KernelLog::log(const char* function, LogLevel level, const char* message, ...)
{ {
if (!(level_mask & (1 << (int)level))) return;
va_list ap; va_list ap;
va_start(ap, message); va_start(ap, message);
Serial::reset_color(); Serial::reset_color();
@ -25,6 +28,7 @@ void KernelLog::log(const char* function, LogLevel level, const char* message, .
void KernelLog::logln(const char* function, LogLevel level, const char* message, ...) void KernelLog::logln(const char* function, LogLevel level, const char* message, ...)
{ {
if (!(level_mask & (1 << (int)level))) return;
va_list ap; va_list ap;
va_start(ap, message); va_start(ap, message);
Serial::reset_color(); Serial::reset_color();
@ -42,3 +46,8 @@ void KernelLog::logln(const char* function, LogLevel level, const char* message,
Serial::print("\n"); Serial::print("\n");
va_end(ap); va_end(ap);
} }
void KernelLog::toggle_log_level(LogLevel level)
{
level_mask ^= (1 << (int)level);
}