Commit 6796d246 authored by Ramon Nou's avatar Ramon Nou
Browse files

avoid shared default client log contention

parent 969da1cb
Loading
Loading
Loading
Loading
+30 −5
Original line number Diff line number Diff line
@@ -56,7 +56,10 @@
#include <thallium.hpp>

#include <cassert>
#include <algorithm>
#include <cctype>
#include <filesystem>
#include <string>
#include <utility>


@@ -119,12 +122,34 @@ PreloadContext::init_logging() {
    const std::string log_opts = gkfs::env::get_var(
            gkfs::env::LOG, gkfs::config::log::client_log_level);

    const std::string log_output = gkfs::env::get_var(
            gkfs::env::LOG_OUTPUT, gkfs::config::log::client_log_path);

    const auto log_output_env = gkfs::env::get_var(gkfs::env::LOG_OUTPUT);
    const auto log_per_process_env =
            gkfs::env::get_var(gkfs::env::LOG_PER_PROCESS);
    const bool implicit_per_process_logging =
            log_output_env.empty() && log_per_process_env.empty();
    const std::string log_output =
            implicit_per_process_logging
                    ? "/tmp/gkfs_client"
                    : (log_output_env.empty()
                               ? gkfs::config::log::client_log_path
                               : log_output_env);

    const auto normalized_log_per_process = [&]() {
        std::string value = log_per_process_env;
        std::transform(value.begin(), value.end(), value.begin(),
                       [](unsigned char c) {
                           return static_cast<char>(std::tolower(c));
                       });
        return value;
    }();
    const bool log_per_process =
            gkfs::env::get_var(gkfs::env::LOG_PER_PROCESS).empty() ? false
                                                                   : true;
            normalized_log_per_process == "1" ||
            normalized_log_per_process == "on" ||
            normalized_log_per_process == "true" ||
            normalized_log_per_process == "yes" ||
            // The default path is shared by all processes. Avoid that
            // contention unless the caller explicitly selected a log path.
            implicit_per_process_logging;

#ifdef GKFS_DEBUG_BUILD
    // atoi returns 0 if no int conversion can be performed, which works