2626 gobject_lib = _libvips .lib
2727
2828 # now check that the binary wrapper is for the same version of libvips that
29- # we find ourseleves linking to at runtime ... if it isn't, we must fall
29+ # we find ourseleves linking to at runtime ... if it isn't, we must fall
3030 # back to ABI mode
3131 lib_major = vips_lib .vips_version (0 )
3232 lib_minor = vips_lib .vips_version (1 )
3333 wrap_major = vips_lib .VIPS_MAJOR_VERSION
3434 wrap_minor = vips_lib .VIPS_MINOR_VERSION
35- logger .debug ('Module generated for libvips %s.%s' %
36- (wrap_major , wrap_minor ))
37- logger .debug ('Linked to libvips %s.%s' % (lib_major , lib_minor ))
35+ logger .debug ('Module generated for libvips %s.%s' %
36+ (wrap_major , wrap_minor ))
37+ logger .debug ('Linked to libvips %s.%s' % (lib_major , lib_minor ))
3838
3939 if wrap_major != lib_major or wrap_minor != lib_minor :
4040 raise Exception ('bad wrapper version' )
109109
110110 ffi .cdef (cdefs (features ))
111111
112+
112113from .error import *
113114
114115# redirect all vips warnings to logging
115116
116117class GLogLevelFlags (object ):
117- # log flags
118+ # log flags
118119 FLAG_RECURSION = 1 << 0
119120 FLAG_FATAL = 1 << 1
120121
121- # GLib log levels
122+ # GLib log levels
122123 LEVEL_ERROR = 1 << 2 # always fatal
123124 LEVEL_CRITICAL = 1 << 3
124125 LEVEL_WARNING = 1 << 4
@@ -127,14 +128,15 @@ class GLogLevelFlags(object):
127128 LEVEL_DEBUG = 1 << 7
128129
129130 LEVEL_TO_LOGGER = {
130- LEVEL_DEBUG : 10 ,
131- LEVEL_INFO : 20 ,
132- LEVEL_MESSAGE : 20 ,
133- LEVEL_WARNING : 30 ,
134- LEVEL_ERROR : 40 ,
135- LEVEL_CRITICAL : 50 ,
131+ LEVEL_DEBUG : 10 ,
132+ LEVEL_INFO : 20 ,
133+ LEVEL_MESSAGE : 20 ,
134+ LEVEL_WARNING : 30 ,
135+ LEVEL_ERROR : 40 ,
136+ LEVEL_CRITICAL : 50 ,
136137 }
137138
139+
138140if API_mode :
139141 @ffi .def_extern ()
140142 def _log_handler_callback (domain , level , message , user_data ):
@@ -151,16 +153,16 @@ def _log_handler_callback(domain, level, message, user_data):
151153 # keep a ref to the cb to stop it being GCd
152154 _log_handler_cb = ffi .callback ('GLogFunc' , _log_handler_callback )
153155
154- _log_handler_id = glib_lib .g_log_set_handler (_to_bytes ('VIPS' ),
155- GLogLevelFlags .LEVEL_DEBUG |
156- GLogLevelFlags .LEVEL_INFO |
157- GLogLevelFlags .LEVEL_MESSAGE |
158- GLogLevelFlags .LEVEL_WARNING |
159- GLogLevelFlags .LEVEL_CRITICAL |
160- GLogLevelFlags .LEVEL_ERROR |
161- GLogLevelFlags .FLAG_FATAL |
162- GLogLevelFlags .FLAG_RECURSION ,
163- _log_handler_cb , ffi .NULL )
156+ _log_handler_id = glib_lib .g_log_set_handler (_to_bytes ('VIPS' ),
157+ GLogLevelFlags .LEVEL_DEBUG |
158+ GLogLevelFlags .LEVEL_INFO |
159+ GLogLevelFlags .LEVEL_MESSAGE |
160+ GLogLevelFlags .LEVEL_WARNING |
161+ GLogLevelFlags .LEVEL_CRITICAL |
162+ GLogLevelFlags .LEVEL_ERROR |
163+ GLogLevelFlags .FLAG_FATAL |
164+ GLogLevelFlags .FLAG_RECURSION ,
165+ _log_handler_cb , ffi .NULL )
164166
165167# ffi doesn't like us looking up methods during shutdown: make a note of the
166168# remove handler here
@@ -176,6 +178,7 @@ def _remove_log_handler():
176178 _remove_handler (_to_bytes ('VIPS' ), _log_handler_id )
177179 _log_handler_id = None
178180
181+
179182atexit .register (_remove_log_handler )
180183
181184from .enums import *
0 commit comments