summaryrefslogtreecommitdiff
path: root/tumbler
diff options
context:
space:
mode:
authorGaël Bonithon <gael@xfce.org>2021-12-27 12:53:45 +0100
committerGaël Bonithon <gael@xfce.org>2021-12-27 13:11:20 +0100
commit3ea0a2d0f93f71e69c7b5db39e7c3a72dfea918a (patch)
tree0109a3ffaee681a20f9d2964a112a95508109714 /tumbler
parent32fb595aff6fbc6e37656d510bbccb46e9c1af9e (diff)
downloadtumbler-3ea0a2d0f93f71e69c7b5db39e7c3a72dfea918a.tar.gz
Reserve some third-party API messages to debug logging
FFmpegthumbnailer is known to be really verbose, and we don't have a priori control on the messages that can be displayed by external thumbnailers (it can be in particular FFmpegthumbnailer). Fixes #10, related to #29.
Diffstat (limited to 'tumbler')
-rw-r--r--tumbler/tumbler-util.c37
-rw-r--r--tumbler/tumbler-util.h2
2 files changed, 39 insertions, 0 deletions
diff --git a/tumbler/tumbler-util.c b/tumbler/tumbler-util.c
index 04c434d..cfc1172 100644
--- a/tumbler/tumbler-util.c
+++ b/tumbler/tumbler-util.c
@@ -85,6 +85,43 @@ tumbler_util_dump_strv (const gchar *log_domain,
+/*
+ * This is intended to be used around too verbose third-party APIs we can't silence by
+ * another means:
+ * tumbler_util_toggle_stderr (G_LOG_DOMAIN);
+ * … = too_verbose_api (…);
+ * tumbler_util_toggle_stderr (G_LOG_DOMAIN);
+ * When debug logging is enabled, it does nothing.
+ */
+void
+tumbler_util_toggle_stderr (const gchar *log_domain)
+{
+ static gint stderr_save = -2;
+
+ /* do nothing in case of previous error or if debug logging is enabled */
+ if (stderr_save == -1 || tumbler_util_is_debug_logging_enabled (log_domain))
+ return;
+
+ /* redirect stderr to /dev/null */
+ if (stderr_save == -2)
+ {
+ fflush (stderr);
+ stderr_save = dup (STDERR_FILENO);
+ if (stderr_save != -1 && freopen ("/dev/null", "a", stderr) == NULL)
+ stderr_save = -1;
+ }
+ /* restore stderr to stderr_save */
+ else
+ {
+ fflush (stderr);
+ stderr_save = dup2 (stderr_save, STDERR_FILENO);
+ if (stderr_save != -1)
+ stderr_save = -2;
+ }
+}
+
+
+
gchar **
tumbler_util_get_supported_uri_schemes (void)
{
diff --git a/tumbler/tumbler-util.h b/tumbler/tumbler-util.h
index 20a0cc3..24c7d29 100644
--- a/tumbler/tumbler-util.h
+++ b/tumbler/tumbler-util.h
@@ -34,6 +34,8 @@ void tumbler_util_dump_strv (const gchar *log_domain,
const gchar *label,
const gchar *const *strv);
+void tumbler_util_toggle_stderr (const gchar *log_domain);
+
gchar **tumbler_util_get_supported_uri_schemes (void) G_GNUC_MALLOC;
GKeyFile *tumbler_util_get_settings (void) G_GNUC_MALLOC;