From 982084515caefe5acbe5d96988e067171eaa86c3 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sun, 9 Aug 2026 10:20:42 +0200 Subject: [PATCH] log: make it so we can reuse default one --- kernel/log.cc | 46 ++++++++++++++++++++++++++-------------------- kernel/log.h | 4 ++-- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/kernel/log.cc b/kernel/log.cc index b42fa396c..50929cd13 100644 --- a/kernel/log.cc +++ b/kernel/log.cc @@ -83,8 +83,28 @@ static void log_id_cache_clear() log_id_cache.clear(); } -void log_colored_callback(std::string_view time_str, std::string_view prefix, std::string_view msg, LogSeverity severity) +void log_default_callback(std::string_view time_str, std::string_view prefix, std::string_view msg, LogSeverity severity, bool skip_std) { + (void)severity; + std::string str = stringf("%s%s%s",time_str,prefix,msg); + for (auto f : log_files) { + if (skip_std && (f==stderr || f==stdout)) + continue; + fputs(str.c_str(), f); + } + + for (auto f : log_streams) + *f << str; + + RTLIL::Design *design = yosys_get_design(); + if (design != nullptr) + for (auto &scratchpad : log_scratchpads) + design->scratchpad[scratchpad].append(str); +} + +void log_colored_callback(std::string_view time_str, std::string_view prefix, std::string_view msg, LogSeverity severity, bool skip_std) +{ + (void)skip_std; if (!time_str.empty()) fmt::print(fg(fmt::terminal_color::blue), "{}", time_str); @@ -112,21 +132,12 @@ void log_colored_callback(std::string_view time_str, std::string_view prefix, st default: fmt::print("{}{}", prefix, msg); break; - } + } + + log_default_callback(time_str, prefix, msg, severity, true); } -void log_default_callback(std::string_view time_str, std::string_view prefix, std::string_view msg, LogSeverity severity) -{ - (void)severity; - std::string str = stringf("%s%s%s",time_str,prefix,msg); - for (auto f : log_files) - fputs(str.c_str(), f); - - for (auto f : log_streams) - *f << str; -} - -void (*log_callback)(std::string_view time_str, std::string_view prefix, std::string_view msg, LogSeverity severity) = log_default_callback; +void (*log_callback)(std::string_view time_str, std::string_view prefix, std::string_view msg, LogSeverity severity, bool skip_std) = log_default_callback; #if defined(_WIN32) && !defined(__MINGW32__) @@ -201,12 +212,7 @@ static void logv_string(std::string_view prefix, std::string_view format, std::s if (format == "%s" && str.back() == '\n') next_print_log = true; } - log_callback(time_str, prefix, strin, severity); - - RTLIL::Design *design = yosys_get_design(); - if (design != nullptr) - for (auto &scratchpad : log_scratchpads) - design->scratchpad[scratchpad].append(str); + log_callback(time_str, prefix, strin, severity, false); static std::string linebuffer; static bool log_warn_regex_recusion_guard = false; diff --git a/kernel/log.h b/kernel/log.h index f657f0348..40bef3589 100644 --- a/kernel/log.h +++ b/kernel/log.h @@ -121,8 +121,8 @@ extern int log_debug_suppressed; void set_verific_logging(void (*cb)(int msg_type, const char *message_id, const char* file_path, unsigned int left_line, unsigned int left_col, unsigned int right_line, unsigned int right_col, const char *msg)); extern void (*log_verific_callback)(int msg_type, const char *message_id, const char* file_path, unsigned int left_line, unsigned int left_col, unsigned int right_line, unsigned int right_col, const char *msg); -void log_default_callback(std::string_view time_str, std::string_view prefix, std::string_view msg, LogSeverity severity); -extern void (*log_callback)(std::string_view time_str, std::string_view prefix, std::string_view msg, LogSeverity severity); +void log_default_callback(std::string_view time_str, std::string_view prefix, std::string_view msg, LogSeverity severity, bool skip_std); +extern void (*log_callback)(std::string_view time_str, std::string_view prefix, std::string_view msg, LogSeverity severity, bool skip_std); #ifndef NDEBUG static inline bool ys_debug(int n = 0) { if (log_force_debug) return true; log_debug_suppressed += n; return false; }