Fix bug in log::enable

This commit is contained in:
Justin C. Miller
2018-05-05 15:33:56 -07:00
parent bc6a42735c
commit 569bc243f1
3 changed files with 9 additions and 11 deletions

View File

@@ -132,8 +132,6 @@ public:
void set_color(uint8_t fg, uint8_t bg) void set_color(uint8_t fg, uint8_t bg)
{ {
if (!m_palette) return;
m_bg = m_palette[bg]; m_bg = m_palette[bg];
m_fg = m_palette[fg]; m_fg = m_palette[fg];
m_attr = (bg << 8) | fg; m_attr = (bg << 8) | fg;

View File

@@ -1,10 +1,11 @@
#include <type_traits> #include <type_traits>
#include "kutil/memory.h" #include "kutil/memory.h"
#include "assert.h"
#include "console.h" #include "console.h"
#include "log.h" #include "log.h"
static const uint64_t default_enabled[] = {0x00, 0x0f, 0x0f, 0x0f}; static const uint64_t default_enabled[] = {0x00, 0xff, 0xff, 0xff};
static const uint8_t level_colors[] = {0x07, 0x0f, 0x0b, 0x09}; static const uint8_t level_colors[] = {0x07, 0x0f, 0x0b, 0x09};
static const char *levels[] = {"debug", " info", " warn", "error", "fatal"}; static const char *levels[] = {"debug", " info", " warn", "error", "fatal"};
@@ -20,17 +21,16 @@ static const char *areas[] = {
log log::s_log; log log::s_log;
log::log() : log::log() : m_cons(nullptr)
m_cons(nullptr)
{ {
for (int i = 0; i < sizeof(m_enabled) / sizeof(uint64_t); ++i) kassert(0, "Invalid log constructor");
m_enabled[i] = default_enabled[i];
} }
log::log(console *cons) : log::log(console *cons) :
m_cons(cons) m_cons(cons)
{ {
for (int i = 0; i < sizeof(m_enabled) / sizeof(uint64_t); ++i) const int num_levels = static_cast<int>(level::max) - 1;
for (int i = 0; i < num_levels; ++i)
m_enabled[i] = default_enabled[i]; m_enabled[i] = default_enabled[i];
} }
@@ -49,10 +49,10 @@ log::enable(logs type, level at_level)
{ {
using under_t = std::underlying_type<level>::type; using under_t = std::underlying_type<level>::type;
under_t at = static_cast<under_t>(at_level); under_t at = static_cast<under_t>(at_level);
under_t max = sizeof(m_enabled) / sizeof(under_t); under_t max = sizeof(m_enabled) / sizeof(m_enabled[0]);
for (under_t i = 0; i < max; ++i) { for (under_t i = 0; i < max; ++i) {
if (i <= at) if (i >= at)
s_log.m_enabled[i] |= bit_mask(type); s_log.m_enabled[i] |= bit_mask(type);
else else
s_log.m_enabled[i] &= ~bit_mask(type); s_log.m_enabled[i] &= ~bit_mask(type);

View File

@@ -46,7 +46,7 @@ init_console(const popcorn_data *header)
cons->puts(GIT_VERSION " booting...\n"); cons->puts(GIT_VERSION " booting...\n");
log::init(cons); log::init(cons);
//log::enable(logs::apic, log::level::debug); log::enable(logs::apic, log::level::debug);
log::enable(logs::devices, log::level::debug); log::enable(logs::devices, log::level::debug);
} }