diff --git a/CHANGELOG.md b/CHANGELOG.md index b0c82db..75c6546 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.1.4 + - Add configurable path for sincedb file and custom file name prefix + ## 2.1.3 - Use ruby-filewatch 0.7.1, re-enable close after file is modified again diff --git a/lib/logstash/inputs/file.rb b/lib/logstash/inputs/file.rb index 39335db..38a97a5 100644 --- a/lib/logstash/inputs/file.rb +++ b/lib/logstash/inputs/file.rb @@ -120,6 +120,16 @@ class LogStash::Inputs::File < LogStash::Inputs::Base # NOTE: it must be a file path and not a directory path config :sincedb_path, :validate => :string + # Directory path of where the sincedb file will be written. sincedb_path + # overrides this value so they should not be used together. This has + # the same effect of setting $HOME or $SINCEDB_DIR environment variables. + config :sincedb_dir, :validate => :string + + # Prefix for the sincedb file name. By default the sincedb file is named + # .sincedb*. This allows you to customize the filename but keep the hash + # that is appended to it. + config :sincedb_file_prefix, :validate => :string, :default => ".sincedb_" + # How often (in seconds) to write a since database with the current position of # monitored log files. config :sincedb_write_interval, :validate => :number, :default => 15 @@ -175,21 +185,27 @@ def register end if @sincedb_path.nil? - if ENV["SINCEDB_DIR"].nil? && ENV["HOME"].nil? - @logger.error("No SINCEDB_DIR or HOME environment variable set, I don't know where " \ - "to keep track of the files I'm watching. Either set " \ - "HOME or SINCEDB_DIR in your environment, or set sincedb_path in " \ - "in your Logstash config for the file input with " \ - "path '#{@path.inspect}'") - raise # TODO(sissel): HOW DO I FAIL PROPERLY YO + if @sincedb_dir.nil? + if ENV["SINCEDB_DIR"].nil? && ENV["HOME"].nil? + @logger.error("No SINCEDB_DIR or HOME environment variable set, I don't know where " \ + "to keep track of the files I'm watching. Either set " \ + "HOME or SINCEDB_DIR in your environment, or set sincedb_path in " \ + "in your Logstash config for the file input with " \ + "path '#{@path.inspect}'") + raise # TODO(sissel): HOW DO I FAIL PROPERLY YO + end end - #pick SINCEDB_DIR if available, otherwise use HOME - sincedb_dir = ENV["SINCEDB_DIR"] || ENV["HOME"] + #pick sincedb_path if set, then SINCEDB_DIR if available, otherwise use HOME + sincedb_dir = @sincedb_dir || ENV["SINCEDB_DIR"] || ENV["HOME"] # Join by ',' to make it easy for folks to know their own sincedb # generated path (vs, say, inspecting the @path array) - @sincedb_path = File.join(sincedb_dir, ".sincedb_" + Digest::MD5.hexdigest(@path.join(","))) + path_hex = Digest::MD5.hexdigest(@path.join(",")) + + sincedb_file = @sincedb_file_prefix + path_hex + + @sincedb_path = File.join(sincedb_dir, sincedb_file) # Migrate any old .sincedb to the new file (this is for version <=1.1.1 compatibility) old_sincedb = File.join(sincedb_dir, ".sincedb") diff --git a/logstash-input-file.gemspec b/logstash-input-file.gemspec index 281a9f9..fbaa497 100644 --- a/logstash-input-file.gemspec +++ b/logstash-input-file.gemspec @@ -1,7 +1,7 @@ Gem::Specification.new do |s| s.name = 'logstash-input-file' - s.version = '2.1.3' + s.version = '2.1.4' s.licenses = ['Apache License (2.0)'] s.summary = "Stream events from files." s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"