logger: make log_verific_callback simple

This commit is contained in:
Miodrag Milanovic
2026-09-22 13:15:32 +02:00
parent 59e5cbf41d
commit 6557982d0a
3 changed files with 14 additions and 24 deletions
+10 -20
View File
@@ -139,28 +139,18 @@ const char *get_message_type(msg_type_t msg_type)
void msg_func(msg_type_t msg_type, const char *message_id, linefile_type linefile, const char *msg, va_list args)
{
std::string id = message_id ? stringf("[%s] ",message_id) : "";
string message = stringf("%s%s\n", id, vstringf(msg, args));
auto src = !linefile ? LogSourceLocation{} : LogSourceLocation{LineFile::GetFileName(linefile),
#ifdef VERIFIC_LINEFILE_INCLUDES_COLUMNS
int(linefile->GetLeftLine()), int(linefile->GetLeftCol()), int(linefile->GetRightLine()), int(linefile->GetRightCol())};
#else
int(LineFile::GetLineNo(linefile))};
#endif
if (log_verific_callback) {
string message = linefile ? stringf("%s:%d: ", LineFile::GetFileName(linefile), LineFile::GetLineNo(linefile)) : "";
message += vstringf(msg, args);
string full_message = stringf("%s [%s] %s\n", get_message_type(msg_type), id, message);
#ifdef VERIFIC_LINEFILE_INCLUDES_COLUMNS
log_verific_callback(int(msg_type), message_id, LineFile::GetFileName(linefile),
linefile ? linefile->GetLeftLine() : 0, linefile ? linefile->GetLeftCol() : 0,
linefile ? linefile->GetRightLine() : 0, linefile ? linefile->GetRightCol() : 0, full_message.c_str());
#else
log_verific_callback(int(msg_type), message_id, LineFile::GetFileName(linefile),
linefile ? LineFile::GetLineNo(linefile) : 0, 0,
linefile ? LineFile::GetLineNo(linefile) : 0, 0, full_message.c_str());
#endif
log_verific_callback(int(msg_type), message_id, src, message.c_str());
} else {
auto src = !linefile ? LogSourceLocation{} : LogSourceLocation{LineFile::GetFileName(linefile),
#ifdef VERIFIC_LINEFILE_INCLUDES_COLUMNS
int(linefile->GetLeftLine()), int(linefile->GetLeftCol()), int(linefile->GetRightLine()), int(linefile->GetRightCol())};
#else
int(LineFile::GetLineNo(linefile))};
#endif
string message_prefix = stringf("%s: ",get_message_type(msg_type));
string message = stringf("%s%s\n", id, vstringf(msg, args));
if (msg_type == VERIFIC_ERROR || msg_type == VERIFIC_PROGRAM_ERROR) {
logger().formatted_nonfatal_error(src, message_prefix, "%s%s\n", message);
} else if (msg_type == VERIFIC_WARNING) {
@@ -173,7 +163,7 @@ void msg_func(msg_type_t msg_type, const char *message_id, linefile_type linefil
verific_error_msg = "Design elaboration failed; see full log for details";
}
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))
void set_verific_logging(void (*cb)(int msg_type, const char *message_id, LogSourceLocation src, const char *msg))
{
Message::SetConsoleOutput(0);
Message::RegisterCallBackMsg(msg_func);
+2 -2
View File
@@ -52,8 +52,8 @@ std::chrono::steady_clock::time_point LogManager::get_initial_time() const
return initial_time;
}
void (*log_error_atexit)() = NULL;
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) = NULL;
void (*log_error_atexit)() = nullptr;
void (*log_verific_callback)(int msg_type, const char *message_id, LogSourceLocation src, const char *msg) = nullptr;
// TODO: remove when log_id is removed
vector<char*> log_id_cache;
+2 -2
View File
@@ -471,8 +471,8 @@ LogManager &logger();
extern void (*log_error_atexit)();
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 set_verific_logging(void (*cb)(int msg_type, const char *message_id, LogSourceLocation src, const char *msg));
extern void (*log_verific_callback)(int msg_type, const char *message_id, LogSourceLocation src, const char *msg);
#ifndef NDEBUG
static inline bool ys_debug(int n = 0) { return logger().is_debug(n); }