summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2024-04-09 15:11:15 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2024-04-10 16:18:07 +0200
commit7ec3c01395304c47a8643610a4cfa7a9aa1f7b31 (patch)
tree929cd11d03f786549844284fdb9fda3d12b4df37
parentc1bbcdb5cb3ff24163bf1105856dbe614684ee1f (diff)
downloadjustbuild-7ec3c01395304c47a8643610a4cfa7a9aa1f7b31.tar.gz
Add just-mr command-line option to estrict log limit on stderr
-rw-r--r--share/man/just-mr.1.md5
-rw-r--r--share/man/just-mrrc.5.md7
-rw-r--r--src/other_tools/just_mr/cli.hpp10
-rw-r--r--src/other_tools/just_mr/launch.cpp6
-rw-r--r--src/other_tools/just_mr/main.cpp6
-rw-r--r--src/other_tools/just_mr/rc.cpp20
6 files changed, 47 insertions, 7 deletions
diff --git a/share/man/just-mr.1.md b/share/man/just-mr.1.md
index 7fa02076..c69227cf 100644
--- a/share/man/just-mr.1.md
+++ b/share/man/just-mr.1.md
@@ -118,6 +118,11 @@ output has been generated.
**`--log-limit`** *`NUM`*
Log limit (higher is more verbose) in interval \[0,6\] (Default: 3).
+**`--restrict-stderr-log-limit`** *`NUM`*
+Restrict logging on console to the minimum of the specified **`--log-limit`**
+and the value specified in this option. The default is to not additionally
+restrict the log level at the console.
+
**`--plain-log`**
Do not use ANSI escape sequences to highlight messages.
diff --git a/share/man/just-mrrc.5.md b/share/man/just-mrrc.5.md
index 39fbd435..c9e4a073 100644
--- a/share/man/just-mrrc.5.md
+++ b/share/man/just-mrrc.5.md
@@ -87,6 +87,10 @@ The just-mrrc is given by a JSON object.
value for the log limit, that can be overridden by the command-line
options.
+ - The value for the key *`"restrict stderr log limit"`*, if given,
+ sets the default value for the restriction of the log limit on
+ console; this value can be overridden by the command-line option.
+
- 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.
@@ -171,7 +175,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 limit": 5
+, "restrict stderr log limit": 4
, "log files": [{"root": "home", "path": ".log/just/latest-invocation"}]
, "distdirs": [{"root": "home", "path": ".distfiles"}]
, "just": {"root": "system", "path": "usr/bin/just"}
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);
}
}