Module: GLib

Extended by:
FFI::Library
Defined in:
lib/vips.rb

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, message, _user_data|
  @logger.log(GLIB_TO_SEVERITY[level], message, domain)
end

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject

Returns the value of attribute logger.



38
39
40
# File 'lib/vips.rb', line 38

def logger
  @logger
end

Class Method Details

.remove_log_handlerObject



90
91
92
93
94
95
# File 'lib/vips.rb', line 90

def self.remove_log_handler
  if @glib_log_handler_id != 0 && @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



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/vips.rb', line 97

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