Class: LogStash::Outputs::File
- Defined in:
- lib/logstash/outputs/file.rb
Overview
File output.
Write events to files on disk. You can use fields from the event as parts of the filename.
Direct Known Subclasses
Constant Summary
Constants included from Config::Mixin
Instance Attribute Summary
Attributes included from Config::Mixin
Attributes inherited from Plugin
Instance Method Summary collapse
- #receive(event) ⇒ Object
- #register ⇒ Object
-
#teardown ⇒ Object
def receive.
Methods inherited from Base
#handle, #handle_worker, #initialize, #worker_setup, #workers_not_supported
Methods included from Config::Mixin
Methods inherited from Plugin
#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #terminating?, #to_s
Constructor Details
This class inherits a constructor from LogStash::Outputs::Base
Instance Method Details
#receive(event) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/logstash/outputs/file.rb', line 61 def receive(event) return unless output?(event) path = event.sprintf(@path) fd = open(path) # TODO(sissel): Check if we should rotate the file. if @message_format output = event.sprintf(@message_format) else output = event.to_json end fd.write(output) fd.write("\n") flush(fd) close_stale_files end |
#register ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/logstash/outputs/file.rb', line 47 def register require "fileutils" # For mkdir_p workers_not_supported @files = {} now = Time.now @last_flush_cycle = now @last_stale_cleanup_cycle = now flush_interval = @flush_interval.to_i @stale_cleanup_interval = 10 end |
#teardown ⇒ Object
def receive
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/logstash/outputs/file.rb', line 82 def teardown @logger.debug("Teardown: closing files") @files.each do |path, fd| begin fd.close @logger.debug("Closed file #{path}", :fd => fd) rescue Exception => e @logger.error("Excpetion while flushing and closing files.", :exception => e) end end finished end |