Class: LogStashLogger::Device::File

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash-logger/device/file.rb

Instance Attribute Summary

Attributes inherited from Base

#io, #sync

Instance Method Summary collapse

Methods inherited from Base

#close, #flush, #to_io, #write

Constructor Details

#initialize(opts) ⇒ File

Returns a new instance of File.



6
7
8
9
10
# File 'lib/logstash-logger/device/file.rb', line 6

def initialize(opts)
  super
  @path = opts[:path] || fail(ArgumentError, "Path is required")
  open
end

Instance Method Details

#openObject



12
13
14
15
16
17
18
19
20
# File 'lib/logstash-logger/device/file.rb', line 12

def open
  unless ::File.exist? ::File.dirname @path
    ::FileUtils.mkdir_p ::File.dirname @path
  end

  @io = ::File.open @path, ::File::WRONLY | ::File::APPEND | ::File::CREAT
  @io.binmode
  @io.sync = self.sync
end