Skip to content

Commit

Permalink
Initialize default log manager to report config-file issues.
Browse files Browse the repository at this point in the history
Closes #868 irohad silently exits with 1 if config file does not exist

Signed-off-by: kuvaldini <[email protected]>
  • Loading branch information
kuvadldini-soramitsu authored and LiraLemur committed May 4, 2021
1 parent f9580ab commit 10c2a32
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions irohad/main/irohad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<void> exit_requested;
Expand Down Expand Up @@ -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,
Expand All @@ -220,13 +224,8 @@ int main(int argc, char *argv[]) {
log = log_manager->getChild("Init")->getLogger();
}

// Reading iroha configuration file
std::optional<logger::LoggerPtr> 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());
Expand All @@ -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();
}
Expand All @@ -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);
}

Expand Down

0 comments on commit 10c2a32

Please sign in to comment.