[Bf-blender-cvs] [db8e7f9780f] master: Logging: add argument --log-show-basename

Campbell Barton noreply at git.blender.org
Sat Mar 31 15:30:30 CEST 2018


Commit: db8e7f9780f9148704a986290b9493e27b350fe4
Author: Campbell Barton
Date:   Sat Mar 31 15:27:06 2018 +0200
Branches: master
https://developer.blender.org/rBdb8e7f9780f9148704a986290b9493e27b350fe4

Logging: add argument --log-show-basename

Optionally strips leading path from filenames when logging.

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

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 b0d77281445..a6c66114a5f 100644
--- a/intern/clog/CLG_log.h
+++ b/intern/clog/CLG_log.h
@@ -144,6 +144,7 @@ void CLG_init(void);
 void CLG_exit(void);
 
 void CLG_output_set(void *file_handle);
+void CLG_output_use_basename_set(bool value);
 void CLG_fatal_fn_set(void (*fatal_fn)(void *file_handle));
 
 void CLG_type_filter_include(const char *type_filter, int type_filter_len);
diff --git a/intern/clog/clog.c b/intern/clog/clog.c
index f82e6b3b4a1..37dadb69fca 100644
--- a/intern/clog/clog.c
+++ b/intern/clog/clog.c
@@ -43,6 +43,12 @@
 #define STREQ(a, b) (strcmp(a, b) == 0)
 #define STREQLEN(a, b, n) (strncmp(a, b, n) == 0)
 
+#ifdef _WIN32
+#  define PATHSEP_CHAR '\\'
+#else
+#  define PATHSEP_CHAR '/'
+#endif
+
 /* -------------------------------------------------------------------- */
 /** \name Internal Types
  * \{ */
@@ -59,6 +65,7 @@ typedef struct CLogContext {
 	/* exclude, include filters.  */
 	CLG_IDFilter *filters[2];
 	bool use_color;
+	bool use_basename;
 
 	/** Borrowed, not owned. */
 	FILE *output;
@@ -353,9 +360,23 @@ static void write_type(CLogStringBuf *cstr, CLG_LogType *lg)
 	clg_str_append(cstr, "): ");
 }
 
-static void write_file_line_fn(CLogStringBuf *cstr, const char *file_line, const char *fn)
+static void write_file_line_fn(CLogStringBuf *cstr, const char *file_line, const char *fn, const bool use_basename)
 {
-	clg_str_append(cstr, file_line);
+	uint file_line_len = strlen(file_line);
+	if (use_basename) {
+		uint file_line_offset = file_line_len;
+		while (file_line_offset-- > 0) {
+			if (file_line[file_line_offset] == PATHSEP_CHAR) {
+				file_line_offset++;
+				break;
+			}
+		}
+		file_line += file_line_offset;
+		file_line_len -= file_line_offset;
+	}
+	clg_str_append_with_len(cstr, file_line, file_line_len);
+
+
 	clg_str_append(cstr, " ");
 	clg_str_append(cstr, fn);
 	clg_str_append(cstr, ": ");
@@ -373,7 +394,7 @@ void CLG_log_str(
 	write_type(&cstr, lg);
 
 	{
-		write_file_line_fn(&cstr, file_line, fn);
+		write_file_line_fn(&cstr, file_line, fn, lg->ctx->use_basename);
 		clg_str_append(&cstr, message);
 	}
 	clg_str_append(&cstr, "\n");
@@ -397,12 +418,11 @@ void CLG_logf(
 	char cstr_stack_buf[CLOG_BUF_LEN_INIT];
 	clg_str_init(&cstr, cstr_stack_buf, sizeof(cstr_stack_buf));
 
-	// FILE *fh = lg->ctx->output;
 	write_severity(&cstr, severity, lg->ctx->use_color);
 	write_type(&cstr, lg);
 
 	{
-		write_file_line_fn(&cstr, file_line, fn);
+		write_file_line_fn(&cstr, file_line, fn, lg->ctx->use_basename);
 
 		va_list ap;
 		va_start(ap, fmt);
@@ -436,6 +456,11 @@ static void CLG_ctx_output_set(CLogContext *ctx, void *file_handle)
 #endif
 }
 
+static void CLG_ctx_output_use_basename_set(CLogContext *ctx, bool value)
+{
+	ctx->use_basename = value;
+}
+
 /** Action on fatal severity. */
 static void CLG_ctx_fatal_fn_set(CLogContext *ctx, void (*fatal_fn)(void *file_handle))
 {
@@ -520,6 +545,12 @@ void CLG_output_set(void *file_handle)
 	CLG_ctx_output_set(g_ctx, file_handle);
 }
 
+void CLG_output_use_basename_set(bool value)
+{
+	CLG_ctx_output_use_basename_set(g_ctx, value);
+}
+
+
 void CLG_fatal_fn_set(void (*fatal_fn)(void *file_handle))
 {
 	CLG_ctx_fatal_fn_set(g_ctx, fatal_fn);
diff --git a/source/creator/creator_args.c b/source/creator/creator_args.c
index b7150bca47f..d4af3cd6b09 100644
--- a/source/creator/creator_args.c
+++ b/source/creator/creator_args.c
@@ -535,6 +535,7 @@ static int arg_handle_print_help(int UNUSED(argc), const char **UNUSED(argv), vo
 	printf("Logging Options:\n");
 	BLI_argsPrintArgDoc(ba, "--log");
 	BLI_argsPrintArgDoc(ba, "--log-level");
+	BLI_argsPrintArgDoc(ba, "--log-show-basename");
 	BLI_argsPrintArgDoc(ba, "--log-file");
 
 	printf("\n");
@@ -732,6 +733,15 @@ static int arg_handle_log_level_set(int argc, const char **argv, void *UNUSED(da
 	}
 }
 
+static const char arg_handle_log_show_basename_set_doc[] =
+"\n\tOnly show file name in output (not the leading path)."
+;
+static int arg_handle_log_show_basename_set(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
+{
+	CLG_output_use_basename_set(true);
+	return 0;
+}
+
 static const char arg_handle_log_file_set_doc[] =
 "<filename>\n"
 "\n"
@@ -1931,6 +1941,7 @@ void main_args_setup(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
 
 	BLI_argsAdd(ba, 1, NULL, "--log", CB(arg_handle_log_set), ba);
 	BLI_argsAdd(ba, 1, NULL, "--log-level", CB(arg_handle_log_level_set), ba);
+	BLI_argsAdd(ba, 1, NULL, "--log-show-basename", CB(arg_handle_log_show_basename_set), ba);
 	BLI_argsAdd(ba, 1, NULL, "--log-file", CB(arg_handle_log_file_set), ba);
 
 	BLI_argsAdd(ba, 1, "-d", "--debug", CB(arg_handle_debug_mode_set), ba);



More information about the Bf-blender-cvs mailing list