[{"id":33303,"web_url":"https://patchwork.libcamera.org/comment/33303/","msgid":"<173884378088.1238111.8523796719109699186@ping.linuxembedded.co.uk>","date":"2025-02-06T12:09:40","subject":"Re: [PATCH v3] libcamera: log: Match whole category in\n\tLIBCAMERA_LOG_LEVELS","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-01-23 09:04:18)\n> A LIBCAMERA_LOG_LEVELS value of \"RkISP1:0\" also applies to RkISP1Ccm and\n> RkISP1Awb. This behavior is unexpected as it automatically enables all\n> algorithm log categories when the intent is only to increase the log\n> level of the upper category. Fix that replacing the manual matching code\n> with fnmatch. This has the side effect that more wildcards (\"?\" and\n> \"[...]\") are supported which is acceptable but won't be advertised.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n\nOr even this one too.\n\nIf only there was a way to keep a specific work topic all bundled\ntogether in a centralised way. :-(\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n> \n> Changes in v2:\n> - Replaced matching code with fnmatch instead of a manual fix\n> \n> Changes in v3:\n> - Collected tag\n> - Updated documentation to no longer restrict the wildcard to the end\n>   of the string\n> ---\n>  src/libcamera/base/log.cpp | 26 ++++++--------------------\n>  1 file changed, 6 insertions(+), 20 deletions(-)\n> \n> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp\n> index 3a656b8f099f..72e0db859943 100644\n> --- a/src/libcamera/base/log.cpp\n> +++ b/src/libcamera/base/log.cpp\n> @@ -8,6 +8,7 @@\n>  #include <libcamera/base/log.h>\n>  \n>  #include <array>\n> +#include <fnmatch.h>\n>  #include <fstream>\n>  #include <iostream>\n>  #include <list>\n> @@ -38,8 +39,8 @@\n>   * The levels are configurable through the LIBCAMERA_LOG_LEVELS environment\n>   * variable that contains a comma-separated list of 'category:level' pairs.\n>   *\n> - * The category names are strings and can include a wildcard ('*') character at\n> - * the end to match multiple categories.\n> + * The category names are strings and can include a wildcard ('*') character to\n> + * match multiple categories.\n>   *\n>   * The level are either numeric values, or strings containing the log level\n>   * name. The available log levels are DEBUG, INFO, WARN, ERROR and FATAL. Log\n> @@ -717,24 +718,9 @@ void Logger::registerCategory(LogCategory *category)\n>         categories_.push_back(category);\n>  \n>         const std::string &name = category->name();\n> -       for (const std::pair<std::string, LogSeverity> &level : levels_) {\n> -               bool match = true;\n> -\n> -               for (unsigned int i = 0; i < level.first.size(); ++i) {\n> -                       if (level.first[i] == '*')\n> -                               break;\n> -\n> -                       if (i >= name.size() ||\n> -                           name[i] != level.first[i]) {\n> -                               match = false;\n> -                               break;\n> -                       }\n> -               }\n> -\n> -               if (match) {\n> -                       category->setSeverity(level.second);\n> -                       break;\n> -               }\n> +       for (const auto &[pattern, severity] : levels_) {\n> +               if (fnmatch(pattern.c_str(), name.c_str(), FNM_NOESCAPE) == 0)\n> +                       category->setSeverity(severity);\n>         }\n>  }\n>  \n> -- \n> 2.43.0\n>","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 5E7FBC32EA\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  6 Feb 2025 12:09:45 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9D4AF685D5;\n\tThu,  6 Feb 2025 13:09:44 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 778966053F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  6 Feb 2025 13:09:43 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CC7BC1193;\n\tThu,  6 Feb 2025 13:08:29 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"glXUG84A\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1738843709;\n\tbh=nGnSlkPXraiSqtnB5qviHhPRNtOw2xNs33elgWPPS+8=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=glXUG84ACc8CH/Zt70edGoHUfqcX0faNYRNr4AZhN1f0Y+RftwfaYGWSFicptlgOr\n\t4RdF9opuSN/si7AZy4mz62RhAwqPKceGlnQ7rUkmk2gaQkd0/NkchpJ+d3czixDkeF\n\tdnvowwoVqrmhKkX9nz0oaRn3qNbbPgYKmPBzC/aE=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250123090421.33226-1-stefan.klug@ideasonboard.com>","References":"<20250123090421.33226-1-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v3] libcamera: log: Match whole category in\n\tLIBCAMERA_LOG_LEVELS","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Thu, 06 Feb 2025 12:09:40 +0000","Message-ID":"<173884378088.1238111.8523796719109699186@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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>"}}]