From bd7cdeba22b4988ac0070d0f883b2cee5d3e5f12 Mon Sep 17 00:00:00 2001 From: Robin Davies Date: Sat, 12 Oct 2024 22:09:05 -0400 Subject: [PATCH] Add -log-level flag to pipedald. --- src/main.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 8af84a4..42e127e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -111,6 +111,17 @@ static void EnableBacktrace() } #endif +static bool TryGetLogLevel(const std::string&strLogLevel,LogLevel*result) +{ + if (strLogLevel == "debug") {*result= LogLevel::Debug; return true;} + if (strLogLevel == "info") {*result= LogLevel::Info; return true;} + if (strLogLevel == "warning") {*result= LogLevel::Warning; return true;} + if (strLogLevel == "error") { *result= LogLevel::Error; return true;} + *result = LogLevel::Info; + return false; +} + + int main(int argc, char *argv[]) { @@ -127,12 +138,14 @@ int main(int argc, char *argv[]) bool error = false; bool systemd = false; bool testExtraDevice = false; + std::string logLevel; std::string portOption; CommandLineParser parser; parser.AddOption("-h", &help); parser.AddOption("--help", &help); parser.AddOption("-systemd", &systemd); + parser.AddOption("-log-level",&logLevel); parser.AddOption("-port", &portOption); parser.AddOption("-test-extra-device", &testExtraDevice); // advertise two different devices (for testing multi-device connect) @@ -167,6 +180,7 @@ int main(int argc, char *argv[]) << "Options:\n" << " -systemd: Log to systemd journals instead of to the console.\n" << " -port: Port to listen on e.g. 80, or 0.0.0.0:80\n" + << " -log-level: (debug|info|warning|error)" << "Example:\n" << " pipedald /etc/pipedal/config /etc/pipedal/react -port 80 \n" "\n" @@ -208,6 +222,18 @@ int main(int argc, char *argv[]) } Lv2Log::log_level(configuration.GetLogLevel()); + if (logLevel.length() != 0) + { + LogLevel lv2LogLevel; + if (TryGetLogLevel(logLevel,&lv2LogLevel)) + { + Lv2Log::log_level(lv2LogLevel); + + } else { + Lv2Log::error(SS("Invalid log level: " << logLevel)); + return EXIT_SUCCESS; // indicate to systemd that we don't want a restart. + } + } if (portOption.length() != 0) {