Sha256: abcf0a03ca53f8ab1711466c0a298151864c1b6d6583835ec73617663162cb50

Contents?: true

Size: 1.03 KB

Versions: 10

Compression:

Stored size: 1.03 KB

Contents

require 'pathname'
require 'semantic_logger'

module PactBroker
  module Logging

    def self.included(base)
      base.extend self
      base.extend SemanticLogger::Loggable::ClassMethods
      base.class_eval do
        # Returns [SemanticLogger::Logger] class level logger
        def self.logger
          require 'pact_broker/configuration'
          @logger ||= PactBroker.configuration.custom_logger || SemanticLogger[self]
        end

        # Replace instance class level logger
        def self.logger=(logger)
          @logger = logger
        end

        # Returns [SemanticLogger::Logger] instance level logger
        def logger
          @logger ||= self.class.logger
        end

        # Replace instance level logger
        def logger=(logger)
          @logger = logger
        end
      end
    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
  end

  include Logging
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
pact_broker-2.34.0 lib/pact_broker/logging.rb
pact_broker-2.33.0 lib/pact_broker/logging.rb
pact_broker-2.32.0 lib/pact_broker/logging.rb
pact_broker-2.31.0 lib/pact_broker/logging.rb
pact_broker-2.30.0 lib/pact_broker/logging.rb
pact_broker-2.29.0 lib/pact_broker/logging.rb
pact_broker-2.27.6 lib/pact_broker/logging.rb
pact_broker-2.27.5 lib/pact_broker/logging.rb
pact_broker-2.27.4 lib/pact_broker/logging.rb
pact_broker-2.27.3 lib/pact_broker/logging.rb