Sha256: bbf7ad70e9ba0f4664b1352d9fb57f28bc49d309564e9ab815b2f402fbbeff99

Contents?: true

Size: 1.08 KB

Versions: 8

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require 'logger'
require 'yaml'
require 'singleton'
require 'active_support/inflector'

module Ditty
  module Services
    class Logger
      include Singleton

      CONFIG = './config/logger.yml'.freeze
      attr_reader :loggers

      def initialize
        @loggers = []
        config.each do |values|
          klass = values['class'].constantize
          opts = values['options'] || nil
          logger = klass.new(opts)
          if values['level']
            logger.level = klass.const_get(values['level'].to_sym)
          end
          @loggers << logger
        end
      end

      def method_missing(method, *args, &block)
        loggers.each { |logger| logger.send(method, *args, &block) }
      end

      def respond_to_missing?(method, _include_private = false)
        loggers.any? { |logger| logger.respond_to?(method) }
      end

      private

      def config
        @config ||= File.exist?(CONFIG) ? YAML.load_file(CONFIG) : default
      end

      def default
        [{ 'name' => 'default', 'class' => 'Logger' }]
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ditty-0.4.0 lib/ditty/services/logger.rb
ditty-0.3.3 lib/ditty/services/logger.rb
ditty-0.3.2 lib/ditty/services/logger.rb
ditty-0.3.1 lib/ditty/services/logger.rb
ditty-0.3.0 lib/ditty/services/logger.rb
ditty-0.2.2 lib/ditty/services/logger.rb
ditty-0.2.1 lib/ditty/services/logger.rb
ditty-0.2.0 lib/ditty/services/logger.rb