summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/other_tools/just_mr/cli.hpp34
-rw-r--r--src/other_tools/just_mr/main.cpp23
2 files changed, 52 insertions, 5 deletions
diff --git a/src/other_tools/just_mr/cli.hpp b/src/other_tools/just_mr/cli.hpp
index 869dbafd..2f1e2d92 100644
--- a/src/other_tools/just_mr/cli.hpp
+++ b/src/other_tools/just_mr/cli.hpp
@@ -45,6 +45,12 @@ struct MultiRepoCommonArguments {
std::size_t jobs{std::max(1U, std::thread::hardware_concurrency())};
};
+struct MultiRepoLogArguments {
+ std::vector<std::filesystem::path> log_files{};
+ LogLevel log_limit{kDefaultLogLevel};
+ bool plain_log{false};
+};
+
struct MultiRepoSetupArguments {
std::optional<std::string> sub_main{std::nullopt};
bool sub_all{false};
@@ -125,6 +131,34 @@ static inline void SetupMultiRepoCommonArguments(
->type_name("NUM");
}
+static inline auto SetupMultiRepoLogArguments(
+ gsl::not_null<CLI::App*> const& app,
+ gsl::not_null<MultiRepoLogArguments*> const& clargs) {
+ app->add_option_function<std::string>(
+ "-f,--log-file",
+ [clargs](auto const& log_file_) {
+ clargs->log_files.emplace_back(log_file_);
+ },
+ "Path to local log file.")
+ ->type_name("PATH")
+ ->trigger_on_parse(); // run callback on all instances while parsing,
+ // not after all parsing is done
+ app->add_option_function<std::underlying_type_t<LogLevel>>(
+ "--log-limit",
+ [clargs](auto const& limit) {
+ clargs->log_limit = ToLogLevel(limit);
+ },
+ fmt::format("Log limit (higher is more verbose) in interval [{},{}] "
+ "(Default: {}).",
+ static_cast<int>(kFirstLogLevel),
+ static_cast<int>(kLastLogLevel),
+ static_cast<int>(kDefaultLogLevel)))
+ ->type_name("NUM");
+ app->add_flag("--plain-log",
+ clargs->plain_log,
+ "Do not use ANSI escape sequences to highlight messages.");
+}
+
static inline void SetupMultiRepoSetupArguments(
gsl::not_null<CLI::App*> const& app,
gsl::not_null<MultiRepoSetupArguments*> const& clargs) {
diff --git a/src/other_tools/just_mr/main.cpp b/src/other_tools/just_mr/main.cpp
index 6e114a49..8c238f71 100644
--- a/src/other_tools/just_mr/main.cpp
+++ b/src/other_tools/just_mr/main.cpp
@@ -18,6 +18,7 @@
#include "src/buildtool/build_engine/expression/configuration.hpp"
#include "src/buildtool/logging/log_config.hpp"
#include "src/buildtool/logging/log_sink_cmdline.hpp"
+#include "src/buildtool/logging/log_sink_file.hpp"
#include "src/other_tools/just_mr/cli.hpp"
#include "src/other_tools/just_mr/exit_codes.hpp"
#include "src/other_tools/ops_maps/git_update_map.hpp"
@@ -39,6 +40,7 @@ enum class SubCommand {
struct CommandLineArguments {
SubCommand cmd{SubCommand::kUnknown};
MultiRepoCommonArguments common;
+ MultiRepoLogArguments log;
MultiRepoSetupArguments setup;
MultiRepoFetchArguments fetch;
MultiRepoUpdateArguments update;
@@ -55,6 +57,7 @@ void SetupCommonCommandArguments(
gsl::not_null<CLI::App*> const& app,
gsl::not_null<CommandLineArguments*> const& clargs) {
SetupMultiRepoCommonArguments(app, &clargs->common);
+ SetupMultiRepoLogArguments(app, &clargs->log);
}
/// \brief Setup arguments for subcommand "just-mr fetch".
@@ -80,11 +83,6 @@ void SetupSetupCommandArguments(
SetupMultiRepoSetupArguments(app, &clargs->setup);
}
-void SetupDefaultLogging() {
- LogConfig::SetLogLimit(kDefaultLogLevel);
- LogConfig::SetSinks({LogSinkCmdLine::CreateFactory()});
-}
-
[[nodiscard]] auto ParseCommandLineArguments(int argc, char const* const* argv)
-> CommandLineArguments {
CLI::App app("just-mr");
@@ -171,6 +169,20 @@ void SetupDefaultLogging() {
return clargs;
}
+void SetupDefaultLogging() {
+ LogConfig::SetLogLimit(kDefaultLogLevel);
+ LogConfig::SetSinks({LogSinkCmdLine::CreateFactory()});
+}
+
+void SetupLogging(MultiRepoLogArguments const& clargs) {
+ LogConfig::SetLogLimit(clargs.log_limit);
+ LogConfig::SetSinks({LogSinkCmdLine::CreateFactory(not clargs.plain_log)});
+ for (auto const& log_file : clargs.log_files) {
+ LogConfig::AddSink(
+ LogSinkFile::CreateFactory(log_file, LogSinkFile::Mode::Overwrite));
+ }
+}
+
[[nodiscard]] auto ReadLocation(
nlohmann::json const& location,
std::optional<std::filesystem::path> const& ws_root)
@@ -1110,6 +1122,7 @@ auto main(int argc, char* argv[]) -> int {
// get the user-defined arguments
auto arguments = ParseCommandLineArguments(argc, argv);
+ SetupLogging(arguments.log);
auto config_file = ReadJustMRRC(&arguments);
if (arguments.common.repository_config) {
config_file = arguments.common.repository_config;