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
#receive(event) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/logstash/outputs/file.rb', line 97 def receive(event) return unless output?(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
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/logstash/outputs/file.rb', line 54 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 |
#teardown ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/logstash/outputs/file.rb', line 112 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("Exception while flushing and closing files.", :exception => e) end end finished end |