Class: LogStash::Outputs::File
- Inherits:
-
Base
- Object
- Base
- LogStash::Outputs::File
- Defined in:
- lib/logstash/outputs/file.rb
Overview
This output will write events to files on disk. You can use fields from the event as parts of the filename and/or path.
Constant Summary collapse
- FIELD_REF =
/%\{[^}]+\}/
Instance Method Summary collapse
Instance Method Details
#close ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/logstash/outputs/file.rb', line 104 def close @logger.debug("Close: closing files") @files.each do |path, fd| begin fd.close @logger.debug("Closed file #{path}", :fd => fd) rescue Exception => e @logger.error("Exception while flushing and closing files.", :exception => e) end end end |
#receive(event) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/logstash/outputs/file.rb', line 89 def receive(event) file_output_path = generate_filepath(event) if path_with_field_ref? && !inside_file_root?(file_output_path) @logger.warn("File: the event tried to write outside the files root, writing the event to the failure file", :event => event, :filename => @failure_path) file_output_path = @failure_path end output = (event) write_event(file_output_path, output) end |
#register ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/logstash/outputs/file.rb', line 46 def register require "fileutils" # For mkdir_p workers_not_supported @files = {} @path = File.(path) validate_path if path_with_field_ref? @file_root = extract_file_root @failure_path = File.join(@file_root, @filename_failure) end now = Time.now @last_flush_cycle = now @last_stale_cleanup_cycle = now @flush_interval = @flush_interval.to_i @stale_cleanup_interval = 10 end |