Commit: ac4513a5b84017e5e95fc4b84e3e8444fd2c8494
Author: Campbell Barton
Date:   Sat Mar 31 12:52:47 2018 +0200
Branches: master
https://developer.blender.org/rBac4513a5b84017e5e95fc4b84e3e8444fd2c8494

Logging: add ability to exclude categories.

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

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

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

diff --git a/intern/clog/CLG_log.h b/intern/clog/CLG_log.h
index 0ac4a8dc5d9..b0d77281445 100644
--- a/intern/clog/CLG_log.h
+++ b/intern/clog/CLG_log.h
@@ -41,7 +41,8 @@
  * You can define and use identifiers as needed, logging will lazily 
initialize them.
  *
  * By convention lower case dot separated identifiers are used, eg:
- * `module.sub_module`, this allows filtering by `module.*`, see 
#CLG_type_filter
+ * `module.sub_module`, this allows filtering by `module.*`,
+ * see #CLG_type_filter_include, #CLG_type_filter_exclude
  *
  * There is currently no functionality to remove a category once it's created.
  *
@@ -145,7 +146,8 @@ void CLG_exit(void);
 void CLG_output_set(void *file_handle);
 void CLG_fatal_fn_set(void (*fatal_fn)(void *file_handle));
 
-void CLG_type_filter(const char *type_filter, int type_filter_len);
+void CLG_type_filter_include(const char *type_filter, int type_filter_len);
+void CLG_type_filter_exclude(const char *type_filter, int type_filter_len);
 
 void CLG_logref_init(CLG_LogRef *clg_ref);
 
diff --git a/intern/clog/clog.c b/intern/clog/clog.c
index 486b596e0cc..f82e6b3b4a1 100644
--- a/intern/clog/clog.c
+++ b/intern/clog/clog.c
@@ -56,7 +56,8 @@ typedef struct CLG_IDFilter {
 typedef struct CLogContext {
        /** Single linked list of types.  */
        CLG_LogType *types;
-       CLG_IDFilter *filters;
+       /* exclude, include filters.  */
+       CLG_IDFilter *filters[2];
        bool use_color;
 
        /** Borrowed, not owned. */
@@ -263,21 +264,24 @@ static enum eCLogColor clg_severity_to_color(enum 
CLG_Severity severity)
  */
 static bool clg_ctx_filter_check(CLogContext *ctx, const char *identifier)
 {
-       const CLG_IDFilter *flt = ctx->filters;
        const int identifier_len = strlen(identifier);
-       while (flt != NULL) {
-               const int len = strlen(flt->match);
-               if (STREQ(flt->match, "*") ||
-                   ((len == identifier_len) && (STREQ(identifier, 
flt->match))))
-               {
-                       return true;
-               }
-               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)))
+       for (uint i = 0; i < 2; i++) {
+               const CLG_IDFilter *flt = ctx->filters[i];
+               while (flt != NULL) {
+                       const int len = strlen(flt->match);
+                       if (STREQ(flt->match, "*") ||
+                               ((len == identifier_len) && (STREQ(identifier, 
flt->match))))
                        {
-                               return true;
+                               return (bool)i;
+                       }
+                       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;
+                               }
                        }
+                       flt = flt->next;
                }
        }
        return false;
@@ -438,15 +442,28 @@ static void CLG_ctx_fatal_fn_set(CLogContext *ctx, void 
(*fatal_fn)(void *file_h
        ctx->callbacks.fatal_fn = fatal_fn;
 }
 
-static void CLG_ctx_type_filter(CLogContext *ctx, const char *type_match, int 
type_match_len)
+static void clg_ctx_type_filter_append(CLG_IDFilter **flt_list, const char 
*type_match, int type_match_len)
 {
+       if (type_match_len == 0) {
+               return;
+       }
        CLG_IDFilter *flt = MEM_callocN(sizeof(*flt) + (type_match_len + 1), 
__func__);
-       flt->next = ctx->filters;
-       ctx->filters = flt;
+       flt->next = *flt_list;
+       *flt_list = flt;
        memcpy(flt->match, type_match, type_match_len);
        /* no need to null terminate since we calloc'd */
 }
 
+static void CLG_ctx_type_filter_exclude(CLogContext *ctx, const char 
*type_match, int type_match_len)
+{
+       clg_ctx_type_filter_append(&ctx->filters[0], type_match, 
type_match_len);
+}
+
+static void CLG_ctx_type_filter_include(CLogContext *ctx, const char 
*type_match, int type_match_len)
+{
+       clg_ctx_type_filter_append(&ctx->filters[1], type_match, 
type_match_len);
+}
+
 static CLogContext *CLG_ctx_init(void)
 {
        CLogContext *ctx = MEM_callocN(sizeof(*ctx), __func__);
@@ -464,10 +481,13 @@ static void CLG_ctx_free(CLogContext *ctx)
                ctx->types = item->next;
                MEM_freeN(item);
        }
-       while (ctx->filters != NULL) {
-               CLG_IDFilter *item = ctx->filters;
-               ctx->filters = item->next;
-               MEM_freeN(item);
+
+       for (uint i = 0; i < 2; i++) {
+               while (ctx->filters[i] != NULL) {
+                       CLG_IDFilter *item = ctx->filters[i];
+                       ctx->filters[i] = item->next;
+                       MEM_freeN(item);
+               }
        }
        MEM_freeN(ctx);
 }
@@ -505,9 +525,14 @@ void CLG_fatal_fn_set(void (*fatal_fn)(void *file_handle))
        CLG_ctx_fatal_fn_set(g_ctx, fatal_fn);
 }
 
-void CLG_type_filter(const char *type_match, int type_match_len)
+void CLG_type_filter_exclude(const char *type_match, int type_match_len)
+{
+       CLG_ctx_type_filter_exclude(g_ctx, type_match, type_match_len);
+}
+
+void CLG_type_filter_include(const char *type_match, int type_match_len)
 {
-       CLG_ctx_type_filter(g_ctx, type_match, type_match_len);
+       CLG_ctx_type_filter_include(g_ctx, type_match, type_match_len);
 }
 
 /** \} */
diff --git a/source/creator/creator_args.c b/source/creator/creator_args.c
index 17fa18916fd..3be16ba650b 100644
--- a/source/creator/creator_args.c
+++ b/source/creator/creator_args.c
@@ -761,6 +761,7 @@ static int arg_handle_log_file_set(int argc, const char 
**argv, void *UNUSED(dat
 static const char arg_handle_log_set_doc[] =
 "\n\tEnable logging categories, taking a single comma separated argument.\n"
 "\tMultiple categories can be matched using a '.*' suffix, so '--log \"wm.*\"' 
logs every kind of window-manager message.\n"
+"\tUse \"^\" prefix to ignore, so '--log \"*,^wm.operator.*\"' logs all except 
for 'wm.operators.*'\n"
 "\tUse \"*\" to log everything."
 ;
 static int arg_handle_log_set(int argc, const char **argv, void *UNUSED(data))
@@ -772,7 +773,12 @@ static int arg_handle_log_set(int argc, const char **argv, 
void *UNUSED(data))
                        const char *str_step_end = strchr(str_step, ',');
                        int str_step_len = str_step_end ? (str_step_end - 
str_step) : strlen(str_step);
 
-                       CLG_type_filter(str_step, str_step_len);
+                       if (str_step[0] == '^') {
+                               CLG_type_filter_exclude(str_step + 1, 
str_step_len - 1);
+                       }
+                       else {
+                               CLG_type_filter_include(str_step, str_step_len);
+                       }
 
                        if (str_step_end) {
                                /* typically only be one, but don't fail on 
multiple.*/

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to