Skip to content

Commit

Permalink
squash w/ startup/shutdown. Make validate config function use logger …
Browse files Browse the repository at this point in the history
…once initialized.
  • Loading branch information
korydraughn committed Nov 13, 2024
1 parent 80cc93d commit 993bb2f
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions server/main_server/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ namespace
pid_t g_pid_af = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
pid_t g_pid_ds = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)

// Indicates whether the logging system has been initialized. This is meant to give
// systems, which run before and after the logging system is ready, a way to determine
// when use of the logging system is safe.
bool g_logger_initialized = false;

auto print_usage() -> void;
auto print_version_info() -> void;
auto print_configuration_template() -> void;
Expand Down Expand Up @@ -409,8 +414,13 @@ Environment Variables:

// NOLINTNEXTLINE(bugprone-lambda-function-name)
const auto do_validate = [fn = __func__](const auto& _config, const std::string& _schema_file) {
const auto resolver = [](const jsoncons::uri& _uri) {
fmt::print(stderr, "uri = [{}], path = [{}]\n", _uri.string(), _uri.path());
const auto resolver = [fn](const jsoncons::uri& _uri) {
if (g_logger_initialized) {
log_server::debug("{}: uri = [{}], path = [{}]", fn, _uri.string(), _uri.path());
}
else {
fmt::print(stderr, "uri = [{}], path = [{}]\n", _uri.string(), _uri.path());
}

std::ifstream in{(irods::get_irods_home_directory() / _uri.path()).c_str()};
if (!in) {
Expand All @@ -420,7 +430,13 @@ Environment Variables:
return jsoncons::json::parse(in);
};

fmt::print(stderr, "{}: JSON schema file = [{}].\n", fn, _schema_file);
if (g_logger_initialized) {
log_server::debug("{}: JSON schema file = [{}]", fn, _schema_file);
}
else {
fmt::print(stderr, "{}: JSON schema file = [{}].\n", fn, _schema_file);
}

std::ifstream in{_schema_file};
if (!in) {
return false;
Expand All @@ -435,7 +451,14 @@ Environment Variables:
if (!json_result.empty()) {
std::ostringstream out;
out << pretty_print(json_result);
fmt::print(stderr, "{}: {}\n", fn, out.str());

if (g_logger_initialized) {
log_server::error("{}: {}", fn, out.str());
}
else {
fmt::print(stderr, "{}: {}\n", fn, out.str());
}

return false;
}

Expand All @@ -450,7 +473,13 @@ Environment Variables:
std::string env_file;
std::string session_file;
if (const auto err = irods::get_json_environment_file(env_file, session_file); !err.ok()) {
fmt::print(stderr, "{}: {}\n", __func__, err.status());
if (g_logger_initialized) {
log_server::error("{}: {}", __func__, err.status());
}
else {
fmt::print(stderr, "{}: {}\n", __func__, err.status());
}

return false;
}

Expand All @@ -465,7 +494,12 @@ Environment Variables:
}
}
catch (const std::exception& e) {
fmt::print(stderr, "{}: {}\n", __func__, e.what());
if (g_logger_initialized) {
log_server::error("{}: {}", __func__, e.what());
}
else {
fmt::print(stderr, "{}: {}\n", __func__, e.what());
}
}

return false;
Expand Down Expand Up @@ -604,7 +638,9 @@ Environment Variables:
log_server::set_level(log_ns::get_level_from_config(irods::KW_CFG_LOG_LEVEL_CATEGORY_SERVER));
log_ns::set_server_type("server");
log_ns::set_server_zone(irods::get_server_property<std::string>(irods::KW_CFG_ZONE_NAME));
log_ns::set_server_hostname(boost::asio::ip::host_name());
log_ns::set_server_hostname(irods::get_server_property<std::string>(irods::KW_CFG_HOST));

g_logger_initialized = true;
} // init_logger

auto check_catalog_schema_version() -> std::pair<bool, int>
Expand Down

0 comments on commit 993bb2f

Please sign in to comment.