From b65f3a987ea6a4369fd30f857f23d140a5c0dfc5 Mon Sep 17 00:00:00 2001 From: "xj.lin" Date: Tue, 10 Sep 2019 20:14:58 +0800 Subject: [PATCH] MS-311 1. error log remove compile address Former-commit-id: ab5aaf1309ae03b243347c6aaa0805ccb32b0c3d --- cpp/src/core/src/knowhere/common/exception.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cpp/src/core/src/knowhere/common/exception.cpp b/cpp/src/core/src/knowhere/common/exception.cpp index aec8c036..1697f149 100644 --- a/cpp/src/core/src/knowhere/common/exception.cpp +++ b/cpp/src/core/src/knowhere/common/exception.cpp @@ -14,11 +14,23 @@ namespace knowhere { KnowhereException::KnowhereException(const std::string &msg):msg(msg) {} KnowhereException::KnowhereException(const std::string &m, const char *funcName, const char *file, int line) { +#ifdef DEBUG int size = snprintf(nullptr, 0, "Error in %s at %s:%d: %s", funcName, file, line, m.c_str()); msg.resize(size + 1); snprintf(&msg[0], msg.size(), "Error in %s at %s:%d: %s", funcName, file, line, m.c_str()); +#else + std::string file_path(file); + auto const pos = file_path.find_last_of('/'); + auto filename = file_path.substr(pos+1).c_str(); + + int size = snprintf(nullptr, 0, "Error in %s at %s:%d: %s", + funcName, filename, line, m.c_str()); + msg.resize(size + 1); + snprintf(&msg[0], msg.size(), "Error in %s at %s:%d: %s", + funcName, filename, line, m.c_str()); +#endif } const char *KnowhereException::what() const noexcept { -- GitLab