[gst-cvs] gstreamer: info: write debugging output to file if GST_DEBUG_FILE environment variable is set
Stefan Kost
ensonic at hora-obscura.de
Sat Aug 7 05:18:26 PDT 2010
Am 22.07.2010 02:13, schrieb Tim MXXller:
> Module: gstreamer
> Branch: master
> Commit: 9d4caf8d8c6dd0018258fe97451201a3790e6ca8
> URL: http://cgit.freedesktop.org/gstreamer/gstreamer/commit/?id=9d4caf8d8c6dd0018258fe97451201a3790e6ca8
>
> Author: Tim-Philipp Müller <tim.muller at collabora.co.uk>
> Date: Fri Jun 4 11:24:59 2010 +0100
>
> info: write debugging output to file if GST_DEBUG_FILE environment variable is set
>
> This changes behaviour slightly in that we no longer output things
> via g_printerr(), so any non-standard glib printerr handlers are no
> longer called when GST_DEBUG is enabled. However, this seems not
> really desirable in most cases anyway, and the GLib docs also say
> that libraries should not use g_printerr() for logging.
>
> Other stderr output (e.g. warnings, or application messages) will
> of course not be captured in the log file this way.
>
> GST_DEBUG_FILE=- will redirect debug output to stdout.
I would have appreciated a discussion before doing that change. It is creating
quite a mess in buzztards unit tests. I was:
1.) writing a different log file for each test binary
2.) using log handler to check for expected GST_ERROR / GST_WARNING lines.
My woraround for 1) is g_setenv("GST_DEBUG_FILE", "xxx", TRUE); before gst_init().
For 2.) my fate is to rewrite 40 tests.
Stefan
>
> ---
>
> gst/gstinfo.c | 42 ++++++++++++++++++++++++++++++++----------
> 1 files changed, 32 insertions(+), 10 deletions(-)
>
> diff --git a/gst/gstinfo.c b/gst/gstinfo.c
> index 02a2c94..b7a420d 100644
> --- a/gst/gstinfo.c
> +++ b/gst/gstinfo.c
> @@ -99,6 +99,8 @@
> # include <printf.h>
> #endif
> #include <stdio.h> /* fprintf */
> +#include <glib/gstdio.h>
> +#include <errno.h>
> #ifdef HAVE_UNISTD_H
> # include <unistd.h> /* getpid on UNIX */
> #endif
> @@ -264,6 +266,8 @@ static gboolean pretty_tags = PRETTY_TAGS_DEFAULT;
> static gint __default_level;
> static gint __use_color;
>
> +static FILE *log_file;
> +
> /* FIXME: export this? */
> gboolean
> _priv_gst_in_valgrind (void)
> @@ -308,6 +312,22 @@ _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;
> + }
> +
> g_atomic_int_set (&__default_level, GST_LEVEL_DEFAULT);
> g_atomic_int_set (&__use_color, 1);
>
> @@ -871,7 +891,9 @@ static const gchar *levelcolormap[GST_LEVEL_COUNT] = {
> *
> * The default logging handler used by GStreamer. Logging functions get called
> * whenever a macro like GST_DEBUG or similar is used. This function outputs the
> - * message and additional info using the glib error handler.
> + * message and additional info to stderr (or the log file specified via the
> + * GST_DEBUG_FILE environment variable).
> + *
> * You can add other handlers by using gst_debug_add_log_function().
> * And you can remove this handler by calling
> * gst_debug_remove_log_function(gst_debug_log_default);
> @@ -916,7 +938,7 @@ gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
> levelcolor = levelcolormap[level];
>
> #define PRINT_FMT " %s"PID_FMT"%s "PTR_FMT" %s%s%s %s"CAT_FMT"%s %s\n"
> - g_printerr ("%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed),
> + g_fprintf (log_file, "%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed),
> pidcolor, pid, clear, g_thread_self (), levelcolor,
> gst_debug_level_get_name (level), clear, color,
> gst_debug_category_get_name (category), file, line, function, obj,
> @@ -933,31 +955,31 @@ gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
> SetConsoleTextAttribute (GetStdHandle (STD_ERROR_HANDLE), (c));
> g_static_mutex_lock (&win_print_mutex);
> /* timestamp */
> - g_printerr ("%" GST_TIME_FORMAT " ", GST_TIME_ARGS (elapsed));
> + g_fprintf (log_file, "%" GST_TIME_FORMAT " ", GST_TIME_ARGS (elapsed));
> /* pid */
> SET_COLOR (available_colors[pid % G_N_ELEMENTS (available_colors)]);
> - g_printerr (PID_FMT, pid);
> + g_fprintf (log_file, PID_FMT, pid);
> /* thread */
> SET_COLOR (clear);
> - g_printerr (" " PTR_FMT " ", g_thread_self ());
> + g_fprintf (log_file, " " PTR_FMT " ", g_thread_self ());
> /* level */
> SET_COLOR (levelcolormap[level]);
> - g_printerr ("%s ", gst_debug_level_get_name (level));
> + g_fprintf (log_file, "%s ", gst_debug_level_get_name (level));
> /* category */
> SET_COLOR (gst_debug_construct_win_color (gst_debug_category_get_color
> (category)));
> - g_printerr (CAT_FMT, gst_debug_category_get_name (category),
> + g_fprintf (log_file, CAT_FMT, gst_debug_category_get_name (category),
> file, line, function, obj);
> /* message */
> SET_COLOR (clear);
> - g_printerr (" %s\n", gst_debug_message_get (message));
> + g_fprintf (log_file, " %s\n", gst_debug_message_get (message));
> g_static_mutex_unlock (&win_print_mutex);
> #endif
> } else {
> /* no color, all platforms */
> #define PRINT_FMT " "PID_FMT" "PTR_FMT" %s "CAT_FMT" %s\n"
> - g_printerr ("%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed), pid,
> - g_thread_self (), gst_debug_level_get_name (level),
> + g_fprintf (log_file, "%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed),
> + pid, g_thread_self (), gst_debug_level_get_name (level),
> gst_debug_category_get_name (category), file, line, function, obj,
> gst_debug_message_get (message));
> #undef PRINT_FMT
>
>
>
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
>
>
>
> _______________________________________________
> gstreamer-cvs mailing list
> gstreamer-cvs at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gstreamer-cvs
More information about the Gstreamer-commits
mailing list