Module: GLib
- Extended by:
- FFI::Library
- Defined in:
- lib/vips.rb
Overview
This module uses FFI to make a simple layer over the glib and gobject libraries.
Constant Summary collapse
- G_FREE =
save the FFI::Function that attach will return ... we can use it directly as a param for callbacks
attach_function :g_free, [:pointer], :void
- LOG_FLAG_RECURSION =
log flags
1 << 0
- LOG_FLAG_FATAL =
1 << 1
- LOG_LEVEL_ERROR =
GLib log levels
1 << 2
- LOG_LEVEL_CRITICAL =
always fatal
1 << 3
- LOG_LEVEL_WARNING =
1 << 4
- LOG_LEVEL_MESSAGE =
1 << 5
- LOG_LEVEL_INFO =
1 << 6
- LOG_LEVEL_DEBUG =
1 << 7
- GLIB_TO_SEVERITY =
map glib levels to Logger::Severity
{ LOG_LEVEL_ERROR => Logger::ERROR, LOG_LEVEL_CRITICAL => Logger::FATAL, LOG_LEVEL_WARNING => Logger::WARN, LOG_LEVEL_MESSAGE => Logger::UNKNOWN, LOG_LEVEL_INFO => Logger::INFO, LOG_LEVEL_DEBUG => Logger::DEBUG }
- LOG_HANDLER =
module-level, so it's not GCd away
Proc.new do |domain, level, , user_data| @logger.log(GLIB_TO_SEVERITY[level], , domain) end
Class Attribute Summary collapse
-
.logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
Class Attribute Details
.logger ⇒ Object
Returns the value of attribute logger.
15 16 17 |
# File 'lib/vips.rb', line 15 def logger @logger end |
Class Method Details
.remove_log_handler ⇒ Object
73 74 75 76 77 78 |
# File 'lib/vips.rb', line 73 def self.remove_log_handler if @glib_log_handler_id != 0 and @glib_log_domain g_log_remove_handler @glib_log_domain, @glib_log_handler_id @glib_log_handler_id = nil end end |
.set_log_domain(domain) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/vips.rb', line 80 def self.set_log_domain domain GLib::remove_log_handler @glib_log_domain = domain # forward all glib logging output from this domain to a Ruby logger if @glib_log_domain # disable this feature for now # # libvips background worker threads can issue warnings, and # since the main thread is blocked waiting for libvips to come back # from an ffi call, you get a deadlock on the GIL # # to fix this, we need a way for g_log() calls from libvips workers # to be returned via the main thread # # @glib_log_handler_id = g_log_set_handler @glib_log_domain, # LOG_LEVEL_DEBUG | # LOG_LEVEL_INFO | # LOG_LEVEL_MESSAGE | # LOG_LEVEL_WARNING | # LOG_LEVEL_ERROR | # LOG_LEVEL_CRITICAL | # LOG_FLAG_FATAL | LOG_FLAG_RECURSION, # LOG_HANDLER, nil # we must remove any handlers on exit, since libvips may log stuff # on shutdown and we don't want LOG_HANDLER to be invoked # after Ruby has gone at_exit { GLib::remove_log_handler } end end |