Skip to content

Commit

Permalink
add delimiter and fix specs on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jsvd authored and jordansissel committed Feb 20, 2015
1 parent e434d42 commit 4b8e926
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
4 changes: 4 additions & 0 deletions lib/logstash/inputs/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class LogStash::Inputs::File < LogStash::Inputs::Base
# has no effect.
config :start_position, :validate => [ "beginning", "end"], :default => "end"

# set the new line delimiter, defaults to "\n"
config :delimiter, :validate => :string, :default => "\n"

public
def register
require "addressable/uri"
Expand All @@ -77,6 +80,7 @@ def register
:stat_interval => @stat_interval,
:discover_interval => @discover_interval,
:sincedb_write_interval => @sincedb_write_interval,
:delimiter => @delimiter,
:logger => @logger,
}

Expand Down
1 change: 1 addition & 0 deletions logstash-input-file.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'addressable'
s.add_runtime_dependency 'filewatch', ['0.6.1']

s.add_development_dependency 'stud', ['~> 0.0.19']
s.add_development_dependency 'logstash-devutils'
end

41 changes: 24 additions & 17 deletions spec/inputs/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@

require "logstash/devutils/rspec/spec_helper"
require "tempfile"
require "stud/temporary"

describe "inputs/file" do


delimiter = (LogStash::Environment.windows? ? "\r\n" : "\n")

describe "starts at the end of an existing file" do
tmp_file = Tempfile.new('logstash-spec-input-file')
tmpfile_path = Stud::Temporary.pathname
sincedb_path = Stud::Temporary.pathname

config <<-CONFIG
input {
file {
type => "blah"
path => "#{tmp_file.path}"
sincedb_path => "/dev/null"
path => "#{tmpfile_path}"
sincedb_path => "#{sincedb_path}"
delimiter => "#{delimiter}"
}
}
CONFIG

input do |pipeline, queue|
File.open(tmp_file, "w") do |fd|
File.open(tmpfile_path, "w") do |fd|
fd.puts("ignore me 1")
fd.puts("ignore me 2")
end
Expand All @@ -38,7 +42,7 @@
loop do
insist { retries } < 20 # 2 secs should be plenty?

File.open(tmp_file, "a") do |fd|
File.open(tmpfile_path, "a") do |fd|
fd.puts("hello")
fd.puts("world")
end
Expand All @@ -57,21 +61,23 @@
end

describe "can start at the beginning of an existing file" do
tmp_file = Tempfile.new('logstash-spec-input-file')
tmpfile_path = Stud::Temporary.pathname
sincedb_path = Stud::Temporary.pathname

config <<-CONFIG
input {
file {
type => "blah"
path => "#{tmp_file.path}"
path => "#{tmpfile_path}"
start_position => "beginning"
sincedb_path => "/dev/null"
sincedb_path => "#{sincedb_path}"
delimiter => "#{delimiter}"
}
}
CONFIG

input do |pipeline, queue|
File.open(tmp_file, "a") do |fd|
File.open(tmpfile_path, "a") do |fd|
fd.puts("hello")
fd.puts("world")
end
Expand All @@ -86,22 +92,23 @@
end

describe "restarts at the sincedb value" do
tmp_file = Tempfile.new('logstash-spec-input-file')
tmp_sincedb = Tempfile.new('logstash-spec-input-file-sincedb')
tmpfile_path = Stud::Temporary.pathname
sincedb_path = Stud::Temporary.pathname

config <<-CONFIG
input {
file {
type => "blah"
path => "#{tmp_file.path}"
start_position => "beginning"
sincedb_path => "#{tmp_sincedb.path}"
path => "#{tmpfile_path}"
start_position => "beginning"
sincedb_path => "#{sincedb_path}"
delimiter => "#{delimiter}"
}
}
CONFIG

input do |pipeline, queue|
File.open(tmp_file, "w") do |fd|
File.open(tmpfile_path, "w") do |fd|
fd.puts("hello")
fd.puts("world")
end
Expand All @@ -113,7 +120,7 @@
pipeline.shutdown
t.join

File.open(tmp_file, "a") do |fd|
File.open(tmpfile_path, "a") do |fd|
fd.puts("foo")
fd.puts("bar")
fd.puts("baz")
Expand Down

0 comments on commit 4b8e926

Please sign in to comment.