class LogStash::Inputs::File
Stream events from files.
By default, each event is assumed to be one line. If you want to join lines, you'll want to use the multiline filter.
Files are followed in a manner similar to “tail -0F”. File
rotation is detected and handled by this input.
Public Instance Methods
register()
click to toggle source
# File lib/logstash/inputs/file.rb, line 66 def register require "addressable/uri" require "filewatch/tail" require "digest/md5" @logger.info("Registering file input", :path => @path) @tail_config = { :exclude => @exclude, :stat_interval => @stat_interval, :discover_interval => @discover_interval, :sincedb_write_interval => @sincedb_write_interval, :logger => @logger, } @path.each do |path| if Pathname.new(path).relative? raise ArgumentError.new("File paths must be absolute, relative path specified: #{path}") end 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 end #pick SINCEDB_DIR if available, otherwise use HOME 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(","))) # Migrate any old .sincedb to the new file (this is for version <=1.1.1 compatibility) old_sincedb = File.join(sincedb_dir, ".sincedb") if File.exists?(old_sincedb) @logger.info("Renaming old ~/.sincedb to new one", :old => old_sincedb, :new => @sincedb_path) File.rename(old_sincedb, @sincedb_path) end @logger.info("No sincedb_path set, generating one based on the file path", :sincedb_path => @sincedb_path, :path => @path) end @tail_config[:sincedb_path] = @sincedb_path if @start_position == "beginning" @tail_config[:start_new_files_at] = :beginning end end
run(queue)
click to toggle source
# File lib/logstash/inputs/file.rb, line 123 def run(queue) @tail = FileWatch::Tail.new(@tail_config) @tail.logger = @logger @path.each { |path| @tail.tail(path) } hostname = Socket.gethostname @tail.subscribe do |path, line| @logger.debug? && @logger.debug("Received line", :path => path, :text => line) @codec.decode(line) do |event| decorate(event) event["host"] = hostname event["path"] = path queue << event end end finished end
teardown()
click to toggle source
# File lib/logstash/inputs/file.rb, line 142 def teardown @tail.sincedb_write @tail.quit end