Sha256: 5f9d3eb299880dc407c26d4f362ee1f34c0616cff756ff21e952134dcf227a81

Contents?: true

Size: 853 Bytes

Versions: 1

Compression:

Stored size: 853 Bytes

Contents

# frozen_string_literal: true

module ClearLogic
  module Logger
    class Adapter
      attr_reader :service_class, :logger_class, :log_path

      def initialize(service_class)
        @service_class = service_class
        @logger_class = service_class.logger_class
        @log_path = service_class.logger_options[:log_path] || default_log_path
      end

      def logger
        @logger ||= create_logger
      end

      private

      def create_logger
        system('mkdir', '-p', path) unless Dir.exist?(path)

        logger_class.new(log_path)
      end

      def path
        File.dirname(log_path)
      end

      def default_log_path
        file_name = Dry::Inflector.new.underscore(service_class.name.gsub('::', '/'))
        File.join(ENV['BUNDLE_GEMFILE'], "log/#{file_name}.log").gsub!('Gemfile/', '')
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
clear_logic-0.1.1 lib/clear_logic/logger/adapter.rb