Class: LogStash::Outputs::FileCloseable
- Inherits:
-
Base
- Object
- Base
- LogStash::Outputs::FileCloseable
- Defined in:
- lib/logstash/outputs/file_closeable.rb
Overview
File output.
Write events to files on disk. You can use fields from the event as parts of the filename.
Constant Summary collapse
- JavaException =
java.lang.Exception
Instance Method Summary collapse
- #receive(event) ⇒ Object
- #register ⇒ Object
-
#teardown ⇒ Object
def receive.
Instance Method Details
#receive(event) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/logstash/outputs/file_closeable.rb', line 79 def receive(event) return unless output?(event) @codec.encode(event) if event.include? "tags" and event["tags"].include?("eof") @files.each do |path, fd| if(File.basename(path) == File.basename(event['path'])) fd.active = false end end close_stale_files(true) #means eof return end end |
#register ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/logstash/outputs/file_closeable.rb', line 43 def register require "fileutils" # For mkdir_p @files = {} now = Time.now @last_flush_cycle = now @last_stale_cleanup_cycle = now flush_interval = @flush_interval.to_i @stale_cleanup_interval = 10 @codec.on_event do |event| if @path path = event.sprintf(@path) else path = event["path"] end fd = open(path) if event.is_a? LogStash::Event and output = event.sprintf() else output = event["message"] end @logger.debug("Writing output to file", :output => output, :path => path) if @logger.debug? fd.write(output) fd.write("\n") flush(fd) close_stale_files(false) end end |
#teardown ⇒ Object
def receive
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/logstash/outputs/file_closeable.rb', line 97 def teardown @logger.debug("Teardown: closing files") if @logger.debug? @files.each do |path, fd| begin fd.close @logger.debug("Closed file #{path}", :fd => fd) if @logger.debug? rescue Exception => e @logger.error("Excpetion while flushing and closing files.", :exception => e) if @logger.debug? end end finished end |