Sha256: 8717a9827efc5cb384fdb79ddca85abc5fba96d7d8f4a606f1a5bcd77af81f8f

Contents?: true

Size: 849 Bytes

Versions: 43

Compression:

Stored size: 849 Bytes

Contents

require 'logger'
require 'pathname'

module PactBroker

  module Logging

    # Need to make this configurable based on the calling app!
    LOG_DIR = Pathname.new(File.join(File.dirname(__FILE__), '..', '..', 'log')).cleanpath
    LOG_FILE_NAME = "#{ENV['RACK_ENV'] || 'development'}.log"

    def self.included(base)
      base.extend(self)
    end

    def logger= logger
      @@logger = logger
    end

    def log_error e, description = nil
      message = "#{e.class} #{e.message} #{e.backtrace.join("\n")}"
      message = "#{description} - #{message}" if description
      logger.error message
    end

    def logger
      @@logger ||= begin
        FileUtils.mkdir_p(LOG_DIR)
        logger = Logger.new(File.join(LOG_DIR, LOG_FILE_NAME))
        logger.level = Logger::DEBUG
        logger
      end
    end
  end

  include Logging
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
pact_broker-2.16.1 lib/pact_broker/logging.rb
pact_broker-2.16.0 lib/pact_broker/logging.rb
pact_broker-2.15.0 lib/pact_broker/logging.rb
pact_broker-2.14.0 lib/pact_broker/logging.rb
pact_broker-2.13.1 lib/pact_broker/logging.rb
pact_broker-2.13.0 lib/pact_broker/logging.rb
pact_broker-2.12.0 lib/pact_broker/logging.rb
pact_broker-2.11.0 lib/pact_broker/logging.rb
pact_broker-2.10.0 lib/pact_broker/logging.rb
pact_broker-2.9.0 lib/pact_broker/logging.rb
pact_broker-2.9.0.beta.5 lib/pact_broker/logging.rb
pact_broker-2.8.0.beta.5 lib/pact_broker/logging.rb
pact_broker-2.8.0.beta.4 lib/pact_broker/logging.rb
pact_broker-2.7.0.beta.3 lib/pact_broker/logging.rb
pact_broker-2.7.0.beta.2 lib/pact_broker/logging.rb
pact_broker-2.7.0.beta.1 lib/pact_broker/logging.rb
pact_broker-2.6.0 lib/pact_broker/logging.rb
pact_broker-2.5.1 lib/pact_broker/logging.rb
pact_broker-2.5.0 lib/pact_broker/logging.rb
pact_broker-2.4.2 lib/pact_broker/logging.rb