3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-08-10 16:11:12 +00:00

log: Propagate prefix

This commit is contained in:
Miodrag Milanovic 2026-08-08 08:51:18 +02:00
parent 8410615988
commit 8a3a3fb63b
2 changed files with 18 additions and 14 deletions

View file

@ -100,17 +100,19 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
}
#endif
static void logv_string(std::string_view format, std::string str, LogSeverity severity = LogSeverity::LOG_INFO) {
static void logv_string(std::string_view prefix, std::string_view format, std::string strin, LogSeverity severity) {
size_t remove_leading = 0;
while (format.size() > 1 && format[0] == '\n') {
logv_string("\n", "\n");
logv_string(prefix, "\n", "\n", severity);
format = format.substr(1);
++remove_leading;
}
if (remove_leading > 0) {
str = str.substr(remove_leading);
strin = strin.substr(remove_leading);
}
std::string str = stringf("%s%s",prefix,strin);
if (str.empty())
return;
@ -201,13 +203,13 @@ static void logv_string(std::string_view format, std::string str, LogSeverity se
}
}
void log_formatted_string(std::string_view format, std::string str, LogSeverity severity)
void log_formatted_string(std::string_view prefix, std::string_view format, std::string str, LogSeverity severity)
{
log_assert(!Multithreading::active());
if (log_make_debug && !ys_debug(1))
return;
logv_string(format, std::move(str), severity);
logv_string(prefix, format, std::move(str), severity);
}
void log_formatted_header(RTLIL::Design *design, std::string_view format, std::string str)
@ -230,8 +232,9 @@ void log_formatted_header(RTLIL::Design *design, std::string_view format, std::s
for (int c : header_count)
header_id += stringf("%s%d", header_id.empty() ? "" : ".", c);
log("%s. ", header_id);
log_formatted_string(format, std::move(str), LogSeverity::LOG_HEADER);
log_formatted_string({}, "%s. ", stringf("%s. ", header_id), LogSeverity::LOG_HEADER_ID);
log_formatted_string({}, format, std::move(str), LogSeverity::LOG_HEADER);
log_flush();
if (log_hdump_all)
@ -297,7 +300,7 @@ void log_formatted_warning(std::string_view prefix, std::string message)
if (log_errfile != NULL && !log_quiet_warnings)
log_files.push_back(log_errfile);
log_formatted_string("%s", stringf("%s%s", prefix, message), LogSeverity::LOG_WARNING);
log_formatted_string(prefix, "%s", message, LogSeverity::LOG_WARNING);
log_flush();
if (log_errfile != NULL && !log_quiet_warnings)
@ -327,7 +330,7 @@ void log_formatted_file_info(std::string_view filename, int lineno, std::string
void 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));
logv_string("", format, stringf(format, log_debug_suppressed),LogSeverity::LOG_INFO);
log_debug_suppressed = 0;
}
}
@ -352,7 +355,7 @@ static void log_error_with_prefix(std::string_view prefix, std::string str)
log_last_error = std::move(str);
std::string message(prefix);
message += log_last_error;
log_formatted_string("%s", stringf("%s%s", prefix, log_last_error), LogSeverity::LOG_ERROR);
log_formatted_string(prefix, "%s", log_last_error, LogSeverity::LOG_ERROR);
log_flush();
log_make_debug = bak_log_make_debug;
@ -429,7 +432,7 @@ void log_formatted_cmd_error(std::string str)
pop_errfile = true;
}
log_formatted_string("%s", stringf("ERROR: %s", log_last_error), LogSeverity::LOG_ERROR);
log_formatted_string("ERROR: ", "%s", log_last_error, LogSeverity::LOG_ERROR);
log_flush();
if (pop_errfile)

View file

@ -88,6 +88,7 @@ struct log_cmd_error_exception { };
enum LogSeverity {
LOG_DEBUG,
LOG_INFO,
LOG_HEADER_ID,
LOG_HEADER,
LOG_WARNING,
LOG_ERROR
@ -127,11 +128,11 @@ static inline bool ys_debug(int n = 0) { if (log_force_debug) return true; log_d
static inline bool ys_debug(int = 0) { return false; }
#endif
void log_formatted_string(std::string_view format, std::string str, LogSeverity severity);
void log_formatted_string(std::string_view prefix, std::string_view format, std::string str, LogSeverity severity);
template <typename... Args>
inline void log(FmtString<TypeIdentity<Args>...> fmt, const Args &... args)
{
log_formatted_string(fmt.format_string(), fmt.format(args...), LogSeverity::LOG_INFO);
log_formatted_string("", fmt.format_string(), fmt.format(args...), LogSeverity::LOG_INFO);
}
template <typename... Args>
@ -139,7 +140,7 @@ inline void log_debug(FmtString<TypeIdentity<Args>...> fmt, const Args &... args
{
if (!ys_debug(1))
return;
log_formatted_string(fmt.format_string(), fmt.format(args...), LogSeverity::LOG_DEBUG);
log_formatted_string("", fmt.format_string(), fmt.format(args...), LogSeverity::LOG_DEBUG);
}
void log_formatted_header(RTLIL::Design *design, std::string_view format, std::string str);