class MiniMagick::Logger

Responsible for logging commands to stdout (activated when `MiniMagick.debug` is set to `true`). Implements a simplified Logger interface.

@private

Attributes

format[RW]

Public Class Methods

new(io) click to toggle source
# File lib/mini_magick/logger.rb, line 15
def initialize(io)
  @io     = io
  @format = "[%<duration>.2fs] %<command>s"
end

Public Instance Methods

benchmark(action) { |duration| ... } click to toggle source
# File lib/mini_magick/logger.rb, line 30
def benchmark(action)
  return_value = nil
  duration = Benchmark.realtime { return_value = action.call }
  yield duration
  return_value
end
debug(command, &action) click to toggle source
# File lib/mini_magick/logger.rb, line 20
def debug(command, &action)
  benchmark(action) do |duration|
    output(duration: duration, command: command) if MiniMagick.debug
  end
end
output(data) click to toggle source
# File lib/mini_magick/logger.rb, line 26
def output(data)
  printf @io, "#{format}\n", data
end