From 68275e464d89412268e38c40034494001a8eeb50 Mon Sep 17 00:00:00 2001 From: Sergey Dolgov Date: Tue, 8 Oct 2024 01:08:57 -0700 Subject: [PATCH] pln: env variable RS_PLN_LOGFILE for non-default logfile name --- planning/src/RS/rsOpts.cpp | 37 +++++++++++++++++++---------------- planning/src/main.cpp | 2 +- planning/src/util/pln_log.cpp | 13 ++++++++++++ 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/planning/src/RS/rsOpts.cpp b/planning/src/RS/rsOpts.cpp index 9dfc2824..e9868b7e 100644 --- a/planning/src/RS/rsOpts.cpp +++ b/planning/src/RS/rsOpts.cpp @@ -115,36 +115,36 @@ void rsOpts::print(CStr label) const noexcept { cout << label; else cout << endl; - printf(" argc_ = %i\n", argc_); + ::printf(" argc_ = %i\n", argc_); if (argv_) { - for (int i = 1; i < argc_; i++) printf(" argv[%i] = %s", i, argv_[i]); + for (int i = 1; i < argc_; i++) ::printf(" argv[%i] = %s", i, argv_[i]); } else { lputs("\n\t !!! no argv_"); } lputs(); bool exi = input_file_exists(deviceXML_); - printf(" deviceXML_: %s exists:%i\n", nns(deviceXML_), exi); + ::printf(" deviceXML_: %s exists:%i\n", nns(deviceXML_), exi); exi = input_file_exists(csvFile_); - printf(" csvFile_: %s exists:%i\n", nns(csvFile_), exi); + ::printf(" csvFile_: %s exists:%i\n", nns(csvFile_), exi); - printf(" pcfFile_: %s\n", nns(pcfFile_)); - printf(" blifFile_: %s\n", nns(blifFile_)); - printf(" jsonFile_: %s\n", nns(jsonFile_)); - printf(" editsFile_: %s\n", nns(editsFile_)); - printf(" output_: %s\n", nns(output_)); - printf(" assignOrder_: %s\n", nns(assignOrder_)); + ::printf(" pcfFile_: %s\n", nns(pcfFile_)); + ::printf(" blifFile_: %s\n", nns(blifFile_)); + ::printf(" jsonFile_: %s\n", nns(jsonFile_)); + ::printf(" editsFile_: %s\n", nns(editsFile_)); + ::printf(" output_: %s\n", nns(output_)); + ::printf(" assignOrder_: %s\n", nns(assignOrder_)); - printf(" input_: %s\n", nns(input_)); + ::printf(" input_: %s\n", nns(input_)); - printf(" test_id_ = %i\n", test_id_); - printf(" trace_ = %i traceIndex_ = %i\n", trace_, traceIndex_); + ::printf(" test_id_ = %i\n", test_id_); + ::printf(" trace_ = %i traceIndex_ = %i\n", trace_, traceIndex_); cout << " trace_specified: " << std::boolalpha << trace_specified() << '\n'; cout << " unit_specified: " << std::boolalpha << unit_specified() << endl; - printf(" help_:%i check_:%i\n", help_, check_); - printf(" ver:%i det_ver_:%i\n", version_, det_ver_); + ::printf(" help_:%i check_:%i\n", help_, check_); + ::printf(" ver:%i det_ver_:%i\n", version_, det_ver_); lputs(); #endif // RSBE_UNIT_TEST_ON @@ -168,10 +168,13 @@ void rsOpts::printHelp() const noexcept { CStr hlp = tab1[i+1]; if (!hlp) break; - printf("%30s : %s\n", opt, hlp); + ::printf("%30s : %s\n", opt, hlp); } - flush_out(true); + cout << endl; + ::printf("Logfile can be specified by env variable RS_PLN_LOGFILE\n"); + ::printf("Default logfile is 'rs_planner.log'\n"); + cout << endl; } static char* make_file_name(CStr arg) noexcept { diff --git a/planning/src/main.cpp b/planning/src/main.cpp index aa975907..902fb0e3 100644 --- a/planning/src/main.cpp +++ b/planning/src/main.cpp @@ -1,4 +1,4 @@ -static const char* _pln_VERSION_STR = "pln0349"; +static const char* _pln_VERSION_STR = "pln0350"; #include "RS/rsEnv.h" #include "util/pln_log.h" diff --git a/planning/src/util/pln_log.cpp b/planning/src/util/pln_log.cpp index 7990c6ab..82e32fbd 100644 --- a/planning/src/util/pln_log.cpp +++ b/planning/src/util/pln_log.cpp @@ -49,6 +49,19 @@ bool open_pln_logfile(CStr fn) noexcept { assert(fn and fn[0]); if (_plnLF.is_open()) return false; + + CStr env_fn = ::getenv("RS_PLN_LOGFILE"); + if (env_fn and env_fn[0]) { + if (fn and ::strcmp(fn, env_fn)) { + cout << endl; + ::printf("PLN: using logfile name '%s' from env variable %s\n", + env_fn, "RS_PLN_LOGFILE"); + cout << endl; cout.flush(); + fflush(stdout); + } + fn = env_fn; + } + if (!fn or !fn[0]) return false;