[{"id":33138,"web_url":"https://patchwork.libcamera.org/comment/33138/","msgid":"<20250122122412.GC7077@pendragon.ideasonboard.com>","date":"2025-01-22T12:24:12","subject":"Re: [PATCH v2] libcamera: log: Match whole category in\n\tLIBCAMERA_LOG_LEVELS","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Stefan,\n\nThank you for the patch.\n\nOn Wed, Jan 22, 2025 at 11:12:19AM +0100, Stefan Klug wrote:\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> \n> ---\n> \n> Changes in v2:\n> - Replaced matching code with fnmatch instead of a manual fix\n> ---\n>  src/libcamera/base/log.cpp | 22 ++++------------------\n>  1 file changed, 4 insertions(+), 18 deletions(-)\n> \n> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp\n> index 3a656b8f099f..086103b328e6 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> @@ -717,24 +718,9 @@ void Logger::registerCategory(LogCategory *category)\n>  \tcategories_.push_back(category);\n>  \n>  \tconst std::string &name = category->name();\n> -\tfor (const std::pair<std::string, LogSeverity> &level : levels_) {\n> -\t\tbool match = true;\n> -\n> -\t\tfor (unsigned int i = 0; i < level.first.size(); ++i) {\n> -\t\t\tif (level.first[i] == '*')\n> -\t\t\t\tbreak;\n> -\n> -\t\t\tif (i >= name.size() ||\n> -\t\t\t    name[i] != level.first[i]) {\n> -\t\t\t\tmatch = false;\n> -\t\t\t\tbreak;\n> -\t\t\t}\n> -\t\t}\n> -\n> -\t\tif (match) {\n> -\t\t\tcategory->setSeverity(level.second);\n> -\t\t\tbreak;\n> -\t\t}\n> +\tfor (const auto &[pattern, severity] : levels_) {\n> +\t\tif (fnmatch(pattern.c_str(), name.c_str(), FNM_NOESCAPE) == 0)\n> +\t\t\tcategory->setSeverity(severity);\n>  \t}\n\nYou also need to update the comment at the beginning of the file to\nindicate the wildcard can be located anywhere. With that,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  }\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 AFC1EBD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 22 Jan 2025 12:24:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A33CF68556;\n\tWed, 22 Jan 2025 13:24:22 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0061368551\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 Jan 2025 13:24:20 +0100 (CET)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D245BC16;\n\tWed, 22 Jan 2025 13:23:17 +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=\"QHW05ZgS\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1737548598;\n\tbh=nN9OAPUIhqKAqFgCziezPdptc3wk28MRhNppMMDPTDY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=QHW05ZgSPjAzFcHRsHLWjJL8TzyzX354qKJePzo6E5jvuLBUknEwRaKeXfj0uewXy\n\t4COZS2i4wvH8fP9aWVT+vyjgYdeY55BWTWpfplptofrLDozJlPzKhQeGCb7V4KNwxa\n\tepk6c43zG7ULs3EuvTQ5oGmpfH7Hrs75bZY3DGU4=","Date":"Wed, 22 Jan 2025 14:24:12 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v2] libcamera: log: Match whole category in\n\tLIBCAMERA_LOG_LEVELS","Message-ID":"<20250122122412.GC7077@pendragon.ideasonboard.com>","References":"<20250122101242.96995-1-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20250122101242.96995-1-stefan.klug@ideasonboard.com>","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>"}},{"id":33302,"web_url":"https://patchwork.libcamera.org/comment/33302/","msgid":"<173884358791.1238111.15518724970200611908@ping.linuxembedded.co.uk>","date":"2025-02-06T12:06:27","subject":"Re: [PATCH v2] 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 Laurent Pinchart (2025-01-22 12:24:12)\n> Hi Stefan,\n> \n> Thank you for the patch.\n> \n> On Wed, Jan 22, 2025 at 11:12:19AM +0100, Stefan Klug wrote:\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> > \n> > ---\n> > \n> > Changes in v2:\n> > - Replaced matching code with fnmatch instead of a manual fix\n> > ---\n> >  src/libcamera/base/log.cpp | 22 ++++------------------\n> >  1 file changed, 4 insertions(+), 18 deletions(-)\n> > \n> > diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp\n> > index 3a656b8f099f..086103b328e6 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> > @@ -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> You also need to update the comment at the beginning of the file to\n> indicate the wildcard can be located anywhere. With that,\n> \n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> \n> >  }\n> >  \n> \n> -- \n> Regards,\n> \n> Laurent Pinchart","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 44B86C0F2A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  6 Feb 2025 12:06:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6FF70685D5;\n\tThu,  6 Feb 2025 13:06:33 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BD8D86053F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  6 Feb 2025 13:06:31 +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 1BA3E1193;\n\tThu,  6 Feb 2025 13:05:18 +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=\"BRqRBUwi\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1738843518;\n\tbh=qo5R0wetV6obTn1OixVtmP+H5mZzGmmfFGHDg/Z8/NM=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=BRqRBUwiLmWR8I9+ry3vcz/tmmoFpzYN4peBRml0rS/XrALNPS69WkNq6IQhylMGt\n\trYbEMz136jBOAJTFcENv8B02ZetWKhiIRjwEiIwQ3iv65H/KamYNjlUAsByczkW2lK\n\t+PjDuzykiOxXfS9K/UXR9HLEYSD4EddIa0XhnGDU=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250122122412.GC7077@pendragon.ideasonboard.com>","References":"<20250122101242.96995-1-stefan.klug@ideasonboard.com>\n\t<20250122122412.GC7077@pendragon.ideasonboard.com>","Subject":"Re: [PATCH v2] libcamera: log: Match whole category in\n\tLIBCAMERA_LOG_LEVELS","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tStefan Klug <stefan.klug@ideasonboard.com>","Date":"Thu, 06 Feb 2025 12:06:27 +0000","Message-ID":"<173884358791.1238111.15518724970200611908@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>"}}]