Reorganize logging in memgraph_bolt.cpp

Summary:
Remove utils/stacktrace/log.hpp
The single function defined in log.hpp is used only in
memgraph_bolt.cpp. Therefore, the function has been moved and the file
removed.

Move utils/stacktrace/stacktrace.hpp one level up

Move some logging from memgraph_bolt to Server

Reviewers: buda, dtomicevic

Reviewed By: buda

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D465
This commit is contained in:
Teon Banek 2017-06-13 15:43:00 +02:00
parent c56eb4310e
commit 7de8fd4b1b
9 changed files with 21 additions and 29 deletions

View File

@ -55,21 +55,24 @@ class Server
}
void Start(size_t n) {
logger_.info("Starting {} workers", n);
workers_.reserve(n);
for (size_t i = 0; i < n; ++i) {
workers_.push_back(
std::make_shared<Worker<Session, OutputStream, Socket>>(
dbms_, query_engine_));
workers_.back()->Start(alive_);
}
logger_.info("Server is fully armed and operational");
logger_.info("Listening on {} at {}", socket_.endpoint().address(),
socket_.endpoint().port());
while (alive_) {
this->WaitAndProcessEvents();
}
}
void Shutdown() {
logger_.info("Shutting down...");
alive_.store(false);
for (auto &worker : workers_) worker->thread_.join();
@ -114,4 +117,5 @@ class Server
Event event_;
Logger logger_;
};
}
} // namespace communication

View File

@ -18,7 +18,7 @@
#include "utils/flag_validation.hpp"
#include "utils/signals/handler.hpp"
#include "utils/stacktrace/log.hpp"
#include "utils/stacktrace.hpp"
#include "utils/terminate_handler.hpp"
namespace fs = std::experimental::filesystem;
@ -39,11 +39,6 @@ DEFINE_VALIDATED_int32(num_workers,
std::max(std::thread::hardware_concurrency(), 1U),
"Number of workers", FLAG_IN_RANGE(1, INT32_MAX));
void throw_and_stacktace(std::string message) {
Stacktrace stacktrace;
logger.info(stacktrace.dump());
}
// Load flags in this order, the last one has the highest priority:
// 1) /etc/memgraph/config
// 2) ~/.memgraph/config
@ -85,6 +80,14 @@ void load_config(int &argc, char **&argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
}
void log_stacktrace(const std::string &title) {
Stacktrace stacktrace;
// TODO: Change this from 'info' to 'error', when default error logging is
// added.
logging::info(title);
logging::info(stacktrace.dump());
}
int main(int argc, char **argv) {
fs::current_path(fs::path(argv[0]).parent_path());
load_config(argc, argv);
@ -99,7 +102,7 @@ int main(int argc, char **argv) {
// Get logger.
logger = logging::log->logger("Main");
logger.info("{}", logging::log->type());
logger.debug("Using {} logger", logging::log->type());
// Unhandled exception handler init.
std::set_terminate(&terminate_handler);
@ -139,8 +142,6 @@ int main(int argc, char **argv) {
std::exit(EXIT_FAILURE);
}
logger.info("Listening on {} at {}", FLAGS_interface, FLAGS_port);
Dbms dbms;
QueryEngine<result_stream_t> query_engine;
@ -156,9 +157,7 @@ int main(int argc, char **argv) {
[&server]() { server.Shutdown(); });
// Start worker threads.
logger.info("Starting {} workers", FLAGS_num_workers);
server.Start(FLAGS_num_workers);
logger.info("Shutting down...");
return EXIT_SUCCESS;
}

View File

@ -7,7 +7,7 @@
#include <iostream>
#include <sstream>
#include "utils/stacktrace/stacktrace.hpp"
#include "utils/stacktrace.hpp"
/**
* if STACKTRACE_ASSERT_ON is defined the full stacktrace will be printed on

View File

@ -9,7 +9,7 @@
#include <fmt/format.h>
#include <fmt/ostream.h>
#include "utils/stacktrace/stacktrace.hpp"
#include "utils/stacktrace.hpp"
namespace utils {

View File

@ -1,10 +0,0 @@
#pragma once
#include "logging/default.hpp"
#include "utils/stacktrace/stacktrace.hpp"
void log_stacktrace(const std::string& title) {
Stacktrace stacktrace;
logging::info(title);
logging::info(stacktrace.dump());
}

View File

@ -1,7 +1,7 @@
#pragma once
#include "utils/auto_scope.hpp"
#include "utils/stacktrace/stacktrace.hpp"
#include "utils/stacktrace.hpp"
#include <execinfo.h>
#include <iostream>

View File

@ -5,7 +5,6 @@
#include "logging/default.cpp"
#include "utils/fswatcher.hpp"
#include "utils/signals/handler.hpp"
#include "utils/stacktrace/log.hpp"
#include "utils/terminate_handler.hpp"
using namespace std::chrono_literals;

View File

@ -5,7 +5,7 @@
#include <utility>
#include "utils/signals/handler.hpp"
#include "utils/stacktrace/stacktrace.hpp"
#include "utils/stacktrace.hpp"
TEST(SignalHandler, SegmentationFaultTest) {
SignalHandler::register_handler(Signal::SegmentationFault, []() {