Sha256: 4e70b904cbd6a96816b94cde6264786a07d099314fe745a451af8e93ea5a9672

Contents?: true

Size: 830 Bytes

Versions: 3

Compression:

Stored size: 830 Bytes

Contents

require 'logger'
require 'logme/configuration'
require 'logme/net_http_formatter'

module LogMe
  attr_writer :log_enabled
  attr_writer :log_level
  attr_writer :log_label
  attr_writer :logger

  def log_enabled?
    @log_enabled != false
  end

  def log_level
    @log_level ||= :info
  end

  def log_label
    @log_label ||= self.name
  end

  def logger
    @logger ||= ::Logger.new STDOUT
  end

  def log(message)
    logger.send log_level, "[#{log_label}] #{message}\n" if log_enabled?
  end

  def log_request(request, url)
    log formatter.format_request(request, url)
  end

  def log_response(response)
    log formatter.format_response(response)
  end

  def self.extended(base)
    base.send :extend, LogMe::Configuration
  end

  private

  def formatter
    @formatter ||= LogMe::NetHttpFormatter.new
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
log-me-0.0.8 lib/log-me.rb
log-me-0.0.7 lib/log-me.rb
log-me-0.0.6 lib/log-me.rb