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;
@@ -100,7 +100,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
100100}
101101#endif
102102
103- static void logv_string (std::string_view format, std::string str) {
103+ static void logv_string (std::string_view format, std::string str, LogSeverity severity = LogSeverity::LOG_INFO ) {
104104 size_t remove_leading = 0 ;
105105 while (format.size () > 1 && format[0 ] == ' \n ' ) {
106106 logv_string (" \n " , " \n " );
@@ -156,6 +156,10 @@ static void logv_string(std::string_view format, std::string str) {
156156
157157 for (auto f : log_streams)
158158 *f << time_str;
159+
160+ if (severity >= LogSeverity::LOG_WARNING)
161+ for (auto f : log_warning_streams)
162+ *f << time_str;
159163 }
160164
161165 for (auto f : log_files)
@@ -164,6 +168,12 @@ static void logv_string(std::string_view format, std::string str) {
164168 for (auto f : log_streams)
165169 *f << str;
166170
171+ if (severity >= LogSeverity::LOG_WARNING)
172+ for (auto f : log_warning_streams) {
173+ *f << str;
174+ f->flush ();
175+ }
176+
167177 RTLIL::Design *design = yosys_get_design ();
168178 if (design != nullptr )
169179 for (auto &scratchpad : log_scratchpads)
@@ -201,11 +211,11 @@ static void logv_string(std::string_view format, std::string str) {
201211 }
202212}
203213
204- void log_formatted_string (std::string_view format, std::string str)
214+ void log_formatted_string (std::string_view format, std::string str, LogSeverity severity )
205215{
206216 if (log_make_debug && !ys_debug (1 ))
207217 return ;
208- logv_string (format, std::move (str));
218+ logv_string (format, std::move (str), severity );
209219}
210220
211221void log_formatted_header (RTLIL::Design *design, std::string_view format, std::string str)
@@ -291,7 +301,7 @@ void log_formatted_warning(std::string_view prefix, std::string message)
291301 if (log_errfile != NULL && !log_quiet_warnings)
292302 log_files.push_back (log_errfile);
293303
294- log (" %s%s " , prefix, message);
304+ log_formatted_string (" %s" , stringf ( " %s%s " , prefix, message), LogSeverity::LOG_WARNING );
295305 log_flush ();
296306
297307 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 }
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;
@@ -425,7 +435,7 @@ void log_formatted_cmd_error(std::string str)
425435 pop_errfile = true ;
426436 }
427437
428- log (" ERROR: %s" , log_last_error);
438+ log_formatted_string (" ERROR: %s" , log_last_error, LogSeverity::LOG_ERROR );
429439 log_flush ();
430440
431441 if (pop_errfile)
0 commit comments