mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-10-31 03:32:29 +00:00 
			
		
		
		
	Logging: Add log stream that only get sent warning+ logs.
This commit is contained in:
		
							parent
							
								
									ed4eb6d331
								
							
						
					
					
						commit
						8ce48ca81e
					
				
					 2 changed files with 25 additions and 10 deletions
				
			
		|  | @ -39,7 +39,7 @@ | |||
| YOSYS_NAMESPACE_BEGIN | ||||
| 
 | ||||
| std::vector<FILE*> log_files; | ||||
| std::vector<std::ostream*> log_streams; | ||||
| std::vector<std::ostream*> log_streams, log_warning_streams; | ||||
| std::vector<std::string> log_scratchpads; | ||||
| std::map<std::string, std::set<std::string>> log_hdump; | ||||
| 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) | |||
| } | ||||
| #endif | ||||
| 
 | ||||
| static void logv_string(std::string_view format, std::string str) { | ||||
| static void logv_string(std::string_view format, std::string str, LogSeverity severity = LogSeverity::LOG_INFO) { | ||||
| 	size_t remove_leading = 0; | ||||
| 	while (format.size() > 1 && format[0] == '\n') { | ||||
| 		logv_string("\n", "\n"); | ||||
|  | @ -156,6 +156,10 @@ static void logv_string(std::string_view format, std::string str) { | |||
| 
 | ||||
| 		for (auto f : log_streams) | ||||
| 			*f << time_str; | ||||
| 
 | ||||
| 		if (severity >= LogSeverity::LOG_WARNING) | ||||
| 			for (auto f : log_warning_streams) | ||||
| 				*f << time_str; | ||||
| 	} | ||||
| 
 | ||||
| 	for (auto f : log_files) | ||||
|  | @ -164,6 +168,12 @@ static void logv_string(std::string_view format, std::string str) { | |||
| 	for (auto f : log_streams) | ||||
| 		*f << str; | ||||
| 
 | ||||
| 	if (severity >= LogSeverity::LOG_WARNING) | ||||
| 		for (auto f : log_warning_streams) { | ||||
| 			*f << str; | ||||
| 			f->flush(); | ||||
| 		} | ||||
| 
 | ||||
| 	RTLIL::Design *design = yosys_get_design(); | ||||
| 	if (design != nullptr) | ||||
| 		for (auto &scratchpad : log_scratchpads) | ||||
|  | @ -201,11 +211,11 @@ static void logv_string(std::string_view format, std::string str) { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| void log_formatted_string(std::string_view format, std::string str) | ||||
| void log_formatted_string(std::string_view format, std::string str, LogSeverity severity) | ||||
| { | ||||
| 	if (log_make_debug && !ys_debug(1)) | ||||
| 		return; | ||||
| 	logv_string(format, std::move(str)); | ||||
| 	logv_string(format, std::move(str), severity); | ||||
| } | ||||
| 
 | ||||
| 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) | |||
| 			if (log_errfile != NULL && !log_quiet_warnings) | ||||
| 				log_files.push_back(log_errfile); | ||||
| 
 | ||||
| 			log("%s%s", prefix, message); | ||||
| 			log_formatted_string("%s", stringf("%s%s", prefix, message), LogSeverity::LOG_WARNING); | ||||
| 			log_flush(); | ||||
| 
 | ||||
| 			if (log_errfile != NULL && !log_quiet_warnings) | ||||
|  | @ -339,7 +349,7 @@ static void log_error_with_prefix(std::string_view prefix, std::string str) | |||
| 	} | ||||
| 
 | ||||
| 	log_last_error = std::move(str); | ||||
| 	log("%s%s", prefix, log_last_error); | ||||
| 	log_formatted_string("%s", stringf("%s%s", prefix, log_last_error), LogSeverity::LOG_ERROR); | ||||
| 	log_flush(); | ||||
| 
 | ||||
| 	log_make_debug = bak_log_make_debug; | ||||
|  | @ -425,7 +435,7 @@ void log_formatted_cmd_error(std::string str) | |||
| 			pop_errfile = true; | ||||
| 		} | ||||
| 
 | ||||
| 		log("ERROR: %s", log_last_error); | ||||
| 		log_formatted_string("ERROR: %s", log_last_error, LogSeverity::LOG_ERROR); | ||||
| 		log_flush(); | ||||
| 
 | ||||
| 		if (pop_errfile) | ||||
|  |  | |||
							
								
								
									
										11
									
								
								kernel/log.h
									
										
									
									
									
								
							
							
						
						
									
										11
									
								
								kernel/log.h
									
										
									
									
									
								
							|  | @ -94,8 +94,15 @@ YOSYS_NAMESPACE_BEGIN | |||
| 
 | ||||
| struct log_cmd_error_exception { }; | ||||
| 
 | ||||
| enum LogSeverity { | ||||
| 	LOG_INFO, | ||||
| 	LOG_WARNING, | ||||
| 	LOG_ERROR | ||||
| }; | ||||
| 
 | ||||
| extern std::vector<FILE*> log_files; | ||||
| extern std::vector<std::ostream*> log_streams; | ||||
| extern std::vector<std::ostream*> log_warning_streams; | ||||
| extern std::vector<std::string> log_scratchpads; | ||||
| extern std::map<std::string, std::set<std::string>> log_hdump; | ||||
| 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; } | |||
| #endif | ||||
| #  define log_debug(...) do { if (ys_debug(1)) log(__VA_ARGS__); } while (0) | ||||
| 
 | ||||
| void log_formatted_string(std::string_view format, std::string str); | ||||
| void log_formatted_string(std::string_view format, std::string str, LogSeverity severity = LogSeverity::LOG_INFO); | ||||
| template <typename... Args> | ||||
| inline void log(FmtString<TypeIdentity<Args>...> fmt, const Args &... args) | ||||
| { | ||||
| 	if (log_make_debug && !ys_debug(1)) | ||||
| 		return; | ||||
| 	log_formatted_string(fmt.format_string(), fmt.format(args...)); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue