From patchwork Wed Jan 22 10:12:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22611 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 66652C3200 for ; Wed, 22 Jan 2025 10:12:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 40A3768558; Wed, 22 Jan 2025 11:12:51 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="urarmmi2"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 91E536187C for ; Wed, 22 Jan 2025 11:12:49 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:98fa:5e38:1a0b:e8d9]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9FE51C16; Wed, 22 Jan 2025 11:11:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1737540706; bh=Nq6t9EvNGFlaukp6OUWEwtwSSKP2hlNyDsEuaPh5GvI=; h=From:To:Cc:Subject:Date:From; b=urarmmi22lAvhgzM75HT9zmOM7xsi571jopIoNhvVQoFA3LaE27s3PF51V1D57NAi KjGF3LzsYOx3p9XjXcbhZfFGEgAE+Z2SHslWmQZ3+Jd9wuhCeanPQ8PiS8I3qIdhIV cNWrItYzh2H212jeUWUihT+KqCM1QZ/RVbyNetuM= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v2] libcamera: log: Match whole category in LIBCAMERA_LOG_LEVELS Date: Wed, 22 Jan 2025 11:12:19 +0100 Message-ID: <20250122101242.96995-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 --- src/libcamera/base/log.cpp | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp index 3a656b8f099f..086103b328e6 100644 --- a/src/libcamera/base/log.cpp +++ b/src/libcamera/base/log.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -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); } }