summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Klug <stefan.klug@ideasonboard.com>2025-01-23 10:04:18 +0100
committerStefan Klug <stefan.klug@ideasonboard.com>2025-02-06 15:25:52 +0100
commit9b1f609e5b754ce7adc0219a08b72714ae783e43 (patch)
tree6f53ea21cbb2d371f109708e884b59500111c44c /src
parent7e5d8118425304420abd4295844ffe15d858678b (diff)
libcamera: log: Match whole category in LIBCAMERA_LOG_LEVELSHEADmaster
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 <stefan.klug@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/base/log.cpp26
1 files 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 <libcamera/base/log.h>
#include <array>
+#include <fnmatch.h>
#include <fstream>
#include <iostream>
#include <list>
@@ -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<std::string, LogSeverity> &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);
}
}