diff options
-rw-r--r-- | share/man/just-mrrc.5.org | 10 | ||||
-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 |
4 files changed, 60 insertions, 4 deletions
diff --git a/share/man/just-mrrc.5.org b/share/man/just-mrrc.5.org index 05166cd2..c6396f56 100644 --- a/share/man/just-mrrc.5.org +++ b/share/man/just-mrrc.5.org @@ -68,6 +68,14 @@ The just-mrrc is given by a JSON object. configuration file. If the key ~"local launcher"~ is absent, the default ~["env", "--"]~ is assumed. +- The value for the key ~"log limit"~, if given, sets the default + value for the log limit, that can be overridden by the command-line + options. + +- The value ~"log files"~, if given, has to be a list of location + objects, specifying additional log files, on top of those specified + on the command line. + - The value for the key ~"just args"~ is a JSON object. Its keys are ~just~ subcommands and its value is a JSON list of strings. For the corresponding subcommand, these strings are prefixed to the ~just~ argument vector, if @@ -87,6 +95,8 @@ An example just-mrrc file could look like the following: , "local build root": {"root": "home", "path": ".cache/just"} , "checkout locations": {"root": "home", "path": ".just-local.json"} , "local launcher": ["env", "--"] +, "log limit": 4 +, "log files": [{"root": "home", "path": ".log/just/latest-invocation"}] , "distdirs": [{"root": "home", "path": ".distfiles"}] , "just": {"root": "system", "path": "usr/bin/just"} , "just args": 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"); |