[Bf-blender-cvs] [1cc7de9d920] soc-2020-info-editor: Auto refresh info editor when new log arrives

Mateusz Grzeliński noreply at git.blender.org
Tue Aug 18 12:38:56 CEST 2020


Commit: 1cc7de9d920427a5b1bfe46ef51deeb0260ba9a7
Author: Mateusz Grzeliński
Date:   Tue Aug 18 12:37:37 2020 +0200
Branches: soc-2020-info-editor
https://developer.blender.org/rB1cc7de9d920427a5b1bfe46ef51deeb0260ba9a7

Auto refresh info editor when new log arrives

CLOG is a separate library so it can not directly use window manager notifications. Now it can be done by setting custom write callback.
Also remove todos and cleanup comments.

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

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

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

diff --git a/intern/clog/CLG_log.h b/intern/clog/CLG_log.h
index 771f52962b3..39b9809b2b5 100644
--- a/intern/clog/CLG_log.h
+++ b/intern/clog/CLG_log.h
@@ -85,7 +85,8 @@ extern "C" {
 #  define _CLOG_ATTR_PRINTF_FORMAT(format_param, dots_param)
 #endif
 
-/* workaround: copied from blender\source\blender\blenlib\BLI_compiler_attrs.h to avoid making dependency on blenlib */
+/* workaround: copied from blender\source\blender\blenlib\BLI_compiler_attrs.h to avoid making
+ * dependency on blenlib */
 /* Use to suppress '-Wimplicit-fallthrough' (in place of 'break'). */
 #ifndef ATTR_FALLTHROUGH
 #  if defined(__GNUC__) && (__GNUC__ >= 7) /* gcc7.0+ only */
@@ -155,7 +156,7 @@ typedef struct CLG_LogRecord {
   /** Link for clog version of ListBase */
   struct CLG_LogRecord *next, *prev;
   /** track where does the log comes from */
-  CLG_LogType *type;
+  const CLG_LogType *type;
   enum CLG_Severity severity;
   unsigned short verbosity;
   uint64_t timestamp;
@@ -176,24 +177,30 @@ typedef struct CLG_LogRecordList {
   struct CLG_LogRecord *first, *last;
 } CLG_LogRecordList;
 
-void CLG_log_str(CLG_LogType *lg,
-                 enum CLG_Severity severity,
-                 unsigned short verbosity,
+void CLG_log_str(const CLG_LogType *lg,
+                 const enum CLG_Severity severity,
+                 const unsigned short verbosity,
                  const char *file_line,
                  const char *fn,
                  const char *message) _CLOG_ATTR_NONNULL(1, 4, 5, 6);
-void CLG_logf(CLG_LogType *lg,
-              enum CLG_Severity severity,
-              unsigned short verbosity,
+void CLG_logf(const CLG_LogType *lg,
+              const enum CLG_Severity severity,
+              const unsigned short verbosity,
               const char *file_line,
               const char *fn,
               const char *format,
               ...) _CLOG_ATTR_NONNULL(1, 4, 5, 6) _CLOG_ATTR_PRINTF_FORMAT(6, 7);
+void CLG_log_write_callback_default(const struct CLG_LogType *lg,
+                                    const enum CLG_Severity severity,
+                                    const unsigned short verbosity,
+                                    const char *file_line,
+                                    const char *fn,
+                                    const char *message);
 
 const char *clg_severity_as_text(enum CLG_Severity severity);
-CLG_LogRecord *clog_log_record_init(CLG_LogType *type,
-                                    enum CLG_Severity severity,
-                                    unsigned short verbosity,
+CLG_LogRecord *clog_log_record_init(const CLG_LogType *type,
+                                    const enum CLG_Severity severity,
+                                    const unsigned short verbosity,
                                     const char *file_line,
                                     const char *function,
                                     const char *message);
@@ -215,6 +222,12 @@ bool CLG_output_use_timestamp_get(void);
 void CLG_output_use_timestamp_set(int value);
 void CLG_fatal_fn_set(void (*fatal_fn)(void *file_handle));
 void CLG_backtrace_fn_set(void (*fatal_fn)(void *file_handle));
+void CLG_log_write_fn_set(void (*log_write_fn)(const CLG_LogType *lg,
+                                               const enum CLG_Severity severity,
+                                               const unsigned short verbosity,
+                                               const char *file_line,
+                                               const char *fn,
+                                               const char *message)) _CLOG_ATTR_NONNULL(1);
 
 void CLG_type_filter_set(const char *glob_str);
 int CLG_type_filter_get(char *buff, int buff_len);
diff --git a/intern/clog/clog.c b/intern/clog/clog.c
index 88efc3df592..0d2a8580003 100644
--- a/intern/clog/clog.c
+++ b/intern/clog/clog.c
@@ -74,7 +74,7 @@ typedef struct CLG_IDFilter {
 } CLG_IDFilter;
 
 typedef struct CLogContext {
-  /** Single linked list of types.  */
+  /** Single linked list of types. */
   CLG_LogType *types;
   CLG_LogRecordList log_records;
 
@@ -102,13 +102,19 @@ typedef struct CLogContext {
   } default_type;
 
   struct {
+    void (*log_write_fn)(const CLG_LogType *lg,
+                         const enum CLG_Severity severity,
+                         const unsigned short verbosity,
+                         const char *file_line,
+                         const char *fn,
+                         const char *message);
     void (*fatal_fn)(void *file_handle);
     void (*backtrace_fn)(void *file_handle);
   } callbacks;
 
   bool use_stdout;
   bool always_show_warnings;
-  /** used only is use_stdout is false */
+  /** Used only is use_stdout is false. */
   char output_file_path[256];
 } CLogContext;
 
@@ -120,8 +126,7 @@ typedef struct CLogContext {
  * Use so we can do a single call to write.
  * \{ */
 
-/* TODO (grzelins) temporary fix for handling big log messages */
-#define CLOG_BUF_LEN_INIT 4096
+#define CLOG_BUF_LEN_INIT 512
 
 typedef struct CLogStringBuf {
   char *data;
@@ -389,6 +394,12 @@ static void clg_ctx_backtrace(CLogContext *ctx)
   fflush(ctx->output_file);
 }
 
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Logging API
+ * \{ */
+
 static uint64_t clg_timestamp_ticks_get(void)
 {
   uint64_t tick;
@@ -402,9 +413,9 @@ static uint64_t clg_timestamp_ticks_get(void)
   return tick;
 }
 
-CLG_LogRecord *clog_log_record_init(CLG_LogType *type,
-                                    enum CLG_Severity severity,
-                                    unsigned short verbosity,
+CLG_LogRecord *clog_log_record_init(const CLG_LogType *type,
+                                    const enum CLG_Severity severity,
+                                    const unsigned short verbosity,
                                     const char *file_line,
                                     const char *function,
                                     const char *message)
@@ -412,7 +423,6 @@ CLG_LogRecord *clog_log_record_init(CLG_LogType *type,
   CLG_LogRecord *log_record = MEM_callocN(sizeof(*log_record), "ClogRecord");
   log_record->type = type;
   log_record->severity = severity;
-  log_record->severity = severity;
   log_record->verbosity = verbosity;
   log_record->timestamp = clg_timestamp_ticks_get() - type->ctx->timestamp_tick_start;
   log_record->file_line = file_line;
@@ -430,12 +440,6 @@ void CLG_log_record_free(CLG_LogRecord *log_record)
   MEM_freeN(log_record);
 }
 
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name Logging API
- * \{ */
-
 static void write_timestamp(CLogStringBuf *cstr, const uint64_t timestamp_tick_start)
 {
   char timestamp_str[64];
@@ -448,7 +452,9 @@ static void write_timestamp(CLogStringBuf *cstr, const uint64_t timestamp_tick_s
   clg_str_append_with_len(cstr, timestamp_str, timestamp_len);
 }
 
-static void write_severity(CLogStringBuf *cstr, enum CLG_Severity severity, bool use_color)
+static void write_severity(CLogStringBuf *cstr,
+                           const enum CLG_Severity severity,
+                           const bool use_color)
 {
   assert((unsigned int)severity < CLG_SEVERITY_LEN);
   if (use_color) {
@@ -462,7 +468,7 @@ static void write_severity(CLogStringBuf *cstr, enum CLG_Severity severity, bool
   }
 }
 
-static void write_type(CLogStringBuf *cstr, CLG_LogType *lg)
+static void write_type(CLogStringBuf *cstr, const CLG_LogType *lg)
 {
   clg_str_append(cstr, " (");
   clg_str_append(cstr, lg->identifier);
@@ -513,12 +519,12 @@ static void CLG_record_append(CLG_LogRecordList *listbase, CLG_LogRecord *link)
   listbase->last = link;
 }
 
-void CLG_log_str(CLG_LogType *lg,
-                 enum CLG_Severity severity,
-                 unsigned short verbosity,
-                 const char *file_line,
-                 const char *fn,
-                 const char *message)
+void CLG_log_write_callback_default(const CLG_LogType *lg,
+                                    const enum CLG_Severity severity,
+                                    const unsigned short verbosity,
+                                    const char *file_line,
+                                    const char *fn,
+                                    const char *message)
 {
   CLogStringBuf cstr;
   char cstr_stack_buf[CLOG_BUF_LEN_INIT];
@@ -547,6 +553,16 @@ void CLG_log_str(CLG_LogType *lg,
   (void)bytes_written;
 
   clg_str_free(&cstr);
+}
+
+void CLG_log_str(const CLG_LogType *lg,
+                 const enum CLG_Severity severity,
+                 unsigned short verbosity,
+                 const char *file_line,
+                 const char *fn,
+                 const char *message)
+{
+  lg->ctx->callbacks.log_write_fn(lg, severity, verbosity, file_line, fn, message);
 
   CLG_LogRecord *log_record = clog_log_record_init(
       lg, severity, verbosity, file_line, fn, message);
@@ -561,58 +577,31 @@ void CLG_log_str(CLG_LogType *lg,
   }
 }
 
-
-/* TODO (grzelins) there is problem with handling big messages (example is report from duplicating object) */
-void CLG_logf(CLG_LogType *lg,
-              enum CLG_Severity severity,
-              unsigned short verbosity,
+void CLG_logf(const CLG_LogType *lg,
+              const enum CLG_Severity severity,
+              const unsigned short verbosity,
               const char *file_line,
               const char *fn,
               const char *fmt,
               ...)
 {
-  CLogStringBuf cstr;
-  char cstr_stack_buf[CLOG_BUF_LEN_INIT];
-  clg_str_init(&cstr, cstr_stack_buf, sizeof(cstr_stack_buf));
-
-  if (lg->ctx->use_timestamp) {
-    write_timestamp(&cstr, lg->ctx->timestamp_tick_start);
-  }
-
-  write_severity(&cstr, severity, lg->ctx->use_color);
-  if (severity <= CLG_SEVERITY_VERBOSE) {
-    char verbosity_str[8];
-    sprintf(verbosity_str, ":%u", verbosity);
-    clg_str_append(&cstr, verbosity_str);
-  }
-  write_type(&cstr, lg);
-
-  write_file_line_fn(&cstr, file_line, fn, lg->ctx->use_basename);
-
-  int cstr_size_before_va = cstr.len;
+  CLogStringBuf message;
+  char message_stack_buf[CLOG_BUF_LEN_INIT];
+  clg_str_init(&message, messa

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list