diff --git a/CMakeLists.txt b/CMakeLists.txt index e9f1eff7e..4a65d5a60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -322,6 +322,13 @@ if (LOG_NO_ERROR) add_definitions(-DLOG_NO_ERROR) endif() # -- logging ------------------------------------------------------------------ +# -- logger ------------------------------------------------------------------- +option(SYNC_LOGGER "" OFF) +message(STATUS "SYNC LOGGER: ${SYNC_LOGGER}") +if (SYNC_LOGGER) + add_definitions(-DSYNC_LOGGER) +endif() +# -- logger ------------------------------------------------------------------- # -- assert ------------------------------------------------------------------- option(RUNTIME_ASSERT "Enable runtime assertions" ON) message(STATUS "RUNTIME_ASSERT: ${RUNTIME_ASSERT}") diff --git a/include/communication/bolt/v1/transport/chunked_encoder.hpp b/include/communication/bolt/v1/transport/chunked_encoder.hpp index ebe72f281..73037f291 100644 --- a/include/communication/bolt/v1/transport/chunked_encoder.hpp +++ b/include/communication/bolt/v1/transport/chunked_encoder.hpp @@ -23,7 +23,6 @@ public: ChunkedEncoder(Stream &stream) : logger(logging::log->logger("Chunked Encoder")), stream(stream) { - // logger = logging::log->logger("Chunked Encoder"); } static constexpr size_t chunk_size = N - 2; @@ -71,9 +70,6 @@ private: void end_chunk() { - // TODO: this call is unnecessary bacause the same method is called - // inside the flush method - // write_chunk_header(); flush(); } diff --git a/include/logging/log.hpp b/include/logging/log.hpp index b1da9c904..909764ef1 100644 --- a/include/logging/log.hpp +++ b/include/logging/log.hpp @@ -49,6 +49,8 @@ public: streams.emplace_back(std::forward(stream)); } + virtual std::string type() = 0; + protected: friend class Logger; diff --git a/include/logging/logger.hpp b/include/logging/logger.hpp index b904db24a..dc3d72df1 100644 --- a/include/logging/logger.hpp +++ b/include/logging/logger.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include diff --git a/include/logging/logs/async_log.hpp b/include/logging/logs/async_log.hpp index 33039cebc..1d8db0d35 100644 --- a/include/logging/logs/async_log.hpp +++ b/include/logging/logs/async_log.hpp @@ -12,6 +12,7 @@ public: protected: void emit(Record::uptr) override; + std::string type() override; private: lockfree::MpscQueue records; diff --git a/include/logging/logs/sync_log.hpp b/include/logging/logs/sync_log.hpp index aed0379a9..15a1d6a00 100644 --- a/include/logging/logs/sync_log.hpp +++ b/include/logging/logs/sync_log.hpp @@ -8,4 +8,5 @@ class SyncLog : public Log, Lockable { protected: void emit(Record::uptr) override; + std::string type() override; }; diff --git a/src/logging/logs/async_log.cpp b/src/logging/logs/async_log.cpp index b5b942811..df3d9c2d9 100644 --- a/src/logging/logs/async_log.cpp +++ b/src/logging/logs/async_log.cpp @@ -11,6 +11,11 @@ void AsyncLog::emit(Record::uptr record) records.push(std::move(record)); } +std::string AsyncLog::type() +{ + return "AsyncLog"; +} + void AsyncLog::work() { using namespace std::chrono_literals; diff --git a/src/logging/logs/sync_log.cpp b/src/logging/logs/sync_log.cpp index 1cd0cf5e0..7a43b8845 100644 --- a/src/logging/logs/sync_log.cpp +++ b/src/logging/logs/sync_log.cpp @@ -5,3 +5,8 @@ void SyncLog::emit(Record::uptr record) auto guard = this->acquire_unique(); dispatch(*record); } + +std::string SyncLog::type() +{ + return "SyncLog"; +} diff --git a/src/memgraph_bolt.cpp b/src/memgraph_bolt.cpp index f42bd4d7f..23f812b98 100644 --- a/src/memgraph_bolt.cpp +++ b/src/memgraph_bolt.cpp @@ -34,10 +34,17 @@ int main(void) // that are configured below std::set_terminate(&terminate_handler); + // logger init +#ifdef SYNC_LOGGER logging::init_sync(); - // logging::init_async(); +#else + logging::init_async(); +#endif logging::log->pipe(std::make_unique()); + + // get Main logger logger = logging::log->logger("Main"); + logger.info("{}", logging::log->type()); signal(SIGINT, sigint_handler); signal(SIGABRT, sigint_handler); @@ -64,7 +71,7 @@ int main(void) bolt::Server server(std::move(socket)); serverptr = &server; - constexpr size_t N = 1; + auto N = std::thread::hardware_concurrency(); logger.info("Starting {} workers", N); server.start(N);