Sha256: de7425ab60df0d07cc75281c3d67b76aa1192062f58ef196b536e3a6feae0aec

Contents?: true

Size: 843 Bytes

Versions: 38

Compression:

Stored size: 843 Bytes

Contents

require 'json'

module Roqua
  class LogWrapper
    attr_reader :logger

    def initialize(logger)
      @logger  = logger
    end

    def add(level, message, options = {})
      logger.send(level, "#{Roqua.appname}.#{message} #{options.to_json}".strip)
    end

    [:fatal, :error, :warn, :info, :debug].each do |level|
      define_method(level) do |*args|
        add(level, *args)
      end
    end

    def lifecycle(message, options = {})
      started_at = Time.now.to_f
      info("#{message}:started", options)
      value = yield
      finished_at = Time.now.to_f
      duration = finished_at - started_at
      info("#{message}:finished", {duration: duration}.merge(options))
      value
    rescue => e
      error("#{message}:failed", {exception: e.class.name, message: e.message}.merge(options))
      raise
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
roqua-support-0.4.6 lib/roqua/support/log_wrapper.rb
roqua-support-0.4.5 lib/roqua/support/log_wrapper.rb
roqua-support-0.4.4 lib/roqua/support/log_wrapper.rb
roqua-support-0.4.3 lib/roqua/support/log_wrapper.rb
roqua-support-0.4.2 lib/roqua/support/log_wrapper.rb
roqua-support-0.4.1 lib/roqua/support/log_wrapper.rb
roqua-support-0.4.0 lib/roqua/support/log_wrapper.rb
roqua-support-0.3.5 lib/roqua/support/log_wrapper.rb
roqua-support-0.3.4 lib/roqua/support/log_wrapper.rb
roqua-support-0.3.3 lib/roqua/support/log_wrapper.rb
roqua-support-0.3.2 lib/roqua/support/log_wrapper.rb
roqua-support-0.3.1 lib/roqua/support/log_wrapper.rb
roqua-support-0.3.0 lib/roqua/support/log_wrapper.rb
roqua-support-0.1.34 lib/roqua/support/log_wrapper.rb
roqua-support-0.1.33 lib/roqua/support/log_wrapper.rb
roqua-support-0.1.32 lib/roqua/support/log_wrapper.rb
roqua-support-0.1.31 lib/roqua/support/log_wrapper.rb
roqua-support-0.1.30 lib/roqua/support/log_wrapper.rb
roqua-support-0.1.29 lib/roqua/support/log_wrapper.rb
roqua-support-0.1.28 lib/roqua/support/log_wrapper.rb