From 0c797c7113742601fed9f068e46becfc55ea342e Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Fri, 17 Jan 2025 10:19:22 -0700 Subject: [PATCH] :fire: Remove `level` from logging message symbols Level is not a property of a message string, it's a property of a message instance. --- include/log/catalog/catalog.hpp | 4 +--- include/log/catalog/mipi_encoder.hpp | 5 ++--- tools/gen_str_catalog.py | 12 ++++-------- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/include/log/catalog/catalog.hpp b/include/log/catalog/catalog.hpp index 1472b7f4..05aaf3b4 100644 --- a/include/log/catalog/catalog.hpp +++ b/include/log/catalog/catalog.hpp @@ -1,14 +1,12 @@ #pragma once -#include - #include namespace sc { template struct args; template struct undefined; -template struct message {}; +template struct message {}; template struct module_string {}; } // namespace sc diff --git a/include/log/catalog/mipi_encoder.hpp b/include/log/catalog/mipi_encoder.hpp index 93e046ed..b29a3c4a 100644 --- a/include/log/catalog/mipi_encoder.hpp +++ b/include/log/catalog/mipi_encoder.hpp @@ -20,12 +20,11 @@ namespace logging::mipi { namespace detail { -template constexpr auto to_message() { +template constexpr auto to_message() { constexpr auto s = S::value; using char_t = typename std::remove_cv_t::value_type; return [&](std::integer_sequence) { return sc::message< - static_cast(L), sc::undefined, char_t, s[Is]...>>{}; }(std::make_integer_sequence{}); } @@ -114,7 +113,7 @@ template struct log_handler { ALWAYS_INLINE auto log_msg(Msg msg) -> void { msg.apply([&](S, Args... args) { constexpr auto L = stdx::to_underlying(get_level(Env{}).value); - using Message = decltype(detail::to_message()); + using Message = decltype(detail::to_message()); using Module = decltype(detail::to_module()); dispatch_message(catalog(), module(), diff --git a/tools/gen_str_catalog.py b/tools/gen_str_catalog.py index d014bf37..d1935e1b 100755 --- a/tools/gen_str_catalog.py +++ b/tools/gen_str_catalog.py @@ -32,25 +32,21 @@ def split_args(s: str) -> list[str]: string_re = re.compile( - r"sc::message<\(logging::level\)(\d+), sc::undefined, char, (.*)>\s*>" + r"sc::message, char, (.*)>\s*>" ) def extract_string_id(line_m): - levels = ["MAX", "FATAL", "ERROR", "WARN", "INFO", "USER1", "USER2", "TRACE"] - catalog_type = line_m.group(1) string_m = string_re.match(line_m.group(3)) - log_level = string_m.group(1) - arg_tuple = string_m.group(2) - string_tuple = string_m.group(3).replace("(char)", "") + arg_tuple = string_m.group(1) + string_tuple = string_m.group(2).replace("(char)", "") string_value = "".join((chr(int(c)) for c in re.split(r"\s*,\s*", string_tuple))) args = split_args(arg_tuple) return ( (catalog_type, arg_tuple), dict( - level=levels[int(log_level)], msg=string_value, type="flow" if string_value.startswith("flow.") else "msg", arg_types=args, @@ -85,7 +81,7 @@ def extract(line_num: int, line_m): def stable_msg_key(msg: dict): - return hash(msg["level"]) ^ hash(msg["msg"]) ^ hash("".join(msg["arg_types"])) + return hash(msg["msg"]) ^ hash("".join(msg["arg_types"])) def stable_module_key(module: str):