Class: LogStashLogger::Device::File
- Defined in:
- lib/logstash-logger/device/file.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(opts) ⇒ File
constructor
A new instance of File.
- #open ⇒ Object
- #to_io ⇒ Object
Methods inherited from Base
#close, #close!, #flush, #reset, #unrecoverable_error?, #write, #write_batch, #write_one
Constructor Details
#initialize(opts) ⇒ File
Returns a new instance of File.
5 6 7 8 9 10 11 12 13 |
# File 'lib/logstash-logger/device/file.rb', line 5 def initialize(opts) super @path = opts[:path] || fail(ArgumentError, "Path is required") @shift_age = opts[:shift_age] @shift_size = opts[:shift_size] @shift_period_suffix = opts[:shift_period_suffix] @use_log_device = opts.key?(:shift_age) || opts.key?(:shift_size) || opts.key?(:shift_period_suffix) open end |
Instance Method Details
#open ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/logstash-logger/device/file.rb', line 15 def open unless ::File.exist? ::File.dirname @path ::FileUtils.mkdir_p ::File.dirname @path end if @use_log_device require 'logger' = { binmode: true } [:shift_age] = @shift_age unless @shift_age.nil? [:shift_size] = @shift_size unless @shift_size.nil? [:shift_period_suffix] = @shift_period_suffix unless @shift_period_suffix.nil? @io = ::Logger::LogDevice.new(@path, **) @io.dev.sync = self.sync unless self.sync.nil? else @io = ::File.open @path, ::File::WRONLY | ::File::APPEND | ::File::CREAT @io.binmode @io.sync = self.sync unless self.sync.nil? end end |
#to_io ⇒ Object
35 36 37 |
# File 'lib/logstash-logger/device/file.rb', line 35 def to_io @io.respond_to?(:dev) ? @io.dev : @io end |