From b4c65d9680601e628da00c4fbf4c89fdae5a8932 Mon Sep 17 00:00:00 2001 From: sale Date: Fri, 16 Dec 2016 14:49:20 +0000 Subject: [PATCH] Stacktrace dump method added Summary: Stacktrace dump method added Test Plan: manual Reviewers: buda Subscribers: buda Differential Revision: https://memgraph.phacility.com/D19 --- include/utils/stacktrace.hpp | 16 ++++++++++++++++ include/utils/terminate_handler.hpp | 9 +-------- src/memgraph_bolt.cpp | 6 +----- 3 files changed, 18 insertions(+), 13 deletions(-) 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 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); }