Sha256: 2b3b44fafca6aa0d69bd5042d349a8309bcb51e81baefbf98597dfc27e0116c5

Contents?: true

Size: 1.1 KB

Versions: 5

Compression:

Stored size: 1.1 KB

Contents

require 'berkeley_library/logging/env'
require 'berkeley_library/logging/events'
require 'berkeley_library/logging/formatters'
require 'berkeley_library/logging/loggers'

module BerkeleyLibrary
  module Logging
    class Configurator
      class << self

        def configure(config)
          configure_lograge(config)

          logger = Loggers.new_default_logger(config)
          logger.info("Custom logger initialized for environment #{Logging.env.inspect}")
          configure_webpacker(logger)
          config.logger = logger
        end

        private

        def configure_lograge(config)
          return unless config.respond_to?(:lograge)

          config.lograge.tap do |lograge|
            lograge.enabled = true
            lograge.custom_options = Events.extract_data_for_lograge
            lograge.formatter = Formatters.lograge_formatter
          end
        end

        def configure_webpacker(logger)
          return unless defined?(::Webpacker)

          logger.info('Using custom logger for Webpacker')
          ::Webpacker::Instance.logger = logger
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
berkeley_library-logging-0.2.4 lib/berkeley_library/logging/configurator.rb
berkeley_library-logging-0.2.3 lib/berkeley_library/logging/configurator.rb
berkeley_library-logging-0.2.2 lib/berkeley_library/logging/configurator.rb
berkeley_library-logging-0.2.1 lib/berkeley_library/logging/configurator.rb
berkeley_library-logging-0.2.0 lib/berkeley_library/logging/configurator.rb