From 47a763209ac2d8c4183543539e7daed40330e0b6 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 4 Aug 2017 18:01:19 +0100 Subject: [PATCH] hide warnings if VIPS_WARNING is defined If VIPS_WARNING is defined, suppress all warning messages from vips by installing a null log handler. Libraries should not call g_log_set_handler(), it is supposed to be for the application layer, but this can be awkward to set up if you are using libvips from something like Ruby. This env var hack is a workaround. see https://github.com/jcupitt/ruby-vips/issues/119 see https://github.com/jcupitt/libvips/issues/544 --- ChangeLog | 1 + libvips/iofuncs/init.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/ChangeLog b/ChangeLog index 6f1002a0..aa5ee3d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 2/8/17 started 8.5.8 - fix transparency detection in merge, thanks Haida +- define env var VIPS_WARNING to hide warning messages 9/6/17 started 8.5.7 - better smartcrop diff --git a/libvips/iofuncs/init.c b/libvips/iofuncs/init.c index a606f8a4..f7657e6a 100644 --- a/libvips/iofuncs/init.c +++ b/libvips/iofuncs/init.c @@ -26,6 +26,8 @@ * constructed before we go parallel * 18/9/16 * - call _setmaxstdio() on win32 + * 4/8/17 + * - hide warnings is VIPS_WARNING is set */ /* @@ -241,6 +243,15 @@ vips_load_plugins( const char *fmt, ... ) return( result ); } +/* Install this log handler to hide warning messages. + */ +static void +empty_log_handler( const gchar *log_domain, GLogLevelFlags log_level, + const gchar *message, gpointer user_data ) +{ +} + + /** * vips_init: * @argv0: name of application @@ -442,6 +453,18 @@ vips_init( const char *argv0 ) done = TRUE; + /* If VIPS_WARNING is defined, suppress all warning messages from vips. + * + * Libraries should not call g_log_set_handler(), it is + * supposed to be for the application layer, but this can be awkward to + * set up if you are using libvips from something like Ruby. Allow this + * env var hack as a workaround. + */ + if( g_getenv( "VIPS_WARNING" ) || + g_getenv( "IM_WARNING" ) ) + g_log_set_handler( "VIPS", G_LOG_LEVEL_WARNING, + empty_log_handler, NULL ); + vips__thread_gate_stop( "init: startup" ); return( 0 );