lib/logstash/outputs/file.rb in logstash-output-file-0.1.1 vs lib/logstash/outputs/file.rb in logstash-output-file-0.1.2
- old
+ new
@@ -5,10 +5,11 @@
require "zlib"
# This output will write events to files on disk. You can use fields
# from the event as parts of the filename and/or path.
class LogStash::Outputs::File < LogStash::Outputs::Base
+ FIELD_REF = /%\{[^}]+\}/
config_name "file"
milestone 2
# The path to the file to write. Event fields can be used here,
@@ -76,11 +77,11 @@
private
def validate_path
root_directory = @path.split(File::SEPARATOR).select { |item| !item.empty? }.shift
- if (root_directory =~ /%\{[^}]+\}/) != nil
+ if (root_directory =~ FIELD_REF) != nil
@logger.error("File: The starting part of the path should not be dynamic.", :path => @path)
raise LogStash::ConfigurationError.new("The starting part of the path should not be dynamic.")
end
end
@@ -124,11 +125,11 @@
event.sprintf(@path)
end
private
def path_with_field_ref?
- path =~ /%\{[^}]+\}/
+ path =~ FIELD_REF
end
def format_message(event)
if @message_format
event.sprintf(@message_format)
@@ -136,11 +137,11 @@
event.to_json
end
end
def extract_file_root
- extracted_path = File.expand_path(path.gsub(/%{.+/, ''))
- Pathname.new(extracted_path).expand_path
+ parts = File.expand_path(path).split(File::SEPARATOR)
+ parts.take_while { |part| part !~ FIELD_REF }.join(File::SEPARATOR)
end
def teardown
@logger.debug("Teardown: closing files")
@files.each do |path, fd|