diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/other_tools/just_mr/cli.hpp | 10 | ||||
-rw-r--r-- | src/other_tools/just_mr/launch.cpp | 6 | ||||
-rw-r--r-- | src/other_tools/just_mr/main.cpp | 6 | ||||
-rw-r--r-- | src/other_tools/just_mr/rc.cpp | 20 |
4 files changed, 36 insertions, 6 deletions
diff --git a/src/other_tools/just_mr/cli.hpp b/src/other_tools/just_mr/cli.hpp index 04bda36a..d76eee69 100644 --- a/src/other_tools/just_mr/cli.hpp +++ b/src/other_tools/just_mr/cli.hpp @@ -20,6 +20,7 @@ #include <optional> #include <string> #include <thread> +#include <type_traits> #include <unordered_map> #include <vector> @@ -61,6 +62,7 @@ struct MultiRepoCommonArguments { struct MultiRepoLogArguments { std::vector<std::filesystem::path> log_files{}; std::optional<LogLevel> log_limit{}; + std::optional<LogLevel> restrict_stderr_log_limit{}; bool plain_log{false}; bool log_append{false}; }; @@ -276,6 +278,14 @@ static inline auto SetupMultiRepoLogArguments( static_cast<int>(kLastLogLevel), static_cast<int>(kDefaultLogLevel))) ->type_name("NUM"); + app->add_option_function<std::underlying_type_t<LogLevel>>( + "--restrict-stderr-log-limit", + [clargs](auto const& limit) { + clargs->restrict_stderr_log_limit = ToLogLevel(limit); + }, + "Restrict logging on console to the minimum of the specified " + "--log-limit and this value") + ->type_name("NUM"); app->add_flag("--plain-log", clargs->plain_log, "Do not use ANSI escape sequences to highlight messages."); diff --git a/src/other_tools/just_mr/launch.cpp b/src/other_tools/just_mr/launch.cpp index 12c9155c..1236d9f4 100644 --- a/src/other_tools/just_mr/launch.cpp +++ b/src/other_tools/just_mr/launch.cpp @@ -126,6 +126,12 @@ auto CallJust(std::optional<std::filesystem::path> const& config_file, std::to_string(static_cast<std::underlying_type<LogLevel>::type>( *log_args.log_limit))); } + if (log_args.restrict_stderr_log_limit) { + cmd.emplace_back("--restrict-stderr-log-limit"); + cmd.emplace_back( + std::to_string(static_cast<std::underlying_type<LogLevel>::type>( + *log_args.restrict_stderr_log_limit))); + } if (log_args.plain_log) { cmd.emplace_back("--plain-log"); } diff --git a/src/other_tools/just_mr/main.cpp b/src/other_tools/just_mr/main.cpp index e0504ea7..442d74f6 100644 --- a/src/other_tools/just_mr/main.cpp +++ b/src/other_tools/just_mr/main.cpp @@ -184,7 +184,8 @@ void SetupLogging(MultiRepoLogArguments const& clargs) { else { LogConfig::SetLogLimit(kDefaultLogLevel); } - LogConfig::SetSinks({LogSinkCmdLine::CreateFactory(not clargs.plain_log)}); + LogConfig::SetSinks({LogSinkCmdLine::CreateFactory( + not clargs.plain_log, clargs.restrict_stderr_log_limit)}); for (auto const& log_file : clargs.log_files) { LogConfig::AddSink(LogSinkFile::CreateFactory( log_file, @@ -217,6 +218,9 @@ auto main(int argc, char* argv[]) -> int { SetupLogging(arguments.log); auto config_file = ReadJustMRRC(&arguments); + // As the rc file can contain logging parameters, reset the logging + // configuration + SetupLogging(arguments.log); if (arguments.common.repository_config) { config_file = arguments.common.repository_config; } diff --git a/src/other_tools/just_mr/rc.cpp b/src/other_tools/just_mr/rc.cpp index 90d0f2ed..c5de5ad5 100644 --- a/src/other_tools/just_mr/rc.cpp +++ b/src/other_tools/just_mr/rc.cpp @@ -426,7 +426,21 @@ namespace { std::exit(kExitConfigError); } clargs->log.log_limit = ToLogLevel(limit->Number()); - LogConfig::SetLogLimit(*clargs->log.log_limit); + } + } + // Set restrict stderr log limit, if specified and not set on the command + // line + if (not clargs->log.restrict_stderr_log_limit) { + auto limit = rc_config["restrict stderr 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.restrict_stderr_log_limit = ToLogLevel(limit->Number()); } } // Add additional log sinks specified in the rc file. @@ -444,10 +458,6 @@ namespace { 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); } } |