Sha256: b5307b07044c7274304f4335f51bcc0e628f68979c7d9e13404d2062ae467e08

Contents?: true

Size: 902 Bytes

Versions: 7

Compression:

Stored size: 902 Bytes

Contents

# frozen_string_literal: true

require "fileutils"

module Ductr
  module Log
    #
    # An output to write logs in a file
    #
    class FileOutput < StandardOutput
      #
      # Creates the output with the given formatter, path and options
      #
      # @param [::Logger::Formatter] formatter The formatter to use when writing logs
      # @param [String] path The path to write the logs
      # @param [Hash] **options The options to write files
      #
      # @see The ruby's logger documentation to get options documentation
      #
      def initialize(formatter, path:, **options) # rubocop:disable Lint/MissingSuper
        dir = File.dirname(path)
        FileUtils.mkdir_p(dir) unless File.directory?(dir)
        File.new(path, "w") unless File.exist?(path)

        @formatter = formatter.new
        @log_device = ::Logger::LogDevice.new path, **options
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ductr-0.2.3 lib/ductr/log/outputs/file_output.rb
ductr-0.2.2 lib/ductr/log/outputs/file_output.rb
ductr-0.2.1 lib/ductr/log/outputs/file_output.rb
ductr-0.2.0 lib/ductr/log/outputs/file_output.rb
ductr-0.1.2 lib/ductr/log/outputs/file_output.rb
ductr-0.1.1 lib/ductr/log/outputs/file_output.rb
ductr-0.1.0 lib/ductr/log/outputs/file_output.rb