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 <stefan.klug@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
parent
7e5d811842
commit
9b1f609e5b
1 changed files with 6 additions and 20 deletions
|
@ -8,6 +8,7 @@
|
||||||
#include <libcamera/base/log.h>
|
#include <libcamera/base/log.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <fnmatch.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
@ -38,8 +39,8 @@
|
||||||
* The levels are configurable through the LIBCAMERA_LOG_LEVELS environment
|
* The levels are configurable through the LIBCAMERA_LOG_LEVELS environment
|
||||||
* variable that contains a comma-separated list of 'category:level' pairs.
|
* variable that contains a comma-separated list of 'category:level' pairs.
|
||||||
*
|
*
|
||||||
* The category names are strings and can include a wildcard ('*') character at
|
* The category names are strings and can include a wildcard ('*') character to
|
||||||
* the end to match multiple categories.
|
* match multiple categories.
|
||||||
*
|
*
|
||||||
* The level are either numeric values, or strings containing the log level
|
* 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
|
* 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);
|
categories_.push_back(category);
|
||||||
|
|
||||||
const std::string &name = category->name();
|
const std::string &name = category->name();
|
||||||
for (const std::pair<std::string, LogSeverity> &level : levels_) {
|
for (const auto &[pattern, severity] : levels_) {
|
||||||
bool match = true;
|
if (fnmatch(pattern.c_str(), name.c_str(), FNM_NOESCAPE) == 0)
|
||||||
|
category->setSeverity(severity);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue