[orbis-kernel] Logs: fix crash on char[N] format

Cleanup, remove duplicated const formatters
Allow filtering by log level
This commit is contained in:
DH 2023-07-07 02:03:30 +03:00
parent 6cb9809b64
commit 4caf726005
2 changed files with 15 additions and 13 deletions

View File

@ -26,26 +26,25 @@ template <typename T, typename = void> struct log_class_string {
static void format(std::string &out, const void *arg);
};
template <> struct log_class_string<const void *, void> {
template <> struct log_class_string<void *, void> {
static void format(std::string &out, const void *arg);
};
template <typename T>
struct log_class_string<T *, void> : log_class_string<const void *, void> {};
struct log_class_string<T *, void> : log_class_string<void *, void> {};
template <> struct log_class_string<const char *, void> {
template <> struct log_class_string<char *, void> {
static void format(std::string &out, const void *arg);
};
template <>
struct log_class_string<char *, void> : log_class_string<const char *> {};
template <std::size_t N> struct log_class_string<char[N]> {
static void format(std::string &out, const void *arg) {
out += reinterpret_cast<const char *>(arg);
}
};
template <>
struct log_class_string<const char8_t *, void>
: log_class_string<const char *> {};
template <>
struct log_class_string<char8_t *, void> : log_class_string<const char8_t *> {};
struct log_class_string<char8_t *, void> : log_class_string<char *> {};
template <typename... Args>
using log_args_t = const void *(&&)[sizeof...(Args) + 1];
@ -62,7 +61,7 @@ struct log_type_info {
template <typename... Args>
constexpr const log_type_info type_info_v[sizeof...(Args) + 1]{
log_type_info::make<std::decay_t<Args>>()...};
log_type_info::make<std::remove_cvref_t<Args>>()...};
void _orbis_log_print(LogLevel lvl, const char *msg, std::string_view names,
const log_type_info *sup, ...);

View File

@ -13,12 +13,12 @@ static void append_hex(std::string &out, std::uintmax_t value) {
}
namespace orbis::logs {
void log_class_string<const void *>::format(std::string &out, const void *arg) {
void log_class_string<void *>::format(std::string &out, const void *arg) {
const void *ptr = *reinterpret_cast<const void *const *>(arg);
append_hex(out, reinterpret_cast<std::uintptr_t>(ptr));
}
void log_class_string<const char *>::format(std::string &out, const void *arg) {
void log_class_string<char *>::format(std::string &out, const void *arg) {
out += *reinterpret_cast<const char *const *>(arg);
}
@ -137,6 +137,9 @@ void log_class_string<bool>::format(std::string &out, const void *arg) {
void _orbis_log_print(LogLevel lvl, const char *msg, std::string_view names,
const log_type_info *sup, ...) {
if (lvl > logs_level.load(std::memory_order::relaxed)) {
return;
}
/*constinit thread_local*/ std::string text;
/*constinit thread_local*/ std::vector<const void *> args;