Class: Fluent::FileOutput
- Inherits:
-
TimeSlicedOutput
- Object
- Output
- BufferedOutput
- TimeSlicedOutput
- Fluent::FileOutput
- Defined in:
- lib/fluent/plugin/out_file.rb
Constant Summary collapse
- SUPPORTED_COMPRESS =
{ 'gz' => :gz, 'gzip' => :gz, }
Constants included from Configurable
Configurable::CONFIG_TYPE_REGISTRY
Instance Attribute Summary
Attributes inherited from TimeSlicedOutput
Attributes inherited from Output
Attributes included from PluginLoggerMixin
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
-
#initialize ⇒ FileOutput
constructor
A new instance of FileOutput.
- #secondary_init(primary) ⇒ Object
- #write(chunk) ⇒ Object
Methods inherited from TimeSlicedOutput
Methods inherited from BufferedOutput
#before_shutdown, #calc_retry_wait, #emit, #enqueue_buffer, #flush_secondary, #force_flush, #format_stream, #shutdown, #start, #submit_flush, #try_flush, #write_abort
Methods inherited from Output
Methods included from PluginLoggerMixin
Methods included from PluginId
Methods included from Configurable
#config, included, lookup_type, register_type
Constructor Details
#initialize ⇒ FileOutput
Returns a new instance of FileOutput.
49 50 51 52 53 54 |
# File 'lib/fluent/plugin/out_file.rb', line 49 def initialize require 'zlib' require 'time' require 'fluent/plugin/file_util' super end |
Instance Method Details
#configure(conf) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/fluent/plugin/out_file.rb', line 56 def configure(conf) if path = conf['path'] @path = path end unless @path raise ConfigError, "'path' parameter is required on file output" end if pos = @path.index('*') @path_prefix = @path[0,pos] @path_suffix = @path[pos+1..-1] conf['buffer_path'] ||= "#{@path}" else @path_prefix = @path+"." @path_suffix = ".log" conf['buffer_path'] ||= "#{@path}.*" end test_path = generate_path(Time.now.strftime(@time_slice_format)) unless ::Fluent::FileUtil.writable_p?(test_path) raise ConfigError, "out_file: `#{test_path}` is not writable" end super @formatter = Plugin.new_formatter(@format) @formatter.configure(conf) @buffer.symlink_path = @symlink_path if @symlink_path end |
#format(tag, time, record) ⇒ Object
87 88 89 |
# File 'lib/fluent/plugin/out_file.rb', line 87 def format(tag, time, record) @formatter.format(tag, time, record) end |
#secondary_init(primary) ⇒ Object
111 112 113 |
# File 'lib/fluent/plugin/out_file.rb', line 111 def secondary_init(primary) # don't warn even if primary.class is not FileOutput end |
#write(chunk) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/fluent/plugin/out_file.rb', line 91 def write(chunk) path = generate_path(chunk.key) FileUtils.mkdir_p File.dirname(path), mode: DEFAULT_DIR_PERMISSION case @compress when nil File.open(path, "a", DEFAULT_FILE_PERMISSION) {|f| chunk.write_to(f) } when :gz File.open(path, "a", DEFAULT_FILE_PERMISSION) {|f| gz = Zlib::GzipWriter.new(f) chunk.write_to(gz) gz.close } end return path # for test end |