From ff7e15db88b2de27506392936e41f5a00872e4ab Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Mon, 20 Jun 2016 14:01:20 +0200 Subject: [PATCH] logger: Output INFO messages as default --- include/registry.hpp | 14 ++++++-------- include/services/logger.hpp | 2 +- src/eventloop.cpp | 11 ++++++++--- src/registry.cpp | 20 ++++++++++---------- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/include/registry.hpp b/include/registry.hpp index 81202f50..e7f4c5df 100644 --- a/include/registry.hpp +++ b/include/registry.hpp @@ -18,14 +18,12 @@ struct RegistryModuleEntry class Registry { - // Stopped and no loaded modules - const int STAGE_1 = 1; - // Modules loaded but waiting for initial broadcast - const int STAGE_2 = 2; - // Running - const int STAGE_3 = 3; - // Unloading modules - const int STAGE_4 = 4; + const int STAGE_1 = 1; // Stopped and no loaded modules + const int STAGE_2 = 2; // Modules loaded but waiting for initial broadcast + const int STAGE_3 = 3; // Running + const int STAGE_4 = 4; // Unloading modules + + std::shared_ptr logger; concurrency::Atomic stage; diff --git a/include/services/logger.hpp b/include/services/logger.hpp index 3e5e6cdb..4bbfa8f5 100644 --- a/include/services/logger.hpp +++ b/include/services/logger.hpp @@ -38,7 +38,7 @@ class Logger { std::mutex mtx; - int level = LogLevel::LEVEL_ERROR | LogLevel::LEVEL_WARNING; + int level = LogLevel::LEVEL_ERROR | LogLevel::LEVEL_WARNING | LogLevel::LEVEL_INFO; int fd = LOGGER_FD; public: diff --git a/src/eventloop.cpp b/src/eventloop.cpp index 44ed35f3..f35d0a8f 100644 --- a/src/eventloop.cpp +++ b/src/eventloop.cpp @@ -37,7 +37,7 @@ void EventLoop::start() if (this->state() == STATE_STARTED) return; - this->logger->info("Starting event loop..."); + this->logger->debug("Starting event loop..."); this->bar->load(); this->registry->load(); @@ -46,6 +46,8 @@ void EventLoop::start() this->t_write = std::thread(&EventLoop::loop_write, this); this->t_read = std::thread(&EventLoop::loop_read, this); + + this->logger->debug("Event loop started..."); } void EventLoop::stop() @@ -53,6 +55,8 @@ void EventLoop::stop() if (this->state() == STATE_STOPPED) return; + this->logger->debug("Stopping event loop..."); + this->state = STATE_STOPPED; // break the input read block - totally how it's meant to be done! @@ -62,7 +66,8 @@ void EventLoop::stop() } this->registry->unload(); - this->logger->info("Event loop stopped..."); + + this->logger->debug("Event loop stopped..."); } void EventLoop::wait() @@ -225,7 +230,7 @@ void EventLoop::write_stdout() void EventLoop::cleanup(int timeout_ms) { - log_info("Cleaning up..."); + this->logger->debug("Cleaning up..."); std::atomic t_read_joined(false); std::atomic t_write_joined(false); diff --git a/src/registry.cpp b/src/registry.cpp index 618efb1c..764d6924 100644 --- a/src/registry.cpp +++ b/src/registry.cpp @@ -10,9 +10,9 @@ std::shared_ptr &get_registry() return registry; } -Registry::Registry() +Registry::Registry() : logger(get_logger()) { - get_logger()->debug("Entering STAGE 1"); + this->logger->debug("Entering STAGE 1"); this->stage = STAGE_1; } @@ -22,7 +22,7 @@ bool Registry::ready() if (stage == STAGE_2) for (auto &&entry : this->modules) - if (!entry->warmedup) get_logger()->debug("Waiting for: "+ entry->module->name()); + if (!entry->warmedup) this->logger->debug("Waiting for: "+ entry->module->name()); return stage == STAGE_3; } @@ -38,11 +38,11 @@ void Registry::load() if (this->stage() != STAGE_1) return; - get_logger()->debug("Entering STAGE 2"); + this->logger->debug("Entering STAGE 2"); this->stage = STAGE_2; - get_logger()->debug("Loading modules"); + this->logger->debug("Loading modules"); for (auto &&entry : this->modules) { std::lock_guard wait_lck(this->wait_mtx); @@ -56,11 +56,11 @@ void Registry::unload() if (this->stage() != STAGE_3) return; - get_logger()->debug("Entering STAGE 4"); + this->logger->debug("Entering STAGE 4"); this->stage = STAGE_4; - get_logger()->debug("Unloading modules"); + this->logger->debug("Unloading modules"); // Release wait lock { @@ -95,8 +95,8 @@ bool Registry::wait() continue; } - get_logger()->info("Received initial broadcast from all modules"); - get_logger()->debug("Entering STAGE 3"); + this->logger->debug("Received initial broadcast from all modules"); + this->logger->debug("Entering STAGE 3"); this->stage = STAGE_3; break; @@ -136,7 +136,7 @@ void Registry::notify(const std::string& module_name) mod_entry->module->refresh(); } catch (Exception &e) { log_trace("Exception occurred in runner thread for: "+ module_name); - get_logger()->error(e.what()); + this->logger->error(e.what()); }