[Bf-blender-cvs] [513e86efc1d] soc-2020-info-editor: Make reports use CLOG for printing reports that can not be displayed
Mateusz GrzeliÅski
noreply at git.blender.org
Wed Jul 1 17:43:40 CEST 2020
Commit: 513e86efc1d38ae2fdd05f4824f7d2b6c567082d
Author: Mateusz Grzeliński
Date: Wed Jul 1 17:43:20 2020 +0200
Branches: soc-2020-info-editor
https://developer.blender.org/rB513e86efc1d38ae2fdd05f4824f7d2b6c567082d
Make reports use CLOG for printing reports that can not be displayed
This is useful for example for versioning reports, they will persist in info editor as log entry
===================================================================
M source/blender/blenkernel/intern/report.c
===================================================================
diff --git a/source/blender/blenkernel/intern/report.c b/source/blender/blenkernel/intern/report.c
index 6b8c3a226e4..2a9a401a4cf 100644
--- a/source/blender/blenkernel/intern/report.c
+++ b/source/blender/blenkernel/intern/report.c
@@ -21,6 +21,7 @@
* \ingroup bke
*/
+#include <CLG_log.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
@@ -37,6 +38,8 @@
#include "BKE_global.h" /* G.background only */
#include "BKE_report.h"
+static CLG_LogRef LOG = {"bke.report"};
+
const char *BKE_report_type_str(ReportType type)
{
switch (type) {
@@ -128,11 +131,19 @@ void BKE_report(ReportList *reports, ReportType type, const char *_message)
int len;
const char *message = TIP_(_message);
- /* in background mode always print otherwise there are cases the errors wont be displayed,
+ /* in background mode always log otherwise there are cases the errors wont be displayed,
* but still add to the report list since this is used for python exception handling */
if (G.background || !reports || ((reports->flag & RPT_PRINT) && (type >= reports->printlevel))) {
- printf("%s: %s\n", BKE_report_type_str(type), message);
- fflush(stdout); /* this ensures the message is printed before a crash */
+ // todo enable bke.report logger by default ?
+ if (type & RPT_ERROR_ALL) {
+ CLOG_ERROR(&LOG, "%s: %s", BKE_report_type_str(type), message);
+ }
+ else if (type & RPT_WARNING_ALL) {
+ CLOG_WARN(&LOG, "%s: %s", BKE_report_type_str(type), message);
+ }
+ else {
+ CLOG_INFO(&LOG, 0, "%s: %s", BKE_report_type_str(type), message);
+ }
}
if (reports && (reports->flag & RPT_STORE) && (type >= reports->storelevel)) {
@@ -158,12 +169,22 @@ void BKE_reportf(ReportList *reports, ReportType type, const char *_format, ...)
const char *format = TIP_(_format);
if (G.background || !reports || ((reports->flag & RPT_PRINT) && (type >= reports->printlevel))) {
- printf("%s: ", BKE_report_type_str(type));
+ DynStr *message = BLI_dynstr_new();
va_start(args, _format);
- vprintf(format, args);
+ BLI_dynstr_vappendf(message, format, args);
va_end(args);
- fprintf(stdout, "\n"); /* otherwise each report needs to include a \n */
- fflush(stdout); /* this ensures the message is printed before a crash */
+ char *message_cstring = BLI_dynstr_get_cstring(message);
+ if (type & RPT_ERROR_ALL) {
+ CLOG_ERROR(&LOG, "%s: %s", BKE_report_type_str(type), message_cstring);
+ }
+ else if (type & RPT_WARNING_ALL) {
+ CLOG_WARN(&LOG, "%s: %s", BKE_report_type_str(type), message_cstring);
+ }
+ else {
+ CLOG_INFO(&LOG, 0, "%s: %s", BKE_report_type_str(type), message_cstring);
+ }
+ MEM_freeN(message_cstring);
+ BLI_dynstr_free(message);
}
if (reports && (reports->flag & RPT_STORE) && (type >= reports->storelevel)) {
More information about the Bf-blender-cvs
mailing list