diff --git a/include/utils/stacktrace.hpp b/include/utils/stacktrace.hpp index b5476eb16..b097a8000 100644 --- a/include/utils/stacktrace.hpp +++ b/include/utils/stacktrace.hpp @@ -58,6 +58,22 @@ public: return lines.size(); } + void dump(std::ostream& stream) { + std::string message; + for (int i = 0; i < size(); i++) { + message.append(fmt::format("at {} ({})\n", lines[i].function, + lines[i].location)); + } + stream << message; + } + + void dump(std::string& message) { + for (int i = 0; i < size(); i++) { + message.append(fmt::format("at {} ({}) \n", lines[i].function, + lines[i].location)); + } + } + private: std::vector<Line> lines; diff --git a/include/utils/terminate_handler.hpp b/include/utils/terminate_handler.hpp index 7ae21d5a1..467522e44 100644 --- a/include/utils/terminate_handler.hpp +++ b/include/utils/terminate_handler.hpp @@ -9,14 +9,7 @@ // TODO: log to local file or remote database void stacktrace(std::ostream& stream) noexcept { Stacktrace stacktrace; - - std::string message; - - for (int i = 0; i < stacktrace.size(); i++) { - message.append(fmt::format("\n at {} ({})", stacktrace[i].function, - stacktrace[i].location)); - } - stream << message << std::endl; + stacktrace.dump(stream); } // TODO: log to local file or remote database diff --git a/src/memgraph_bolt.cpp b/src/memgraph_bolt.cpp index 03fcb2e51..aaf9179d6 100644 --- a/src/memgraph_bolt.cpp +++ b/src/memgraph_bolt.cpp @@ -22,11 +22,7 @@ static constexpr const char* port = "7687"; void throw_and_stacktace(std::string message) { Stacktrace stacktrace; - - for (int i = 0; i < stacktrace.size(); i++) - message.append(fmt::format("\n at {} ({})", stacktrace[i].function, - stacktrace[i].location)); - + stacktrace.dump(message); logger.info(message); }