From patchwork Thu Jan 23 09:04:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22614 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 1F527C3200 for ; Thu, 23 Jan 2025 09:04:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AC0596855D; Thu, 23 Jan 2025 10:04:28 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nLHwYdyh"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D50436187B for ; Thu, 23 Jan 2025 10:04:26 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:c0a:33cd:b453:5d3f]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2E0233A4; Thu, 23 Jan 2025 10:03:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1737623003; bh=5BNIWa/4ZUlWWfw6gpxfPA4juooPuNG4l1IwcyY/k00=; h=From:To:Cc:Subject:Date:From; b=nLHwYdyhTjkDajcIFU5pEnORz8ZAo8jDFlestyyV8l955itUNjQhp9HAupbwJjaUZ VNhPvLAMalBCmuwhSyM6I2DA3SrwcMJnxolPNyNXNSaO0z0Lq8p6rdTxz1vunUCIAj ODHhm67VxUTpxrSshDuWyWKwGeTouMUNsvOyvoWs= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Laurent Pinchart Subject: [PATCH v3] libcamera: log: Match whole category in LIBCAMERA_LOG_LEVELS Date: Thu, 23 Jan 2025 10:04:18 +0100 Message-ID: <20250123090421.33226-1-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" A LIBCAMERA_LOG_LEVELS value of "RkISP1:0" also applies to RkISP1Ccm and RkISP1Awb. This behavior is unexpected as it automatically enables all algorithm log categories when the intent is only to increase the log level of the upper category. Fix that replacing the manual matching code with fnmatch. This has the side effect that more wildcards ("?" and "[...]") are supported which is acceptable but won't be advertised. Signed-off-by: Stefan Klug Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- Changes in v2: - Replaced matching code with fnmatch instead of a manual fix Changes in v3: - Collected tag - Updated documentation to no longer restrict the wildcard to the end of the string --- src/libcamera/base/log.cpp | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp index 3a656b8f099f..72e0db859943 100644 --- a/src/libcamera/base/log.cpp +++ b/src/libcamera/base/log.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -38,8 +39,8 @@ * The levels are configurable through the LIBCAMERA_LOG_LEVELS environment * variable that contains a comma-separated list of 'category:level' pairs. * - * The category names are strings and can include a wildcard ('*') character at - * the end to match multiple categories. + * The category names are strings and can include a wildcard ('*') character to + * match multiple categories. * * The level are either numeric values, or strings containing the log level * name. The available log levels are DEBUG, INFO, WARN, ERROR and FATAL. Log @@ -717,24 +718,9 @@ void Logger::registerCategory(LogCategory *category) categories_.push_back(category); const std::string &name = category->name(); - for (const std::pair &level : levels_) { - bool match = true; - - for (unsigned int i = 0; i < level.first.size(); ++i) { - if (level.first[i] == '*') - break; - - if (i >= name.size() || - name[i] != level.first[i]) { - match = false; - break; - } - } - - if (match) { - category->setSeverity(level.second); - break; - } + for (const auto &[pattern, severity] : levels_) { + if (fnmatch(pattern.c_str(), name.c_str(), FNM_NOESCAPE) == 0) + category->setSeverity(severity); } }