From 0cbbf158f90a68c84e52ca140b7a57b11eea6e5b Mon Sep 17 00:00:00 2001 From: Jeon Hee Chul Date: Tue, 11 Jun 2013 22:11:46 +0900 Subject: [PATCH] Add '--gst-debug-file' option to dump all GST_LOG into a given file Usage : gst-launch fakesrc ! fakesink --gst-debug-file=/tmp/gstlog This will generate /tmp/gstlog-{pid}-{timestamp} --- gst/gst.c | 39 ++++++++++++++++++++++++++++++++++++--- gst/gstinfo.c | 45 ++++++++++++++++++++++++++++++--------------- gst/gstinfo.h | 1 + 3 files changed, 67 insertions(+), 18 deletions(-) diff --git a/gst/gst.c b/gst/gst.c index 4b56ee9..5bf8845 100644 --- a/gst/gst.c +++ b/gst/gst.c @@ -92,7 +92,7 @@ * gst_version_string() returns a printable string. * * The gst_deinit() call is used to clean up all internal resources used - * by GStreamer. It is mostly used in unit tests + * by GStreamer. It is mostly used in unit tests * to check for leaks. * * Last reviewed on 2006-08-11 (0.10.10) @@ -119,7 +119,8 @@ #include "gst.h" #include - +#include +#include #define GST_CAT_DEFAULT GST_CAT_GST_INIT @@ -143,6 +144,8 @@ extern gboolean _priv_gst_disable_registry_update; extern const gchar *priv_gst_dump_dot_dir; #endif +extern gchar* _pri_gst_debug_file_path; + /* defaults */ /* set to TRUE when segfaults need to be left as is */ @@ -178,6 +181,7 @@ enum #ifndef GST_DISABLE_GST_DEBUG ARG_DEBUG_LEVEL, ARG_DEBUG, + ARG_DEBUG_FILE, ARG_DEBUG_DISABLE, ARG_DEBUG_NO_COLOR, ARG_DEBUG_HELP, @@ -327,6 +331,9 @@ gst_init_get_option_group (void) "specific levels for the individual categories. Example: " "GST_AUTOPLUG:5,GST_ELEMENT_*:3"), N_("LIST")}, + {"gst-debug-file", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) parse_goption_arg, + N_("Dump all logs into a given file."), + N_("FILE")}, {"gst-debug-no-color", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) parse_goption_arg, N_("Disable colored debugging output"), NULL}, @@ -928,6 +935,27 @@ parse_one_option (gint opt, const gchar * arg, GError ** err) case ARG_DEBUG: parse_debug_list (arg); break; + case ARG_DEBUG_FILE:{ + char* debug_file = NULL; + debug_file = arg; + if(debug_file) { + struct tm* tm; + time_t ctime; + time(&ctime); + tm = localtime(&ctime); + + _pri_gst_debug_file_path = g_strdup_printf("%s-%d-%d:%d:%d:%d:%d:%d", + debug_file, getpid(), + tm->tm_year+1900, + tm->tm_mon+1, + tm->tm_mday, + tm->tm_hour, + tm->tm_min, + tm->tm_sec ); + } + _gst_debug_redirect(); + break; + } case ARG_DEBUG_NO_COLOR: gst_debug_set_colored (FALSE); break; @@ -984,6 +1012,7 @@ parse_goption_arg (const gchar * opt, { "--gst-debug-level", ARG_DEBUG_LEVEL}, { "--gst-debug", ARG_DEBUG}, { + "--gst-debug-file", ARG_DEBUG_FILE}, { "--gst-debug-disable", ARG_DEBUG_DISABLE}, { "--gst-debug-no-color", ARG_DEBUG_NO_COLOR}, { "--gst-debug-help", ARG_DEBUG_HELP}, @@ -1020,7 +1049,7 @@ parse_goption_arg (const gchar * opt, * This function is therefore mostly used by testsuites and other memory * profiling tools. * - * After this call GStreamer (including this method) should not be used anymore. + * After this call GStreamer (including this method) should not be used anymore. */ void gst_deinit (void) @@ -1044,6 +1073,10 @@ gst_deinit (void) _priv_gst_plugin_paths = NULL; #endif + if(_pri_gst_debug_file_path) + g_free(_pri_gst_debug_file_path); + _pri_gst_debug_file_path = NULL; + clock = gst_system_clock_obtain (); gst_object_unref (clock); gst_object_unref (clock); diff --git a/gst/gstinfo.c b/gst/gstinfo.c index 266feed..c38972a 100644 --- a/gst/gstinfo.c +++ b/gst/gstinfo.c @@ -185,6 +185,7 @@ GST_DEBUG_CATEGORY_STATIC (_GST_CAT_DEBUG); * get the running time: GST_DEBUG_RUNNING_TIME */ GstClockTime _priv_gst_info_start_time; +gchar* _pri_gst_debug_file_path = NULL; #if 0 #if defined __sgi__ @@ -315,21 +316,7 @@ _gst_debug_init (void) { const gchar *env; - env = g_getenv ("GST_DEBUG_FILE"); - if (env != NULL && *env != '\0') { - if (strcmp (env, "-") == 0) { - log_file = stdout; - } else { - log_file = g_fopen (env, "w"); - if (log_file == NULL) { - g_printerr ("Could not open log file '%s' for writing: %s\n", env, - g_strerror (errno)); - log_file = stderr; - } - } - } else { - log_file = stderr; - } + _gst_debug_redirect(); /* get time we started for debugging messages */ _priv_gst_info_start_time = gst_util_get_timestamp (); @@ -432,6 +419,34 @@ _gst_debug_init (void) } } +void _gst_debug_redirect (void) +{ + const gchar *env; + + /* use local path first */ + if (_pri_gst_debug_file_path){ + env = _pri_gst_debug_file_path; + } else { + env = g_getenv ("GST_DEBUG_FILE"); + } + + if (env != NULL && *env != '\0') { + if (strcmp (env, "-") == 0) { + log_file = stdout; + } else { + log_file = g_fopen (env, "w"); + if (log_file == NULL) { + g_printerr ("Could not open log file '%s' for writing: %s\n", env, + g_strerror (errno)); + log_file = stderr; + } + } + } else { + log_file = stderr; + } +} + + /* we can't do this further above, because we initialize the GST_CAT_DEFAULT struct */ #define GST_CAT_DEFAULT _GST_CAT_DEBUG diff --git a/gst/gstinfo.h b/gst/gstinfo.h index f841cd7..6e54423 100644 --- a/gst/gstinfo.h +++ b/gst/gstinfo.h @@ -259,6 +259,7 @@ typedef void (*GstLogFunction) (GstDebugCategory * category, /* FIXME 0.11: move this into private headers */ void _gst_debug_init (void); +void _gst_debug_redirect (void); #ifdef GST_USING_PRINTF_EXTENSION -- 2.7.4