summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2024-04-09 11:23:34 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2024-04-10 16:18:07 +0200
commitc1bbcdb5cb3ff24163bf1105856dbe614684ee1f (patch)
tree106faacb10708dfdfbc34243c43ec39c1a2195ea
parenta0cae2fa7b9bbf6d7fbe8575699bad8c41f9e84c (diff)
downloadjustbuild-c1bbcdb5cb3ff24163bf1105856dbe614684ee1f.tar.gz
Add command-line option to restrict log limit on stderr
-rw-r--r--share/man/just.1.md7
-rw-r--r--src/buildtool/common/cli.hpp11
-rw-r--r--src/buildtool/main/main.cpp3
3 files changed, 20 insertions, 1 deletions
diff --git a/share/man/just.1.md b/share/man/just.1.md
index 812cd33f..156a6cb4 100644
--- a/share/man/just.1.md
+++ b/share/man/just.1.md
@@ -440,6 +440,13 @@ Log limit (higher is more verbose) in interval \[0,6\] (Default: 3).
Supported by:
add-to-cas|analyse|build|describe|install|install-cas|rebuild|traverse|gc|execute.
+**`--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.
+Supported by:
+add-to-cas|analyse|build|describe|install|install-cas|rebuild|traverse|gc|execute.
+
**`--plain-log`**
Do not use ANSI escape sequences to highlight messages.
Supported by:
diff --git a/src/buildtool/common/cli.hpp b/src/buildtool/common/cli.hpp
index cfe2263a..cf348bff 100644
--- a/src/buildtool/common/cli.hpp
+++ b/src/buildtool/common/cli.hpp
@@ -19,8 +19,10 @@
#include <cstddef>
#include <cstdlib>
#include <filesystem>
+#include <optional>
#include <string>
#include <thread>
+#include <type_traits>
#include <vector>
#include "CLI/CLI.hpp"
@@ -47,6 +49,7 @@ struct CommonArguments {
struct LogArguments {
std::vector<std::filesystem::path> log_files{};
LogLevel log_limit{kDefaultLogLevel};
+ std::optional<LogLevel> restrict_stderr_log_limit{};
bool plain_log{false};
bool log_append{false};
};
@@ -249,6 +252,14 @@ static inline auto SetupLogArguments(
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/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index 18beff58..21f08618 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -87,7 +87,8 @@ void SetupDefaultLogging() {
void SetupLogging(LogArguments const& clargs) {
LogConfig::SetLogLimit(clargs.log_limit);
- 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,