diff --git a/cpp/src/core/src/knowhere/common/exception.cpp b/cpp/src/core/src/knowhere/common/exception.cpp index aec8c03650cca53778ef3b39a071beb9c3ebf36c..1697f14910961901a59a88133d538102919226da 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 {