Class: LogStash::Outputs::File
- Inherits:
-
Base
- Object
- Base
- LogStash::Outputs::File
- Defined in:
- lib/logstash/outputs/file.rb
Overview
This output writes events to files on disk. You can use fields from the event as parts of the filename and/or path.
By default, this output writes one event per line in json format. You can customise the line format using the line codec like
- source,ruby
-
output
file { path => ... codec => { line { format => "custom format: %{message"}} }}
Constant Summary collapse
- FIELD_REF =
/%\{[^}]+\}/
Instance Attribute Summary collapse
-
#failure_path ⇒ Object
readonly
Returns the value of attribute failure_path.
Instance Method Summary collapse
Instance Attribute Details
#failure_path ⇒ Object (readonly)
Returns the value of attribute failure_path.
24 25 26 |
# File 'lib/logstash/outputs/file.rb', line 24 def failure_path @failure_path end |
Instance Method Details
#close ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/logstash/outputs/file.rb', line 134 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
128 129 130 131 |
# File 'lib/logstash/outputs/file.rb', line 128 def receive(event) @codec.encode(event) close_stale_files end |
#register ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/logstash/outputs/file.rb', line 76 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 else @file_root = File.dirname(path) end @failure_path = File.join(@file_root, @filename_failure) now = Time.now @last_flush_cycle = now @last_stale_cleanup_cycle = now @flush_interval = @flush_interval.to_i @stale_cleanup_interval = 10 if @codec = LogStash::Plugin.lookup("codec", "line").new @codec.format = end @codec.on_event(&method(:write_event)) end |