From 96fb0d24dfe6cd9bb25abcdf6451cfddad75d83e Mon Sep 17 00:00:00 2001 From: Felix Weiglhofer <weiglhofer@fias.uni-frankfurt.de> Date: Wed, 7 Jun 2023 13:59:32 +0000 Subject: [PATCH] cbmreco: Add flag to write logs to file. --- algo/base/Options.cxx | 4 +++- algo/base/Options.h | 2 ++ reco/app/cbmreco/main.cxx | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/algo/base/Options.cxx b/algo/base/Options.cxx index 99cb8fdccc..4ac19dc780 100644 --- a/algo/base/Options.cxx +++ b/algo/base/Options.cxx @@ -54,7 +54,9 @@ Options::Options(int argc, char** argv) "set log level (debug, info, warning, error, fatal)") ("monitor,m", po::value(&fMonitorUri)->value_name("<uri>")->implicit_value("file:cout"), "URI specifying monitor output (e.g. file:/tmp/monitor.txt, influx1:login:8086:cbmreco_status). Prints to cout when no argument is given. Monitor is disabled when flag is not set.") - ("num-ts,n", po::value(&fNumTimeslices)->default_value(-1)->value_name("<num>"), + ("log-file,f", po::value(&fLogFile)->value_name("<file>"), + "write log messages to file") + ("num-ts,n", po::value<int>(&fNumTimeslices)->default_value(-1)->value_name("<num>"), "Stop after <num> timeslices (-1 = all)") ("skip-ts,s", po::value(&fSkipTimeslices)->default_value(0)->value_name("<num>"), "Skip first <num> timeslices") diff --git a/algo/base/Options.h b/algo/base/Options.h index 61b480a4d2..7ee203f890 100644 --- a/algo/base/Options.h +++ b/algo/base/Options.h @@ -21,6 +21,7 @@ namespace cbm::algo fs::path ParamsDir() const { return fParamsDir; } const std::string& InputLocator() const { return fInputLocator; } severity_level LogLevel() const { return fLogLevel; } + fs::path LogFile() const { return fLogFile; } const std::string& Device() const { return fDevice; } const std::string& MonitorUri() const { return fMonitorUri; } bool CollectKernelTimes() const { return fCollectKernelTimes; } @@ -31,6 +32,7 @@ namespace cbm::algo std::string fParamsDir; // TODO: can we make this a std::path? std::string fInputLocator; severity_level fLogLevel; + std::string fLogFile; std::string fDevice; std::string fMonitorUri; bool fCollectKernelTimes = false; diff --git a/reco/app/cbmreco/main.cxx b/reco/app/cbmreco/main.cxx index 1aff967930..35ab5864da 100644 --- a/reco/app/cbmreco/main.cxx +++ b/reco/app/cbmreco/main.cxx @@ -19,6 +19,8 @@ int main(int argc, char** argv) logging::add_console(opts.LogLevel()); + if (!opts.LogFile().empty()) logging::add_file(opts.LogFile().string(), opts.LogLevel()); + // XPU xpu::settings settings; settings.profile = opts.CollectKernelTimes(); -- GitLab