Sha256: 4f6368dee060cfba3c8af6079d254f4412fd4215b0ba4fdd8d3bdb30ba86c2b6

Contents?: true

Size: 1003 Bytes

Versions: 23

Compression:

Stored size: 1003 Bytes

Contents

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength
require "forwardable"

class Simple::CLI::Logger::Adapter
  def initialize(logger)
    @logger = logger
  end

  LOGGER_METHODS = [
    :debug, :info, :warn, :error, :fatal,
    :debug?, :info?, :warn?, :error?, :fatal?,
    :level, :level=
  ]

  extend Forwardable
  delegate LOGGER_METHODS => :@logger

  def success(msg, *args, &block)
    if @logger.respond_to?(:success)
      @logger.send :success, msg, *args, &block
    else
      info "success: #{msg}", *args, &block
    end
  end

  def benchmark(msg, *args, &block)
    _ = block

    severity = :warn
    if msg.is_a?(Symbol)
      severity, msg = msg, args.shift
    end

    start = Time.now
    r = yield

    msg += ": #{(1000 * (Time.now - start)).to_i} msecs."
    send severity, msg, *args

    r
  rescue StandardError
    msg += "raises #{$!.class.name} after #{(1000 * (Time.now - start)).to_i} msecs."
    send severity, msg, *args
    raise $!
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
simple-cli-0.4.2 lib/simple/cli/logger/adapter.rb
simple-cli-0.4.1 lib/simple/cli/logger/adapter.rb
simple-cli-0.4.0 lib/simple/cli/logger/adapter.rb
simple-cli-0.3.13 lib/simple/cli/logger/adapter.rb
simple-cli-0.3.12 lib/simple/cli/logger/adapter.rb
simple-cli-0.2.28 lib/simple/cli/logger/adapter.rb
simple-cli-0.3.11 lib/simple/cli/logger/adapter.rb
simple-cli-0.3.10 lib/simple/cli/logger/adapter.rb
simple-cli-0.3.9 lib/simple/cli/logger/adapter.rb
simple-cli-0.3.8 lib/simple/cli/logger/adapter.rb
simple-cli-0.3.7 lib/simple/cli/logger/adapter.rb
simple-cli-0.3.5 lib/simple/cli/logger/adapter.rb
simple-cli-0.3.4 lib/simple/cli/logger/adapter.rb
simple-cli-0.3.3 lib/simple/cli/logger/adapter.rb
simple-cli-0.3.0 lib/simple/cli/logger/adapter.rb
simple-cli-0.2.23 lib/simple/cli/logger/adapter.rb
simple-cli-0.2.22 lib/simple/cli/logger/adapter.rb
simple-cli-0.2.21 lib/simple/cli/logger/adapter.rb
simple-cli-0.2.20 lib/simple/cli/logger/adapter.rb
simple-cli-0.2.19 lib/simple/cli/logger/adapter.rb