log: keep log_debug a macro

This commit is contained in:
Miodrag Milanovic
2026-08-31 08:25:47 +02:00
parent b3e25aea62
commit cdb5ff5f99
3 changed files with 22 additions and 21 deletions
+11 -11
View File
@@ -164,10 +164,10 @@ static void log_id_cache_clear()
log_id_cache.clear();
}
void LogManager::logv_string(std::string_view prefix, std::string_view format, std::string str_in, LogSeverity severity) {
void LogManager::logv_string(LogSeverity severity, std::string_view prefix, std::string_view format, std::string str_in) {
size_t remove_leading = 0;
while (format.size() > 1 && format[0] == '\n') {
logv_string(prefix, "\n", "\n", severity);
logv_string(severity, prefix, "\n", "\n");
format = format.substr(1);
++remove_leading;
}
@@ -230,13 +230,13 @@ void LogManager::logv_string(std::string_view prefix, std::string_view format, s
}
}
void LogManager::log_formatted_string(std::string_view prefix, std::string_view format, std::string str, LogSeverity severity)
void LogManager::log_formatted_string(LogSeverity severity, std::string_view prefix, std::string_view format, std::string str)
{
log_assert(!Multithreading::active());
if (log_make_debug && !is_debug(1))
return;
logv_string(prefix, format, std::move(str), severity);
logv_string(severity, prefix, format, std::move(str));
}
void LogManager::log_formatted_header(RTLIL::Design *design, std::string_view format, std::string str)
@@ -256,7 +256,7 @@ void LogManager::log_formatted_header(RTLIL::Design *design, std::string_view fo
for (int c : header_count)
header_id += stringf("%s%d", header_id.empty() ? "" : ".", c);
log_formatted_string(stringf("%s. ", header_id), format, std::move(str), LogSeverity::Header);
log_formatted_string(LogSeverity::Header, stringf("%s. ", header_id), format, std::move(str));
flush();
if (log_hdump_all)
@@ -312,12 +312,12 @@ void LogManager::log_formatted_warning(std::string_view prefix, std::string_view
if (log_warnings.count(message))
{
log_formatted_string(prefix, format, message, LogSeverity::Info);
log_formatted_string(LogSeverity::Info, prefix, format, message);
flush();
}
else
{
log_formatted_string(prefix, format, message, LogSeverity::Warning);
log_formatted_string(LogSeverity::Warning, prefix, format, message);
flush();
log_warnings.insert(message);
}
@@ -338,13 +338,13 @@ void LogManager::log_formatted_file_warning(std::string_view filename, int linen
void LogManager::log_formatted_file_info(std::string_view filename, int lineno, std::string_view format, std::string str)
{
std::string prefix = stringf("%s:%d: Info: ", filename, lineno);
log_formatted_string(prefix, format, std::move(str), LogSeverity::Info);
log_formatted_string(LogSeverity::Info, prefix, format, std::move(str));
}
void LogManager::log_suppressed() {
if (log_debug_suppressed && !log_make_debug) {
constexpr const char* format = "<suppressed ~%d debug messages>\n";
logv_string({}, format, stringf(format, log_debug_suppressed),LogSeverity::Info);
logv_string(LogSeverity::Info, {}, format, stringf(format, log_debug_suppressed));
log_debug_suppressed = 0;
}
}
@@ -356,7 +356,7 @@ void LogManager::log_error_with_prefix(std::string_view prefix, std::string_view
log_make_debug = 0;
log_suppressed();
log_formatted_string(prefix, format, message, LogSeverity::Error);
log_formatted_string(LogSeverity::Error, prefix, format, message);
flush();
log_make_debug = bak_log_make_debug;
@@ -433,7 +433,7 @@ void log_yosys_abort_message(std::string_view file, int line, std::string_view f
void LogManager::log_formatted_cmd_error(std::string_view format, std::string message)
{
if (log_cmd_error_throw) {
log_formatted_string("ERROR: ", format, message, LogSeverity::Error);
log_formatted_string(LogSeverity::Error, "ERROR: ", format, message);
flush();
throw log_cmd_error_exception();
+9 -8
View File
@@ -401,7 +401,7 @@ public:
void add_hdump(std::string name, std::string value) { log_hdump[name].insert(value); }
void log_formatted_string(std::string_view prefix, std::string_view format, std::string str, LogSeverity severity);
void log_formatted_string(LogSeverity severity, std::string_view prefix, std::string_view format, std::string str);
void log_formatted_header(RTLIL::Design *design, std::string_view format, std::string str);
void log_formatted_warning(std::string_view prefix, std::string_view format, std::string message);
void log_formatted_file_warning(std::string_view filename, int lineno, std::string_view format, std::string str);
@@ -429,7 +429,7 @@ public:
std::string finish_hasher();
private:
void logv_string(std::string_view prefix, std::string_view format, std::string str_in, LogSeverity severity);
void logv_string(LogSeverity severity, std::string_view prefix, std::string_view format, std::string str_in);
[[noreturn]] void log_error_with_prefix(std::string_view prefix, std::string_view format, std::string message);
std::vector<std::unique_ptr<LogSink>> log_sinks;
@@ -473,23 +473,24 @@ static inline bool ys_debug(int = 0) { return false; }
template <typename... Args>
inline void log(FmtString<TypeIdentity<Args>...> fmt, const Args &... args)
{
logger().log_formatted_string({}, fmt.format_string(), fmt.format(args...), LogSeverity::Info);
logger().log_formatted_string(LogSeverity::Info, {}, fmt.format_string(), fmt.format(args...));
}
template <typename... Args>
inline void log_comment(FmtString<TypeIdentity<Args>...> fmt, const Args &... args)
{
logger().log_formatted_string({}, fmt.format_string(), fmt.format(args...), LogSeverity::Comment);
logger().log_formatted_string(LogSeverity::Comment, {}, fmt.format_string(), fmt.format(args...));
}
template <typename... Args>
inline void log_debug(FmtString<TypeIdentity<Args>...> fmt, const Args &... args)
inline void log_formatted_string(LogSeverity severity, std::string_view prefix,
FmtString<TypeIdentity<Args>...> fmt, const Args &... args)
{
if (!ys_debug(1))
return;
logger().log_formatted_string({}, fmt.format_string(), fmt.format(args...), LogSeverity::Debug);
logger().log_formatted_string(severity, prefix, fmt.format_string(), fmt.format(args...));
}
#define log_debug(...) do { if (ys_debug(1)) YOSYS_NAMESPACE_PREFIX log_formatted_string(YOSYS_NAMESPACE_PREFIX LogSeverity::Debug, {}, __VA_ARGS__); } while (0)
template <typename... Args>
inline void log_header(RTLIL::Design *design, FmtString<TypeIdentity<Args>...> fmt, const Args &... args)
{
+2 -2
View File
@@ -73,7 +73,7 @@ void log(const char *format, ...)
va_start(ap, format);
std::string formatted = vstringf(format, ap);
va_end(ap);
logger().log_formatted_string({}, format, formatted, LogSeverity::Info);
logger().log_formatted_string(LogSeverity::Info, {}, format, formatted);
}
void log_compat(const char *format, ...)
@@ -82,7 +82,7 @@ void log_compat(const char *format, ...)
va_start(ap, format);
std::string formatted = vstringf(format, ap);
va_end(ap);
logger().log_formatted_string({}, format, formatted, LogSeverity::Info);
logger().log_formatted_string(LogSeverity::Info, {}, format, formatted);
}
YOSYS_NAMESPACE_END