[PATCH] libcamera: log: Match whole category in LIBCAMERA_LOG_LEVELS
Barnabás Pőcze
pobrn at protonmail.com
Mon Jan 20 14:59:47 CET 2025
Hi
2025. január 20., hétfő 14:30 keltezéssel, Stefan Klug <stefan.klug at ideasonboard.com> írta:
> 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 by ensuring that the full name
> gets matched. The * wildcard is still supported, so RkISP1* matches
> RkISP1 and RkISP1Awb.
>
> Signed-off-by: Stefan Klug <stefan.klug at ideasonboard.com>
> ---
> src/libcamera/base/log.cpp | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp
> index 3a656b8f099f..36e57d6017ab 100644
> --- a/src/libcamera/base/log.cpp
> +++ b/src/libcamera/base/log.cpp
> @@ -718,11 +718,15 @@ void Logger::registerCategory(LogCategory *category)
>
> const std::string &name = category->name();
> for (const std::pair<std::string, LogSeverity> &level : levels_) {
> + unsigned int i;
> + bool wildcard = false;
> bool match = true;
>
> - for (unsigned int i = 0; i < level.first.size(); ++i) {
> - if (level.first[i] == '*')
> + for (i = 0; i < level.first.size(); ++i) {
> + if (level.first[i] == '*') {
> + wildcard = true;
> break;
> + }
>
> if (i >= name.size() ||
> name[i] != level.first[i]) {
> @@ -731,6 +735,10 @@ void Logger::registerCategory(LogCategory *category)
> }
> }
>
> + /* Ensure the full name got matched */
> + if (!(wildcard || i == name.size()))
> + continue;
> +
Would `fnmatch()` work? If so, then I think that would simplify the code while
allowing a greater set of wildcards.
Regards,
Barnabás Pőcze
> if (match) {
> category->setSeverity(level.second);
> break;
> --
> 2.43.0
>
>
More information about the libcamera-devel
mailing list