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
This commit is contained in:
John Cupitt 2017-08-04 18:01:19 +01:00
parent 3a29cea09f
commit 47a763209a
2 changed files with 24 additions and 0 deletions

View File

@ -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

View File

@ -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 );