[Bf-blender-cvs] [ef5782e2974] master: CLOG: add support for substring matching.

Bastien Montagne noreply at git.blender.org
Fri Mar 12 16:01:50 CET 2021


Commit: ef5782e297449e00e5c82e025552ddfa5cd223b2
Author: Bastien Montagne
Date:   Fri Mar 12 15:38:31 2021 +0100
Branches: master
https://developer.blender.org/rBef5782e297449e00e5c82e025552ddfa5cd223b2

CLOG: add support for substring matching.

So that `--log "*undo*"` matches any log identifier containing `undo`.

Reviewed By: campbellbarton

Differential Revision: https://developer.blender.org/D10647

===================================================================

M	intern/clog/clog.c
M	source/creator/creator_args.c

===================================================================

diff --git a/intern/clog/clog.c b/intern/clog/clog.c
index a26ac10a61f..391b71d77de 100644
--- a/intern/clog/clog.c
+++ b/intern/clog/clog.c
@@ -303,19 +303,27 @@ static enum eCLogColor clg_severity_to_color(enum CLG_Severity severity)
  * - `foo` exact match of `foo`.
  * - `foo.bar` exact match for `foo.bar`
  * - `foo.*` match for `foo` & `foo.bar` & `foo.bar.baz`
+ * - `*bar*` match for `foo.bar` & `baz.bar` & `foo.barbaz`
  * - `*` matches everything.
  */
 static bool clg_ctx_filter_check(CLogContext *ctx, const char *identifier)
 {
-  const int identifier_len = strlen(identifier);
+  const size_t identifier_len = strlen(identifier);
   for (uint i = 0; i < 2; i++) {
     const CLG_IDFilter *flt = ctx->filters[i];
     while (flt != NULL) {
-      const int len = strlen(flt->match);
+      const size_t len = strlen(flt->match);
       if (STREQ(flt->match, "*") || ((len == identifier_len) && (STREQ(identifier, flt->match)))) {
         return (bool)i;
       }
-      if ((len >= 2) && (STREQLEN(".*", &flt->match[len - 2], 2))) {
+      if (flt->match[0] == '*' && flt->match[len - 1] == '*') {
+        char *match = MEM_callocN(sizeof(char) * len - 1, __func__);
+        memcpy(match, flt->match + 1, len - 2);
+        if (strstr(identifier, match) != NULL) {
+          return (bool)i;
+        }
+      }
+      else if ((len >= 2) && (STREQLEN(".*", &flt->match[len - 2], 2))) {
         if (((identifier_len == len - 2) && STREQLEN(identifier, flt->match, len - 2)) ||
             ((identifier_len >= len - 1) && STREQLEN(identifier, flt->match, len - 1))) {
           return (bool)i;
diff --git a/source/creator/creator_args.c b/source/creator/creator_args.c
index 0e0d66d40a9..7316c1729f5 100644
--- a/source/creator/creator_args.c
+++ b/source/creator/creator_args.c
@@ -869,6 +869,8 @@ static const char arg_handle_log_set_doc[] =
     "\tEnable logging categories, taking a single comma separated argument.\n"
     "\tMultiple categories can be matched using a '.*' suffix,\n"
     "\tso '--log \"wm.*\"' logs every kind of window-manager message.\n"
+    "\tSub-string can be matched using a '*' prefix and suffix,\n"
+    "\tso '--log \"*undo*\"' logs every kind of undo-related message.\n"
     "\tUse \"^\" prefix to ignore, so '--log \"*,^wm.operator.*\"' logs all except for "
     "'wm.operators.*'\n"
     "\tUse \"*\" to log everything.";



More information about the Bf-blender-cvs mailing list