lib/logstash/outputs/file.rb in logstash-output-file-4.2.3 vs lib/logstash/outputs/file.rb in logstash-output-file-4.2.4
- old
+ new
@@ -16,11 +16,11 @@
# codec => line { format => "custom format: %{message}"}
# }
# }
class LogStash::Outputs::File < LogStash::Outputs::Base
concurrency :shared
-
+
FIELD_REF = /%\{[^}]+\}/
config_name "file"
attr_reader :failure_path
@@ -46,11 +46,11 @@
# If the generated path is invalid, the events will be saved
# into this file and inside the defined path.
config :filename_failure, :validate => :string, :default => '_filepath_failures'
- # If the configured file is deleted, but an event is handled by the plugin,
+ # If the configured file is deleted, but an event is handled by the plugin,
# the plugin will recreate the file. Default => true
config :create_if_deleted, :validate => :boolean, :default => true
# Dir access mode to use. Note that due to the bug in jruby system umask
# is ignored on linux: https://github.com/jruby/jruby/issues/3426
@@ -80,11 +80,11 @@
def register
require "fileutils" # For mkdir_p
@files = {}
@io_mutex = Mutex.new
-
+
@path = File.expand_path(path)
validate_path
if path_with_field_ref?
@@ -139,22 +139,22 @@
fd.write(chunks.last)
else
# append to the file
chunks.each {|chunk| fd.write(chunk) }
end
- fd.flush
+ flush(fd)
end
-
+
close_stale_files
- end
+ end
end # def receive
public
def close
@io_mutex.synchronize do
@logger.debug("Close: closing files")
-
+
@files.each do |path, fd|
begin
fd.close
@logger.debug("Closed file #{path}", :fd => fd)
rescue Exception => e
@@ -178,12 +178,12 @@
file_output_path = @failure_path
elsif !@create_if_deleted && deleted?(file_output_path)
file_output_path = @failure_path
end
@logger.debug("File, writing event to file.", :filename => file_output_path)
-
- file_output_path
+
+ file_output_path
end
private
def generate_filepath(event)
event.sprintf(@path)
@@ -217,11 +217,11 @@
@files.each do |path, fd|
@logger.debug("Flushing file", :path => path, :fd => fd)
fd.flush
end
-
+
@last_flush_cycle = Time.now
end
# every 10 seconds or so (triggered by events, but if there are no events there's no point closing files anyway)
private
@@ -266,20 +266,20 @@
return @files[path] if cached?(path)
end
end
@logger.info("Opening file", :path => path)
-
+
dir = File.dirname(path)
if !Dir.exist?(dir)
@logger.info("Creating directory", :directory => dir)
if @dir_mode != -1
FileUtils.mkdir_p(dir, :mode => @dir_mode)
else
FileUtils.mkdir_p(dir)
end
end
-
+
# work around a bug opening fifos (bug JRUBY-6280)
stat = File.stat(path) rescue nil
if stat && stat.ftype == "fifo" && LogStash::Environment.jruby?
fd = java.io.FileWriter.new(java.io.File.new(path))
else