Change log level to use an enum instead of uint
This commit is contained in:
parent
4dd979ef54
commit
f354b2d733
@ -8,6 +8,13 @@ namespace mtl {
|
|||||||
|
|
||||||
namespace log {
|
namespace log {
|
||||||
|
|
||||||
|
enum class level : uint32_t {
|
||||||
|
error = 1,
|
||||||
|
warn = 2,
|
||||||
|
info = 3,
|
||||||
|
debug = 4,
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef __GBA__
|
#ifdef __GBA__
|
||||||
constexpr char endl_char = 0;
|
constexpr char endl_char = 0;
|
||||||
#else
|
#else
|
||||||
@ -32,10 +39,10 @@ constexpr char endl_char = '\n';
|
|||||||
*/
|
*/
|
||||||
class stream : public basic_string_stream<false, endl_char> {
|
class stream : public basic_string_stream<false, endl_char> {
|
||||||
private:
|
private:
|
||||||
uint32_t m_log_level;
|
level m_log_level;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
stream(istring& str, uint32_t log_level);
|
stream(istring& str, level log_level);
|
||||||
~stream();
|
~stream();
|
||||||
|
|
||||||
using basic_string_stream::operator=;
|
using basic_string_stream::operator=;
|
||||||
|
|||||||
@ -39,7 +39,7 @@ static volatile uint16_t& flags = *reinterpret_cast<uint16_t*>(0x4FFF700);
|
|||||||
static string_ext string(reinterpret_cast<char*>(0x4FFF600), 256);
|
static string_ext string(reinterpret_cast<char*>(0x4FFF600), 256);
|
||||||
}; // namespace reg
|
}; // namespace reg
|
||||||
|
|
||||||
stream::stream(istring& buf, uint32_t log_level)
|
stream::stream(istring& buf, level log_level)
|
||||||
: basic_string_stream(buf), m_log_level(log_level) {
|
: basic_string_stream(buf), m_log_level(log_level) {
|
||||||
reg::enable = 0xC0DE;
|
reg::enable = 0xC0DE;
|
||||||
}
|
}
|
||||||
@ -48,14 +48,14 @@ stream::~stream() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void stream::flush() {
|
void stream::flush() {
|
||||||
reg::flags = 0x100 | m_log_level;
|
reg::flags = 0x100 | static_cast<uint32_t>(m_log_level);
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
stream debug(reg::string, 4);
|
stream debug(reg::string, level::debug);
|
||||||
stream info(reg::string, 3);
|
stream info(reg::string, level::info);
|
||||||
stream warn(reg::string, 2);
|
stream warn(reg::string, level::warn);
|
||||||
stream error(reg::string, 1);
|
stream error(reg::string, level::error);
|
||||||
|
|
||||||
} // namespace log
|
} // namespace log
|
||||||
|
|
||||||
|
|||||||
11
src/log.cpp
11
src/log.cpp
@ -1,6 +1,5 @@
|
|||||||
#include "mtl/log.hpp"
|
#include "mtl/log.hpp"
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
namespace mtl {
|
namespace mtl {
|
||||||
@ -9,7 +8,7 @@ namespace log {
|
|||||||
|
|
||||||
static string<512> buffer;
|
static string<512> buffer;
|
||||||
|
|
||||||
stream::stream(istring& buf, uint32_t log_level)
|
stream::stream(istring& buf, level log_level)
|
||||||
: basic_string_stream(buf), m_log_level(log_level) { }
|
: basic_string_stream(buf), m_log_level(log_level) { }
|
||||||
stream::~stream() { }
|
stream::~stream() { }
|
||||||
|
|
||||||
@ -18,10 +17,10 @@ void stream::flush() {
|
|||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
stream debug(buffer, 4);
|
stream debug(buffer, level::debug);
|
||||||
stream info(buffer, 3);
|
stream info(buffer, level::info);
|
||||||
stream warn(buffer, 2);
|
stream warn(buffer, level::warn);
|
||||||
stream error(buffer, 1);
|
stream error(buffer, level::error);
|
||||||
|
|
||||||
} // namespace log
|
} // namespace log
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user