mirror of
https://github.com/YosysHQ/yosys
synced 2026-08-10 08:01:14 +00:00
log: add log_callback
This commit is contained in:
parent
8a3a3fb63b
commit
19ca61ac88
2 changed files with 19 additions and 14 deletions
|
|
@ -80,6 +80,20 @@ static void log_id_cache_clear()
|
|||
log_id_cache.clear();
|
||||
}
|
||||
|
||||
void log_default_callback(std::string_view time_str, std::string_view prefix, std::string_view msg, LogSeverity severity)
|
||||
{
|
||||
(void)severity;
|
||||
std::string str = stringf("%s%s%s",time_str,prefix,msg);
|
||||
for (auto f : log_files)
|
||||
fputs(str.c_str(), f);
|
||||
|
||||
for (auto f : log_streams)
|
||||
*f << str;
|
||||
}
|
||||
|
||||
void (*log_callback)(std::string_view time_str, std::string_view prefix, std::string_view msg, LogSeverity severity) = log_default_callback;
|
||||
|
||||
|
||||
#if defined(_WIN32) && !defined(__MINGW32__)
|
||||
// this will get time information and return it in timeval, simulating gettimeofday()
|
||||
int gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
|
|
@ -125,10 +139,9 @@ static void logv_string(std::string_view prefix, std::string_view format, std::s
|
|||
if (log_hasher)
|
||||
log_hasher->update(str);
|
||||
|
||||
std::string time_str;
|
||||
if (log_time)
|
||||
{
|
||||
std::string time_str;
|
||||
|
||||
if (next_print_log || initial_tv.tv_sec == 0) {
|
||||
next_print_log = false;
|
||||
struct timeval tv;
|
||||
|
|
@ -152,19 +165,8 @@ static void logv_string(std::string_view prefix, std::string_view format, std::s
|
|||
// is then in the first formatted argument
|
||||
if (format == "%s" && str.back() == '\n')
|
||||
next_print_log = true;
|
||||
|
||||
for (auto f : log_files)
|
||||
fputs(time_str.c_str(), f);
|
||||
|
||||
for (auto f : log_streams)
|
||||
*f << time_str;
|
||||
}
|
||||
|
||||
for (auto f : log_files)
|
||||
fputs(str.c_str(), f);
|
||||
|
||||
for (auto f : log_streams)
|
||||
*f << str;
|
||||
log_callback(time_str, prefix, strin, severity);
|
||||
|
||||
RTLIL::Design *design = yosys_get_design();
|
||||
if (design != nullptr)
|
||||
|
|
|
|||
|
|
@ -122,6 +122,9 @@ extern int log_debug_suppressed;
|
|||
void set_verific_logging(void (*cb)(int msg_type, const char *message_id, const char* file_path, unsigned int left_line, unsigned int left_col, unsigned int right_line, unsigned int right_col, const char *msg));
|
||||
extern void (*log_verific_callback)(int msg_type, const char *message_id, const char* file_path, unsigned int left_line, unsigned int left_col, unsigned int right_line, unsigned int right_col, const char *msg);
|
||||
|
||||
void log_default_callback(std::string_view time_str, std::string_view prefix, std::string_view msg, LogSeverity severity);
|
||||
extern void (*log_callback)(std::string_view time_str, std::string_view prefix, std::string_view msg, LogSeverity severity);
|
||||
|
||||
#ifndef NDEBUG
|
||||
static inline bool ys_debug(int n = 0) { if (log_force_debug) return true; log_debug_suppressed += n; return false; }
|
||||
#else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue