aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/logging/registry.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zencore/logging/registry.cpp')
-rw-r--r--src/zencore/logging/registry.cpp61
1 files changed, 57 insertions, 4 deletions
diff --git a/src/zencore/logging/registry.cpp b/src/zencore/logging/registry.cpp
index 3ed1fb0df..383a5d8ba 100644
--- a/src/zencore/logging/registry.cpp
+++ b/src/zencore/logging/registry.cpp
@@ -13,6 +13,44 @@
namespace zen::logging {
+bool
+MatchLoggerPattern(std::string_view Pattern, std::string_view Name)
+{
+ size_t Pi = 0;
+ size_t Ni = 0;
+ size_t StarPi = std::string_view::npos;
+ size_t StarNi = 0;
+
+ while (Ni < Name.size())
+ {
+ if (Pi < Pattern.size() && (Pattern[Pi] == Name[Ni] || Pattern[Pi] == '?'))
+ {
+ ++Pi;
+ ++Ni;
+ }
+ else if (Pi < Pattern.size() && Pattern[Pi] == '*')
+ {
+ StarPi = Pi++;
+ StarNi = Ni;
+ }
+ else if (StarPi != std::string_view::npos)
+ {
+ Pi = StarPi + 1;
+ Ni = ++StarNi;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ while (Pi < Pattern.size() && Pattern[Pi] == '*')
+ {
+ ++Pi;
+ }
+ return Pi == Pattern.size();
+}
+
struct Registry::Impl
{
Impl()
@@ -95,12 +133,27 @@ struct Registry::Impl
}
}
- for (auto& [LoggerName, Level] : Levels)
+ for (auto& [Pattern, Level] : Levels)
{
- auto It = m_Loggers.find(LoggerName);
- if (It != m_Loggers.end())
+ if (Pattern.find_first_of("*?") == std::string::npos)
{
- It->second->SetLevel(Level);
+ // Exact match — fast path via map lookup.
+ auto It = m_Loggers.find(Pattern);
+ if (It != m_Loggers.end())
+ {
+ It->second->SetLevel(Level);
+ }
+ }
+ else
+ {
+ // Wildcard pattern — iterate all loggers.
+ for (auto& [Name, CurLogger] : m_Loggers)
+ {
+ if (MatchLoggerPattern(Pattern, Name))
+ {
+ CurLogger->SetLevel(Level);
+ }
+ }
}
}
}