diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/other_tools/just_mr/TARGETS | 1 | ||||
-rw-r--r-- | src/other_tools/just_mr/cli.hpp | 2 | ||||
-rw-r--r-- | src/other_tools/just_mr/main.cpp | 51 |
3 files changed, 50 insertions, 4 deletions
diff --git a/src/other_tools/just_mr/TARGETS b/src/other_tools/just_mr/TARGETS index b2bf6cd2..299818d9 100644 --- a/src/other_tools/just_mr/TARGETS +++ b/src/other_tools/just_mr/TARGETS @@ -6,6 +6,7 @@ , "private-deps": [ ["src/buildtool/build_engine/expression", "expression"] , ["src/buildtool/logging", "logging"] + , ["src/buildtool/logging", "log_level"] , ["src/buildtool/main", "version"] , "cli" , "exit_codes" diff --git a/src/other_tools/just_mr/cli.hpp b/src/other_tools/just_mr/cli.hpp index 8b5604a6..72e6f8a4 100644 --- a/src/other_tools/just_mr/cli.hpp +++ b/src/other_tools/just_mr/cli.hpp @@ -47,7 +47,7 @@ struct MultiRepoCommonArguments { struct MultiRepoLogArguments { std::vector<std::filesystem::path> log_files{}; - LogLevel log_limit{kDefaultLogLevel}; + std::optional<LogLevel> log_limit{}; bool plain_log{false}; bool log_append{false}; }; diff --git a/src/other_tools/just_mr/main.cpp b/src/other_tools/just_mr/main.cpp index 0657c84c..bba90162 100644 --- a/src/other_tools/just_mr/main.cpp +++ b/src/other_tools/just_mr/main.cpp @@ -20,6 +20,7 @@ #include "src/buildtool/build_engine/expression/configuration.hpp" #include "src/buildtool/logging/log_config.hpp" +#include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/log_sink_cmdline.hpp" #include "src/buildtool/logging/log_sink_file.hpp" #include "src/buildtool/main/version.hpp" @@ -188,7 +189,12 @@ void SetupDefaultLogging() { } void SetupLogging(MultiRepoLogArguments const& clargs) { - LogConfig::SetLogLimit(clargs.log_limit); + if (clargs.log_limit) { + LogConfig::SetLogLimit(*clargs.log_limit); + } + else { + LogConfig::SetLogLimit(kDefaultLogLevel); + } LogConfig::SetSinks({LogSinkCmdLine::CreateFactory(not clargs.plain_log)}); for (auto const& log_file : clargs.log_files) { LogConfig::AddSink(LogSinkFile::CreateFactory( @@ -416,6 +422,44 @@ void SetupLogging(MultiRepoLogArguments const& clargs) { clargs->common.local_launcher = kDefaultLauncher; } } + // Set log limit, if specified and not set on the command line + if (not clargs->log.log_limit) { + auto limit = rc_config["log limit"]; + if (limit.IsNotNull()) { + if (not limit->IsNumber()) { + Logger::Log(LogLevel::Error, + "Configuration-file specified log-limit has to be " + "a number, but found {}", + limit->ToString()); + std::exit(kExitConfigError); + } + clargs->log.log_limit = ToLogLevel(limit->Number()); + LogConfig::SetLogLimit(*clargs->log.log_limit); + } + } + // Add additional log sinks specified in the rc file. + auto log_files = rc_config["log files"]; + if (log_files.IsNotNull()) { + if (not log_files->IsList()) { + Logger::Log(LogLevel::Error, + "Configuration-provided log files have to be a list of " + "location objects, but found {}", + log_files->ToString()); + std::exit(kExitConfigError); + } + for (auto const& log_file : log_files->List()) { + auto path = + ReadLocation(log_file->ToJson(), + clargs->common.just_mr_paths->workspace_root); + if (path) { + LogConfig::AddSink(LogSinkFile::CreateFactory( + path->first, + clargs->log.log_append ? LogSinkFile::Mode::Append + : LogSinkFile::Mode::Overwrite)); + clargs->log.log_files.emplace_back(path->first); + } + } + } // read config lookup order auto config_lookup_order = rc_config["config lookup order"]; if (config_lookup_order.IsNotNull()) { @@ -1239,11 +1283,12 @@ void DefaultReachableRepositories( cmd.emplace_back(log_file.string()); } } - if (arguments.log.log_limit != kDefaultLogLevel) { + if (arguments.log.log_limit and + *arguments.log.log_limit != kDefaultLogLevel) { cmd.emplace_back("--log-limit"); cmd.emplace_back( std::to_string(static_cast<std::underlying_type<LogLevel>::type>( - arguments.log.log_limit))); + *arguments.log.log_limit))); } if (arguments.log.plain_log) { cmd.emplace_back("--plain-log"); |