Commit: d9fa0b2198a3492df0683b18f8ab27393aab0c7b
Author: Mateusz Grzeliński
Date:   Tue Aug 4 12:25:41 2020 +0200
Branches: soc-2020-info-editor
https://developer.blender.org/rBd9fa0b2198a3492df0683b18f8ab27393aab0c7b

Fix todo: do not log reports when converting to log to report

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

M       intern/clog/CLG_log.h
M       intern/clog/clog.c
M       release/scripts/startup/bl_ui/space_userpref.py
M       source/blender/blenkernel/BKE_report.h
M       source/blender/blenkernel/intern/report.c
M       source/blender/editors/space_info/info_report.c
M       source/blender/makesrna/intern/rna_userdef.c

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

diff --git a/intern/clog/CLG_log.h b/intern/clog/CLG_log.h
index 16fd8010100..08082c3ca7e 100644
--- a/intern/clog/CLG_log.h
+++ b/intern/clog/CLG_log.h
@@ -141,13 +141,13 @@ typedef struct CLG_LogRecord {
   uint64_t timestamp;
   const char *file_line;
   const char *function;
-  char *message;
+  const char *message;
 } CLG_LogRecord;
 
 /** clog version of ListBase */
-typedef struct LogRecordList {
+typedef struct CLG_LogRecordList {
   struct CLG_LogRecord *first, *last;
-} LogRecordList;
+} CLG_LogRecordList;
 
 void CLG_log_str(CLG_LogType *lg,
                  enum CLG_Severity severity,
@@ -197,7 +197,7 @@ enum CLG_Severity CLG_severity_level_get(void);
 void CLG_severity_level_set(enum CLG_Severity log_level);
 unsigned short CLG_level_get(void);
 void CLG_level_set(unsigned short log_level);
-struct LogRecordList *CLG_log_record_get(void);
+struct CLG_LogRecordList *CLG_log_record_get(void);
 
 void CLG_logref_init(CLG_LogRef *clg_ref);
 
diff --git a/intern/clog/clog.c b/intern/clog/clog.c
index 77db389f3f2..ccdfc64ca31 100644
--- a/intern/clog/clog.c
+++ b/intern/clog/clog.c
@@ -76,7 +76,7 @@ typedef struct CLG_IDFilter {
 typedef struct CLogContext {
   /** Single linked list of types.  */
   CLG_LogType *types;
-  LogRecordList log_records;
+  CLG_LogRecordList log_records;
 
 #ifdef WITH_CLOG_PTHREADS
   pthread_mutex_t types_lock;
@@ -489,6 +489,26 @@ static void write_file_line_fn(CLogStringBuf *cstr,
   clg_str_append(cstr, ": ");
 }
 
+/** Clog version of BLI_addtail (to avoid making dependency) */
+static void CLG_report_append(CLG_LogRecordList *listbase, CLG_LogRecord *link)
+{
+
+  if (link == NULL) {
+    return;
+  }
+
+  link->next = NULL;
+  link->prev = listbase->last;
+
+  if (listbase->last) {
+    listbase->last->next = link;
+  }
+  if (listbase->first == NULL) {
+    listbase->first = link;
+  }
+  listbase->last = link;
+}
+
 void CLG_log_str(CLG_LogType *lg,
                  enum CLG_Severity severity,
                  unsigned short verbosity,
@@ -524,6 +544,10 @@ void CLG_log_str(CLG_LogType *lg,
 
   clg_str_free(&cstr);
 
+  CLG_LogRecord *log_record = clog_log_record_init(
+      lg, severity, verbosity, file_line, fn, message);
+  CLG_report_append(&(lg->ctx->log_records), log_record);
+
   if (lg->ctx->callbacks.backtrace_fn) {
     clg_ctx_backtrace(lg->ctx);
   }
@@ -533,25 +557,6 @@ void CLG_log_str(CLG_LogType *lg,
   }
 }
 
-/** Clog version of BLI_addtail (to avoid making dependency) */
-static void CLG_report_append(LogRecordList *listbase, CLG_LogRecord *link)
-{
-
-  if (link == NULL) {
-    return;
-  }
-
-  link->next = NULL;
-  link->prev = listbase->last;
-
-  if (listbase->last) {
-    listbase->last->next = link;
-  }
-  if (listbase->first == NULL) {
-    listbase->first = link;
-  }
-  listbase->last = link;
-}
 
 /* TODO (grzelins) there is problem with handling big messages (example is 
report from duplicating object) */
 void CLG_logf(CLG_LogType *lg,
@@ -811,7 +816,7 @@ static void CLG_ctx_level_set(CLogContext *ctx, unsigned 
short level)
   }
 }
 
-static LogRecordList *CLG_ctx_log_record_get(CLogContext *ctx)
+static CLG_LogRecordList *CLG_ctx_log_record_get(CLogContext *ctx)
 {
   return &ctx->log_records;
 }
@@ -1008,7 +1013,7 @@ unsigned short CLG_level_get()
   return CLG_ctx_level_get(g_ctx);
 }
 
-LogRecordList *CLG_log_record_get()
+CLG_LogRecordList *CLG_log_record_get()
 {
   return CLG_ctx_log_record_get(g_ctx);
 }
diff --git a/release/scripts/startup/bl_ui/space_userpref.py 
b/release/scripts/startup/bl_ui/space_userpref.py
index a680034a7c2..d2ae3144fe3 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -652,8 +652,6 @@ class USERPREF_PT_system_logging(SystemPanel, 
CenterAlignMixIn, Panel):
         system = prefs.system
 
         layout.prop(system, "log_filter")
-        layout.prop(system, "log_use_basename")
-        layout.prop(system, "log_use_timestamp")
         layout.prop(system, "verbose")
         layout.prop(system, "log_severity")
 
@@ -661,6 +659,9 @@ class USERPREF_PT_system_logging(SystemPanel, 
CenterAlignMixIn, Panel):
         col.active = system.log_severity in {'LOG_VERBOSE', 'LOG_DEBUG'}
         col.prop(system, "log_level")
 
+        layout.prop(system, "log_use_basename")
+        layout.prop(system, "log_use_timestamp")
+
         layout.prop(system, "log_use_stdout")
         col = layout.column()
         col.active = not system.log_use_stdout
diff --git a/source/blender/blenkernel/BKE_report.h 
b/source/blender/blenkernel/BKE_report.h
index 6e875e6cbd4..2e97a361af0 100644
--- a/source/blender/blenkernel/BKE_report.h
+++ b/source/blender/blenkernel/BKE_report.h
@@ -44,6 +44,7 @@ ReportList *BKE_reports_duplicate(ReportList *reports);
 
 void BKE_report_format(ReportList *reports, ReportType type, int flags, const 
char *message);
 void BKE_report(ReportList *reports, ReportType type, const char *message);
+Report *BKE_report_init(ReportType type, int flags, const char *message);
 void BKE_reportf_format(ReportList *reports, ReportType type, int flags, const 
char *format, ...)
     ATTR_PRINTF_FORMAT(4, 5);
 void BKE_reportf(ReportList *reports, ReportType type, const char *format, ...)
@@ -67,6 +68,14 @@ const char *BKE_report_type_str(ReportType type);
 bool BKE_report_write_file_fp(FILE *fp, ReportList *reports, const char 
*header);
 bool BKE_report_write_file(const char *filepath, ReportList *reports, const 
char *header);
 
+#define CLOG_REPORT(log_ref, report) \
+  CLOG_AT_SEVERITY(log_ref, \
+                   report_type_to_severity((report)->type), \
+                   0, \
+                   "%s: %s", \
+                   BKE_report_type_str(type), \
+                   message);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/report.c 
b/source/blender/blenkernel/intern/report.c
index d235409c543..2b90b22ac6b 100644
--- a/source/blender/blenkernel/intern/report.c
+++ b/source/blender/blenkernel/intern/report.c
@@ -152,8 +152,6 @@ ReportList *BKE_reports_duplicate(ReportList *reports)
 
 void BKE_report_format(ReportList *reports, ReportType type, int flags, const 
char *_message)
 {
-  Report *report;
-  int len;
   const char *message = TIP_(_message);
 
   CLOG_AT_SEVERITY(&LOG,
@@ -165,21 +163,28 @@ void BKE_report_format(ReportList *reports, ReportType 
type, int flags, const ch
                    message);
 
   if (reports) {
-    char *message_alloc;
-    report = MEM_callocN(sizeof(Report), "Report");
-    report->type = type;
-    report->flag = flags;
-    report->typestr = BKE_report_type_str(type);
-
-    len = strlen(message);
-    message_alloc = MEM_mallocN(sizeof(char) * (len + 1), "ReportMessage");
-    memcpy(message_alloc, message, sizeof(char) * (len + 1));
-    report->message = message_alloc;
-    report->len = len;
+    Report *report = BKE_report_init(type, flags, message);
     BLI_addtail(&reports->list, report);
   }
 }
 
+Report *BKE_report_init(ReportType type, int flags, const char *message)
+{
+  Report *report;
+  char *message_alloc;
+  report = MEM_callocN(sizeof(Report), "Report");
+  report->type = type;
+  report->flag = flags;
+  report->typestr = BKE_report_type_str(type);
+
+  int len = strlen(message);
+  message_alloc = MEM_mallocN(sizeof(char) * (len + 1), "ReportMessage");
+  memcpy(message_alloc, message, sizeof(char) * (len + 1));
+  report->message = message_alloc;
+  report->len = len;
+  return report;
+}
+
 void BKE_report(ReportList *reports, ReportType type, const char *_message)
 {
   BKE_report_format(reports, type, 0, _message);
diff --git a/source/blender/editors/space_info/info_report.c 
b/source/blender/editors/space_info/info_report.c
index ab7195a3d4b..b7632813663 100644
--- a/source/blender/editors/space_info/info_report.c
+++ b/source/blender/editors/space_info/info_report.c
@@ -486,9 +486,9 @@ ReportList *clog_to_report_list()
 {
   ReportList *reports = MEM_mallocN(sizeof(*reports), 
"ClogConvertedToReportList");
   BKE_reports_init(reports, 0);
-  ListBase *records = (ListBase *)CLG_log_record_get();
+  CLG_LogRecordList *records = CLG_log_record_get();
 
-  if (BLI_listbase_is_empty(records)) {
+  if (BLI_listbase_is_empty((const struct ListBase *)records)) {
     return reports;
   }
 
@@ -507,23 +507,27 @@ ReportList *clog_to_report_list()
     BLI_dynstr_append(dynStr, ":\n");
     BLI_dynstr_append(dynStr, log->message);
     char *cstr = BLI_dynstr_get_cstring(dynStr);
-    /* TODO (grzelins) using BKE_report will log messages in bke.report! it 
will crash because
-     * message is too long!! */
+    Report *report;
     switch (log->severity) {
+      case CLG_SEVERITY_DEBUG:
+      case CLG_SEVERITY_VERBOSE:
+        report = BKE_report_init(RPT_DEBUG, 0, cstr);
+        break;
       case CLG_SEVERITY_INFO:
-        BKE_report(reports, RPT_INFO, cstr);
+        report = BKE_report_init(RPT_INFO, 0, cstr);
         break;
       case CLG_SEVERITY_WARN:
-        BKE_report(reports, RPT_WARNING, cstr);
+        report = BKE_report_init(RPT_WARNING, 0, cstr);
         break;
       case CLG_SEVERITY_ERROR:
       case CLG_SEVERITY_FATAL:
-        BKE_report(reports, RPT_ERROR, cstr);
+        report = BKE_report_init(RPT_ERROR, 0, cstr);
         break;
       default:
-        BKE_report(reports, RPT_INFO, cstr);
+        report = BKE_report_init(RPT_INFO, 0, cstr);
         break;
     }
+    BLI_addtail(&reports->list, report);
     MEM_freeN(cstr);
     BLI_dynstr_free(dynStr);
     log = log->next;
diff --git a/source/blender/makesrna/intern/rna_userdef.c 
b/source/blender/makesrna/intern/rna_userdef.c
index 44b9af9b6e5..2c6a12972d3 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -5810,7 +5810,7 @@ static void rna_def_userdef_system(BlenderRNA *brna)
   prop = RNA_def_property(srna, "log_use_basename", PROP_BOOLEAN, PROP_NONE);
   RNA_def_property_boolean_funcs(
       prop, "rna_clog_log_use_basename_get", "rna_clog_log_use_basename_set");
-  RNA_def_property_ui_text(prop, "Use Basename", "");
+  RNA_def_property_ui_text(prop, "Use Basename", "Show only filename instead 
of full filepath");
 
   pro

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to