summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim@centricular.com>2015-03-05 17:54:04 +0000
committerTim-Philipp Müller <tim@centricular.com>2015-03-05 17:57:58 +0000
commit5764316a8e5ee227fbd1255927bbe5d3f9ab3b4a (patch)
treee739cba9717b9f6d509f7f6756776f82abfbf42d
parent6cbe86dc589d381a324a05c522096c38f73608a1 (diff)
info: move __FILE__ path shortening into default log handler
Instead of always shortening the __FILE__ path, even if the log message is not actually printed, which might happen if the log level is activated but the category is not, only shorten the path if we're actually going to output it and if it looks like it needs shortening. Log handlers had no guarantee that they would get a name instead of a path anyway on any architecture, so it shouldn't be a problem. https://bugzilla.gnome.org/show_bug.cgi?id=745213
-rw-r--r--gst/gstinfo.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/gst/gstinfo.c b/gst/gstinfo.c
index f94578657..a506823d4 100644
--- a/gst/gstinfo.c
+++ b/gst/gstinfo.c
@@ -495,11 +495,6 @@ gst_debug_log_valist (GstDebugCategory * category, GstDebugLevel level,
g_return_if_fail (function != NULL);
g_return_if_fail (format != NULL);
- /* The predefined macro __FILE__ is always the exact path given to the
- * compiler with MSVC, which may or may not be the basename. We work
- * around it at runtime to improve the readability. */
- file = gst_path_basename (file);
-
message.message = NULL;
message.format = format;
G_VA_COPY (message.arguments, args);
@@ -991,10 +986,20 @@ gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
gchar *obj = NULL;
GstDebugColorMode color_mode;
FILE *log_file = user_data ? user_data : stderr;
+ gchar c;
if (level > gst_debug_category_get_threshold (category))
return;
+ /* __FILE__ might be a file name or an absolute path or a
+ * relative path, irrespective of the exact compiler used,
+ * in which case we want to shorten it to the filename for
+ * readability. */
+ c = file[0];
+ if (c == '.' || c == '/' || c == '\\' || (c != '\0' && file[1] == ':')) {
+ file = gst_path_basename (file);
+ }
+
pid = getpid ();
color_mode = gst_debug_get_color_mode ();