From 9b1f609e5b754ce7adc0219a08b72714ae783e43 Mon Sep 17 00:00:00 2001 From: Stefan Klug Date: Thu, 23 Jan 2025 10:04:18 +0100 Subject: libcamera: log: Match whole category in LIBCAMERA_LOG_LEVELS 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 --- 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 3a656b8f..72e0db85 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); } } -- cgit v1.2.1