Skip to content

Commit 8ce48ca

Browse files
committed
Logging: Add log stream that only get sent warning+ logs.
1 parent ed4eb6d commit 8ce48ca

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

kernel/log.cc

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
YOSYS_NAMESPACE_BEGIN
4040

4141
std::vector<FILE*> log_files;
42-
std::vector<std::ostream*> log_streams;
42+
std::vector<std::ostream*> log_streams, log_warning_streams;
4343
std::vector<std::string> log_scratchpads;
4444
std::map<std::string, std::set<std::string>> log_hdump;
4545
std::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

211221
void 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)

kernel/log.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,15 @@ YOSYS_NAMESPACE_BEGIN
9494

9595
struct log_cmd_error_exception { };
9696

97+
enum LogSeverity {
98+
LOG_INFO,
99+
LOG_WARNING,
100+
LOG_ERROR
101+
};
102+
97103
extern std::vector<FILE*> log_files;
98104
extern std::vector<std::ostream*> log_streams;
105+
extern std::vector<std::ostream*> log_warning_streams;
99106
extern std::vector<std::string> log_scratchpads;
100107
extern std::map<std::string, std::set<std::string>> log_hdump;
101108
extern std::vector<std::regex> log_warn_regexes, log_nowarn_regexes, log_werror_regexes;
@@ -132,12 +139,10 @@ static inline bool ys_debug(int = 0) { return false; }
132139
#endif
133140
# define log_debug(...) do { if (ys_debug(1)) log(__VA_ARGS__); } while (0)
134141

135-
void log_formatted_string(std::string_view format, std::string str);
142+
void log_formatted_string(std::string_view format, std::string str, LogSeverity severity = LogSeverity::LOG_INFO);
136143
template <typename... Args>
137144
inline void log(FmtString<TypeIdentity<Args>...> fmt, const Args &... args)
138145
{
139-
if (log_make_debug && !ys_debug(1))
140-
return;
141146
log_formatted_string(fmt.format_string(), fmt.format(args...));
142147
}
143148

0 commit comments

Comments
 (0)