From 9db59165fbc5fc682c10f32efc6e4d04fe86e083 Mon Sep 17 00:00:00 2001 From: Ivan Kuvaldin Date: Sat, 10 Apr 2021 13:26:44 +0300 Subject: [PATCH] Initialize default log manager to report config-file issues. Closes #868 irohad silently exits with 1 if config file does not exist Signed-off-by: kuvaldini Signed-off-by: Ivan Kuvaldin --- irohad/main/irohad.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/irohad/main/irohad.cpp b/irohad/main/irohad.cpp index cb047b1bc9b..d7a770f1dae 100644 --- a/irohad/main/irohad.cpp +++ b/irohad/main/irohad.cpp @@ -28,11 +28,11 @@ #include "main/iroha_conf_literals.hpp" #include "main/iroha_conf_loader.hpp" #include "main/raw_block_loader.hpp" +#include "maintenance/metrics.hpp" #include "network/impl/channel_factory.hpp" #include "util/status_notifier.hpp" #include "util/utility_service.hpp" #include "validators/field_validator.hpp" -#include "maintenance/metrics.hpp" #if defined(USE_LIBURSA) #include "cryptography/ed25519_ursa_impl/crypto_provider.hpp" @@ -108,8 +108,12 @@ DEFINE_string(verbosity, kLogSettingsFromConfigFile, "Log verbosity"); DEFINE_validator(verbosity, &validateVerbosity); /// Metrics. ToDo validator -DEFINE_string(metrics_addr, "127.0.0.1", "Prometeus HTTP server listen address"); -DEFINE_string(metrics_port, "", "Prometeus HTTP server listens port, disabled by default"); +DEFINE_string(metrics_addr, + "127.0.0.1", + "Prometeus HTTP server listen address"); +DEFINE_string(metrics_port, + "", + "Prometeus HTTP server listens port, disabled by default"); std::sig_atomic_t caught_signal = 0; std::promise exit_requested; @@ -207,8 +211,8 @@ int main(int argc, char *argv[]) { // Parsing command line arguments gflags::ParseCommandLineFlags(&argc, &argv, true); - logger::LoggerManagerTreePtr log_manager; - logger::LoggerPtr log; + logger::LoggerManagerTreePtr log_manager = getDefaultLogManager(); + logger::LoggerPtr log = log_manager->getChild("Init")->getLogger(); try { // If the global log level override was set in the command line arguments, @@ -220,13 +224,8 @@ int main(int argc, char *argv[]) { log = log_manager->getChild("Init")->getLogger(); } - // Reading iroha configuration file - std::optional maybe_log; - if (log) { - maybe_log = log; - } auto config_result = - parse_iroha_config(FLAGS_config, getCommonObjectsFactory(), maybe_log); + parse_iroha_config(FLAGS_config, getCommonObjectsFactory(), {log}); if (auto e = iroha::expected::resultToOptionalError(config_result)) { if (log) { log->error("Failed reading the configuration: {}", e.value()); @@ -235,7 +234,7 @@ int main(int argc, char *argv[]) { } auto config = std::move(config_result).assumeValue(); - if (not log_manager) { + if (FLAGS_verbosity == kLogSettingsFromConfigFile) { log_manager = config.logger_manager.value_or(getDefaultLogManager()); log = log_manager->getChild("Init")->getLogger(); } @@ -260,9 +259,9 @@ int main(int argc, char *argv[]) { log_manager); } - if(FLAGS_metrics_port.size()) { + if (FLAGS_metrics_port.size()) { maintenance_metrics_init(FLAGS_metrics_addr + ":" + FLAGS_metrics_port); - }else if(config.metrics_addr_port.size()){ + } else if (config.metrics_addr_port.size()) { maintenance_metrics_init(config.metrics_addr_port); }