Class: Ductr::Log::FileOutput

Inherits:
StandardOutput show all
Defined in:
lib/ductr/log/outputs/file_output.rb

Overview

An output to write logs in a file

Constant Summary

Constants inherited from StandardOutput

StandardOutput::SEVERITY_LABELS

Instance Method Summary collapse

Methods inherited from StandardOutput

#write

Constructor Details

#initialize(formatter, path:, **options) ⇒ FileOutput

Creates the output with the given formatter, path and options

Parameters:

  • formatter (::Logger::Formatter)

    The formatter to use when writing logs

  • path (String)

    The path to write the logs

  • **options (Hash)

    The options to write files

See Also:

  • ruby's logger documentation to get options documentation


20
21
22
23
24
25
26
27
# File 'lib/ductr/log/outputs/file_output.rb', line 20

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