{"id":22716,"url":"https://patchwork.libcamera.org/api/1.1/patches/22716/?format=json","web_url":"https://patchwork.libcamera.org/patch/22716/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20250130195811.1230581-8-pobrn@protonmail.com>","date":"2025-01-30T19:58:52","name":"[RFC,v2,7/9] libcamera: base: log: Split `parseLogLevel[s]()`","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"0e5b95f9504b78521f9a085cee8f342537f3a7a8","submitter":{"id":133,"url":"https://patchwork.libcamera.org/api/1.1/people/133/?format=json","name":"Pőcze Barnabás","email":"pobrn@protonmail.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/22716/mbox/","series":[{"id":4982,"url":"https://patchwork.libcamera.org/api/1.1/series/4982/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4982","date":"2025-01-30T19:58:14","name":"libcamera: base: log: Misc. changes","version":2,"mbox":"https://patchwork.libcamera.org/series/4982/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/22716/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/22716/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 18DA2BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 30 Jan 2025 19:59:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C861468564;\n\tThu, 30 Jan 2025 20:58:59 +0100 (CET)","from mail-10629.protonmail.ch (mail-10629.protonmail.ch\n\t[79.135.106.29])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6AF2B6856F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Jan 2025 20:58:58 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=protonmail.com header.i=@protonmail.com\n\theader.b=\"Ajdm5gxc\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1738267137; x=1738526337;\n\tbh=sOcbDhjCFmdl5MxKIQQEFCEZ3nO9fdZCIVttUxbqR44=;\n\th=Date:To:From:Subject:Message-ID:In-Reply-To:References:\n\tFeedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID:\n\tMessage-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post;\n\tb=Ajdm5gxcxRDkEpGNr+Tb/RcmW/swWI7CJBZ36icITKthRdgBtq+jbhEgZsggwXZhI\n\t/+4hTGiK80TiBIqshMazDZ+z0zAWPV9O5NvAMKmSisKfeZji/1M6ZgQpdhwxlrCFo5\n\tI3WR1tmp9ViQr5NroipXrByU8XYkOUqHq0c4qj/bVEm21r1r4oz+1vsl4Vr9Zp7Cpj\n\tDkoGBghZ3b+extctcK+Imtdk6H3gnFcAjK238heZyjmBwxEciXg3AHg+Msa6lCuZbT\n\tLdGnHfXSy9wsdPpI+gyM/wKkoM9W5yzowY3+0YSgUuqpcdeWdVVxr2hV66rPRIG/HL\n\tfxcEpx4ix1XQw==","Date":"Thu, 30 Jan 2025 19:58:52 +0000","To":"libcamera-devel@lists.libcamera.org","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Subject":"[RFC PATCH v2 7/9] libcamera: base: log: Split `parseLogLevel[s]()`","Message-ID":"<20250130195811.1230581-8-pobrn@protonmail.com>","In-Reply-To":"<20250130195811.1230581-1-pobrn@protonmail.com>","References":"<20250130195811.1230581-1-pobrn@protonmail.com>","Feedback-ID":"20568564:user:proton","X-Pm-Message-ID":"84e67e1b18e4f8175b8574f38da31f60e38c132a","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"quoted-printable","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"These two functions do not need to be exposed in any\nway, nor do they need to be a member of the `Logger` class.\n\nSo move them into an anonymous namespace.\n\nSigned-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n---\n src/libcamera/base/log.cpp | 186 ++++++++++++++++++-------------------\n 1 file changed, 93 insertions(+), 93 deletions(-)","diff":"diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp\nindex 0dfdb0e9b..19fc5cc67 100644\n--- a/src/libcamera/base/log.cpp\n+++ b/src/libcamera/base/log.cpp\n@@ -65,7 +65,9 @@\n \n namespace libcamera {\n \n-static int log_severity_to_syslog(LogSeverity severity)\n+namespace {\n+\n+int log_severity_to_syslog(LogSeverity severity)\n {\n \tswitch (severity) {\n \tcase LogDebug:\n@@ -83,7 +85,7 @@ static int log_severity_to_syslog(LogSeverity severity)\n \t}\n }\n \n-static const char *log_severity_name(LogSeverity severity)\n+const char *log_severity_name(LogSeverity severity)\n {\n \tstatic const char *const names[] = {\n \t\t\"DEBUG\",\n@@ -99,6 +101,92 @@ static const char *log_severity_name(LogSeverity severity)\n \t\treturn \"UNKWN\";\n }\n \n+/**\n+ * \\brief Parse a log level string into a LogSeverity\n+ * \\param[in] level The log level string\n+ *\n+ * Log levels can be specified as an integer value in the range from LogDebug to\n+ * LogFatal, or as a string corresponding to the severity name in uppercase. Any\n+ * other value is invalid.\n+ *\n+ * \\return The log severity, or LogInvalid if the string is invalid\n+ */\n+LogSeverity parseLogLevel(std::string_view level)\n+{\n+\tstatic const char *const names[] = {\n+\t\t\"DEBUG\",\n+\t\t\"INFO\",\n+\t\t\"WARN\",\n+\t\t\"ERROR\",\n+\t\t\"FATAL\",\n+\t};\n+\n+\tunsigned int severity;\n+\n+\tif (std::isdigit(level[0])) {\n+\t\tauto [end, ec] = std::from_chars(level.data(), level.data() + level.size(), severity);\n+\t\tif (ec != std::errc() || *end != '\\0' || severity > LogFatal)\n+\t\t\tseverity = LogInvalid;\n+\t} else {\n+\t\tseverity = LogInvalid;\n+\t\tfor (unsigned int i = 0; i < std::size(names); ++i) {\n+\t\t\tif (names[i] == level) {\n+\t\t\t\tseverity = i;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\treturn static_cast<LogSeverity>(severity);\n+}\n+\n+/**\n+ * \\brief Parse the log levels from the environment\n+ *\n+ * The log levels are stored in the LIBCAMERA_LOG_LEVELS environment variable\n+ * as a list of \"category:level\" pairs, separated by commas (','). Parse the\n+ * variable and store the levels to configure all log categories.\n+ */\n+void parseLogLevels(const char *line, std::list<std::pair<std::string, LogSeverity>> &levels)\n+{\n+\tfor (const char *pair = line; *line != '\\0'; pair = line) {\n+\t\tconst char *comma = strchrnul(line, ',');\n+\t\tsize_t len = comma - pair;\n+\n+\t\t/* Skip over the comma. */\n+\t\tline = *comma == ',' ? comma + 1 : comma;\n+\n+\t\t/* Skip to the next pair if the pair is empty. */\n+\t\tif (!len)\n+\t\t\tcontinue;\n+\n+\t\tstd::string_view category;\n+\t\tstd::string_view level;\n+\n+\t\tconst char *colon = static_cast<const char *>(memchr(pair, ':', len));\n+\t\tif (!colon) {\n+\t\t\t/* 'x' is a shortcut for '*:x'. */\n+\t\t\tcategory = \"*\";\n+\t\t\tlevel = std::string_view(pair, len);\n+\t\t} else {\n+\t\t\tcategory = std::string_view(pair, colon - pair);\n+\t\t\tlevel = std::string_view(colon + 1, comma - colon - 1);\n+\t\t}\n+\n+\t\t/* Both the category and the level must be specified. */\n+\t\tif (category.empty() || level.empty())\n+\t\t\tcontinue;\n+\n+\t\tLogSeverity severity = parseLogLevel(level);\n+\t\tif (severity == LogInvalid)\n+\t\t\tcontinue;\n+\n+\t\tlevels.emplace_back(category, severity);\n+\t}\n+}\n+\n+} /* namespace */\n+\n /**\n  * \\brief Log output\n  *\n@@ -312,8 +400,6 @@ private:\n \tLogger();\n \n \tvoid parseLogFile();\n-\tvoid parseLogLevels();\n-\tstatic LogSeverity parseLogLevel(std::string_view level);\n \n \tfriend LogCategory;\n \tvoid registerCategory(LogCategory *category);\n@@ -592,7 +678,9 @@ Logger::Logger()\n \tlogSetStream(&std::cerr, color);\n \n \tparseLogFile();\n-\tparseLogLevels();\n+\n+\tif (const char *debug = utils::secure_getenv(\"LIBCAMERA_LOG_LEVELS\"))\n+\t\tparseLogLevels(debug, levels_);\n }\n \n /**\n@@ -618,94 +706,6 @@ void Logger::parseLogFile()\n \tlogSetFile(file, false);\n }\n \n-/**\n- * \\brief Parse the log levels from the environment\n- *\n- * The log levels are stored in the LIBCAMERA_LOG_LEVELS environment variable\n- * as a list of \"category:level\" pairs, separated by commas (','). Parse the\n- * variable and store the levels to configure all log categories.\n- */\n-void Logger::parseLogLevels()\n-{\n-\tconst char *debug = utils::secure_getenv(\"LIBCAMERA_LOG_LEVELS\");\n-\tif (!debug)\n-\t\treturn;\n-\n-\tfor (const char *pair = debug; *debug != '\\0'; pair = debug) {\n-\t\tconst char *comma = strchrnul(debug, ',');\n-\t\tsize_t len = comma - pair;\n-\n-\t\t/* Skip over the comma. */\n-\t\tdebug = *comma == ',' ? comma + 1 : comma;\n-\n-\t\t/* Skip to the next pair if the pair is empty. */\n-\t\tif (!len)\n-\t\t\tcontinue;\n-\n-\t\tstd::string_view category;\n-\t\tstd::string_view level;\n-\n-\t\tconst char *colon = static_cast<const char *>(memchr(pair, ':', len));\n-\t\tif (!colon) {\n-\t\t\t/* 'x' is a shortcut for '*:x'. */\n-\t\t\tcategory = \"*\";\n-\t\t\tlevel = std::string_view(pair, len);\n-\t\t} else {\n-\t\t\tcategory = std::string_view(pair, colon - pair);\n-\t\t\tlevel = std::string_view(colon + 1, comma - colon - 1);\n-\t\t}\n-\n-\t\t/* Both the category and the level must be specified. */\n-\t\tif (category.empty() || level.empty())\n-\t\t\tcontinue;\n-\n-\t\tLogSeverity severity = parseLogLevel(level);\n-\t\tif (severity == LogInvalid)\n-\t\t\tcontinue;\n-\n-\t\tlevels_.emplace_back(category, severity);\n-\t}\n-}\n-\n-/**\n- * \\brief Parse a log level string into a LogSeverity\n- * \\param[in] level The log level string\n- *\n- * Log levels can be specified as an integer value in the range from LogDebug to\n- * LogFatal, or as a string corresponding to the severity name in uppercase. Any\n- * other value is invalid.\n- *\n- * \\return The log severity, or LogInvalid if the string is invalid\n- */\n-LogSeverity Logger::parseLogLevel(std::string_view level)\n-{\n-\tstatic const char *const names[] = {\n-\t\t\"DEBUG\",\n-\t\t\"INFO\",\n-\t\t\"WARN\",\n-\t\t\"ERROR\",\n-\t\t\"FATAL\",\n-\t};\n-\n-\tunsigned int severity;\n-\n-\tif (std::isdigit(level[0])) {\n-\t\tauto [end, ec] = std::from_chars(level.data(), level.data() + level.size(), severity);\n-\t\tif (ec != std::errc() || *end != '\\0' || severity > LogFatal)\n-\t\t\tseverity = LogInvalid;\n-\t} else {\n-\t\tseverity = LogInvalid;\n-\t\tfor (unsigned int i = 0; i < std::size(names); ++i) {\n-\t\t\tif (names[i] == level) {\n-\t\t\t\tseverity = i;\n-\t\t\t\tbreak;\n-\t\t\t}\n-\t\t}\n-\t}\n-\n-\treturn static_cast<LogSeverity>(severity);\n-}\n-\n /**\n  * \\brief Register a log category with the logger\n  * \\param[in] category The log category\n","prefixes":["RFC","v2","7/9"]}