3939YOSYS_NAMESPACE_BEGIN
4040
4141std::vector<FILE*> log_files;
42- std::vector<std::ostream*> log_streams;
42+ std::vector<std::ostream*> log_streams, log_warning_streams ;
4343std::vector<std::string> log_scratchpads;
4444std::map<std::string, std::set<std::string>> log_hdump;
4545std::vector<std::regex> log_warn_regexes, log_nowarn_regexes, log_werror_regexes;
@@ -102,7 +102,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
102102}
103103#endif
104104
105- static void logv_string (std::string_view format, std::string str) {
105+ static void logv_string (std::string_view format, std::string str, LogSeverity severity = LogSeverity::LOG_INFO ) {
106106 size_t remove_leading = 0 ;
107107 while (format.size () > 1 && format[0 ] == ' \n ' ) {
108108 logv_string (" \n " , " \n " );
@@ -158,6 +158,10 @@ static void logv_string(std::string_view format, std::string str) {
158158
159159 for (auto f : log_streams)
160160 *f << time_str;
161+
162+ if (severity >= LogSeverity::LOG_WARNING)
163+ for (auto f : log_warning_streams)
164+ *f << time_str;
161165 }
162166
163167 for (auto f : log_files)
@@ -166,6 +170,12 @@ static void logv_string(std::string_view format, std::string str) {
166170 for (auto f : log_streams)
167171 *f << str;
168172
173+ if (severity >= LogSeverity::LOG_WARNING)
174+ for (auto f : log_warning_streams) {
175+ *f << str;
176+ f->flush ();
177+ }
178+
169179 RTLIL::Design *design = yosys_get_design ();
170180 if (design != nullptr )
171181 for (auto &scratchpad : log_scratchpads)
@@ -203,11 +213,11 @@ static void logv_string(std::string_view format, std::string str) {
203213 }
204214}
205215
206- void log_formatted_string (std::string_view format, std::string str)
216+ void log_formatted_string (std::string_view format, std::string str, LogSeverity severity )
207217{
208218 if (log_make_debug && !ys_debug (1 ))
209219 return ;
210- logv_string (format, std::move (str));
220+ logv_string (format, std::move (str), severity );
211221}
212222
213223void log_formatted_header (RTLIL::Design *design, std::string_view format, std::string str)
@@ -293,7 +303,7 @@ void log_formatted_warning(std::string_view prefix, std::string message)
293303 if (log_errfile != NULL && !log_quiet_warnings)
294304 log_files.push_back (log_errfile);
295305
296- log (" %s%s " , prefix, message);
306+ log_formatted_string (" %s" , stringf ( " %s%s " , prefix, message), LogSeverity::LOG_WARNING );
297307 log_flush ();
298308
299309 if (log_errfile != NULL && !log_quiet_warnings)
@@ -339,7 +349,7 @@ static void log_error_with_prefix(std::string_view prefix, std::string str)
339349 f = stderr;
340350
341351 log_last_error = std::move (str);
342- log (" %s%s " , prefix, log_last_error);
352+ log_formatted_string (" %s" , stringf ( " %s%s " , prefix, log_last_error), LogSeverity::LOG_ERROR );
343353 log_flush ();
344354
345355 log_make_debug = bak_log_make_debug;
@@ -420,7 +430,7 @@ void log_formatted_cmd_error(std::string str)
420430 pop_errfile = true ;
421431 }
422432
423- log (" ERROR: %s" , log_last_error);
433+ log_formatted_string (" ERROR: %s" , log_last_error, LogSeverity::LOG_ERROR );
424434 log_flush ();
425435
426436 if (pop_errfile)
0 commit comments