Skip to content

Fix log format in opening file #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions lib/logstash/outputs/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# }
class LogStash::Outputs::File < LogStash::Outputs::Base
concurrency :shared

FIELD_REF = /%\{[^}]+\}/

config_name "file"
Expand Down Expand Up @@ -50,7 +50,7 @@ class LogStash::Outputs::File < LogStash::Outputs::Base
# 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

Expand All @@ -74,7 +74,7 @@ def register

@files = {}
@io_mutex = Mutex.new

@path = File.expand_path(path)

validate_path
Expand Down Expand Up @@ -133,16 +133,16 @@ def multi_receive_encoded(events_and_encoded)
chunks.each {|chunk| fd.write(chunk) }
fd.flush
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
Expand Down Expand Up @@ -170,8 +170,8 @@ def event_path(event)
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
Expand Down Expand Up @@ -209,7 +209,7 @@ def flush_pending_files
@logger.debug("Flushing file", :path => path, :fd => fd)
fd.flush
end

@last_flush_cycle = Time.now
end

Expand Down Expand Up @@ -257,8 +257,8 @@ def open(path)
end
end

@logger.info("Opening file", :path => path)
@logger.info("Opening file #{path}")

dir = File.dirname(path)
if !Dir.exist?(dir)
@logger.info("Creating directory", :directory => dir)
Expand All @@ -268,7 +268,7 @@ def open(path)
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?
Expand Down