Commit: 175dd297ddf65e0d2bd470e54e6c887407f1ac3e Author: Mateusz Grzeliński Date: Wed Jul 29 18:59:15 2020 +0200 Branches: soc-2020-info-editor https://developer.blender.org/rB175dd297ddf65e0d2bd470e54e6c887407f1ac3e
Expose part of logging properties in preferences =================================================================== 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_global.h M source/blender/blenkernel/intern/blender.c M source/blender/makesrna/intern/rna_userdef.c M source/creator/creator_args.c =================================================================== diff --git a/intern/clog/CLG_log.h b/intern/clog/CLG_log.h index ad11cc0d1dc..99604574730 100644 --- a/intern/clog/CLG_log.h +++ b/intern/clog/CLG_log.h @@ -88,6 +88,7 @@ extern "C" { /* For printing timestamp. */ #define __STDC_FORMAT_MACROS #include <inttypes.h> +#include <stdbool.h> #define STRINGIFY_ARG(x) "" #x #define STRINGIFY_APPEND(a, b) "" a #b @@ -170,8 +171,13 @@ void clog_log_record_free(CLG_LogRecord *log_record); void CLG_init(void); void CLG_exit(void); -void CLG_output_set(void *file_handle); +bool CLG_use_stdout_get(void); +void CLG_use_stdout_set(bool value); +char *CLG_file_output_path_get(void); +void CLG_file_output_path_set(const char *value); +bool CLG_output_use_basename_get(void); void CLG_output_use_basename_set(int value); +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)); @@ -179,7 +185,9 @@ void CLG_backtrace_fn_set(void (*fatal_fn)(void *file_handle)); 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); +enum CLG_Severity CLG_severity_level_get(void); void CLG_severity_level_set(enum CLG_Severity level); +short CLG_verbosity_level_get(void); void CLG_verbosity_level_set(unsigned short level); struct LogRecordList *CLG_log_record_get(void); diff --git a/intern/clog/clog.c b/intern/clog/clog.c index fd98f104e79..7d8c18a3706 100644 --- a/intern/clog/clog.c +++ b/intern/clog/clog.c @@ -44,6 +44,7 @@ /* For printing timestamp. */ #define __STDC_FORMAT_MACROS +#include <errno.h> #include <inttypes.h> /* Only other dependency (could use regular malloc too). */ @@ -87,7 +88,7 @@ typedef struct CLogContext { bool use_basename; bool use_timestamp; - /** Borrowed, not owned. */ + /** Owned. */ int output; FILE *output_file; @@ -105,6 +106,9 @@ typedef struct CLogContext { void (*backtrace_fn)(void *file_handle); } callbacks; + bool use_stdout; + /** used only is use_stdout is false */ + char output_file_path[256]; } CLogContext; /** \} */ @@ -604,20 +608,75 @@ void CLG_logf(CLG_LogType *lg, /** \name Logging Context API * \{ */ -static void CLG_ctx_output_set(CLogContext *ctx, void *file_handle) +static void CLG_ctx_output_update(CLogContext *ctx) { - ctx->output_file = file_handle; + if (ctx->use_stdout && ctx->output_file != stdout) { + /* set output to stdout */ + if (ctx->output_file != NULL) { + fclose(ctx->output_file); + } + ctx->output_file = stdout; + } + + if (!ctx->use_stdout) { + FILE *fp = fopen(ctx->output_file_path, "w"); + if (fp == NULL) { + const char *err_msg = errno ? strerror(errno) : "unknown"; + printf("Error: %s '%s'.\n", err_msg, ctx->output_file_path); + return; + } + ctx->output_file = fp; + } ctx->output = fileno(ctx->output_file); #if defined(__unix__) || defined(__APPLE__) ctx->use_color = isatty(ctx->output); #endif } +static char *CLG_ctx_file_output_path_get(CLogContext *ctx) +{ + return ctx->output_file_path; +} + +static void CLG_ctx_file_output_path_set(CLogContext *ctx, const char *value) +{ + if (strcmp(ctx->output_file_path, value) != 0) { + strcpy(ctx->output_file_path, value); + if (!ctx->use_stdout) { + CLG_ctx_output_update(ctx); + } + } +} + +static bool CLG_ctx_use_stdout_get(CLogContext *ctx) +{ + return ctx->use_stdout; +} + +static void CLG_ctx_use_stdout_set(CLogContext *ctx, bool value) +{ + if (ctx->use_stdout == value) { + return; + } + ctx->use_stdout = value; + CLG_ctx_output_update(ctx); +} + +static bool CLG_ctx_output_use_basename_get(CLogContext *ctx) +{ + return ctx->use_basename; +} + static void CLG_ctx_output_use_basename_set(CLogContext *ctx, int value) { ctx->use_basename = (bool)value; } +static bool CLG_ctx_output_use_timestamp_get(CLogContext *ctx) +{ + return ctx->use_timestamp; +} + static void CLG_ctx_output_use_timestamp_set(CLogContext *ctx, int value) { ctx->use_timestamp = (bool)value; @@ -665,6 +724,11 @@ static void CLG_ctx_type_filter_include(CLogContext *ctx, clg_ctx_type_filter_append(&ctx->filters[1], type_match, type_match_len); } +static enum CLG_Severity CLG_ctx_severity_level_get(CLogContext *ctx) +{ + return ctx->default_type.severity_level; +} + static void CLG_ctx_severity_level_set(CLogContext *ctx, enum CLG_Severity level) { ctx->default_type.severity_level = level; @@ -673,6 +737,11 @@ static void CLG_ctx_severity_level_set(CLogContext *ctx, enum CLG_Severity level } } +static short CLG_ctx_verbosity_level_get(CLogContext *ctx) +{ + return ctx->default_type.verbosity_level; +} + static void CLG_ctx_verbosity_level_set(CLogContext *ctx, unsigned short level) { ctx->default_type.verbosity_level = level; @@ -695,7 +764,8 @@ static CLogContext *CLG_ctx_init(void) ctx->use_color = true; ctx->default_type.severity_level = CLG_SEVERITY_INFO; ctx->default_type.verbosity_level = 0; - CLG_ctx_output_set(ctx, stdout); + ctx->use_stdout = true; + CLG_ctx_output_update(ctx); return ctx; } @@ -708,6 +778,9 @@ static void CLG_ctx_free(CLogContext *ctx) clog_log_record_free(log); log = log_next; } + if (ctx->output_file != NULL) { + fclose(ctx->output_file); + } ctx->log_records.first = NULL; ctx->log_records.last = NULL; @@ -753,9 +826,29 @@ void CLG_exit(void) CLG_ctx_free(g_ctx); } -void CLG_output_set(void *file_handle) +void CLG_file_output_path_set(const char *CLG_file_output_path_get) +{ + CLG_ctx_file_output_path_set(g_ctx, CLG_file_output_path_get); +} + +char *CLG_file_output_path_get() { - CLG_ctx_output_set(g_ctx, file_handle); + return CLG_ctx_file_output_path_get(g_ctx); +} + +bool CLG_use_stdout_get() +{ + return CLG_ctx_use_stdout_get(g_ctx); +} + +void CLG_use_stdout_set(bool value) +{ + CLG_ctx_use_stdout_set(g_ctx, value); +} + +bool CLG_output_use_basename_get() +{ + return CLG_ctx_output_use_basename_get(g_ctx); } void CLG_output_use_basename_set(int value) @@ -763,6 +856,11 @@ void CLG_output_use_basename_set(int value) CLG_ctx_output_use_basename_set(g_ctx, value); } +bool CLG_output_use_timestamp_get() +{ + return CLG_ctx_output_use_timestamp_get(g_ctx); +} + void CLG_output_use_timestamp_set(int value) { CLG_ctx_output_use_timestamp_set(g_ctx, value); @@ -793,11 +891,21 @@ void CLG_severity_level_set(enum CLG_Severity level) CLG_ctx_severity_level_set(g_ctx, level); } +enum CLG_Severity CLG_severity_level_get() +{ + return CLG_ctx_severity_level_get(g_ctx); +} + void CLG_verbosity_level_set(unsigned short level) { CLG_ctx_verbosity_level_set(g_ctx, level); } +short CLG_verbosity_level_get() +{ + return CLG_ctx_verbosity_level_get(g_ctx); +} + 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 03f85578b6e..f5cb1cfd29d 100644 --- a/release/scripts/startup/bl_ui/space_userpref.py +++ b/release/scripts/startup/bl_ui/space_userpref.py @@ -644,6 +644,27 @@ class USERPREF_PT_system_video_sequencer(SystemPanel, CenterAlignMixIn, Panel): col.prop(system, "sequencer_disk_cache_compression", text="Compression") +class USERPREF_PT_system_logging(SystemPanel, CenterAlignMixIn, Panel): + bl_label = "Logging" + + def draw_centered(self, context, layout): + prefs = context.preferences + system = prefs.system + + layout.prop(system, "log_use_basename") + layout.prop(system, "log_use_timestamp") + layout.prop(system, "log_severity") + layout.prop(system, "verbose") + + col = layout.column() + col.active = system.log_severity == 'LOG_VERBOSE' + col.prop(system, "log_verbosity") + + layout.prop(system, "log_use_stdout") + col = layout.column() + col.active = not system.log_use_stdout + col.prop(system, "log_output_file") + # ----------------------------------------------------------------------------- # Viewport Panels @@ -2233,6 +2254,7 @@ classes = ( USERPREF_PT_system_cycles_devices, USERPREF_PT_system_memory, USERPREF_PT_system_video_sequencer, + USERPREF_PT_system_logging, USERPREF_PT_system_sound, USERPREF_MT_interface_theme_presets, diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h index 66142cf782b..4ae6af95ebe 100644 --- a/source/blender/blenkernel/BKE_global.h +++ b/source/blender/blenkernel/BKE_global.h @@ -88,10 +88,10 @@ typedef struct Global { int f; struct { - /** Logging vars (different loggers may use). */ - int level; /* currently unused */ + /** Verbosity for third party loggers */ + int level; /** FILE handle or use stderr (we own this so close when done). */ - void *file; + void *file; /* currently unused */ } log; /** debug flag, #G_DEBUG, #G_DEBUG_PYTHON & friends, set python or command line args */ diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index e8aa13a8beb..5443b3c1f31 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -81,10 +81,6 @@ void BKE_blender_free(void) BKE_main_free(G_MAIN); G_MAIN = NULL; - if (G.log.file != NULL) { - fclose(G.log.file); - } - BKE_spacetypes_free(); /* after free main, it uses space callbacks */ IMB_exit(); @@ -152,8 +148,6 @@ void BKE_blender_globals_init(void) #else G.f &= ~G_FLAG_SCRIPT_AUTOEXEC; #endif - - G.log.level = 1; } void BKE_blender_globals_clear(void) diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index d2ada217f78..320a79c2f5f 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -18,6 +18,8 @@ * \ingroup RNA */ +#include <BLI_string.h> +#include <CLG_log.h> #include <limits.h> #include <stdlib.h> @@ -172,6 +17 @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs