Class: Fluent::FileStraightOutput

Inherits:
BufferedOutput
  • Object
show all
Defined in:
lib/fluent/plugin/out_simplefile.rb

Instance Method Summary collapse

Constructor Details

#initializeFileStraightOutput

Returns a new instance of FileStraightOutput.



19
20
21
22
# File 'lib/fluent/plugin/out_simplefile.rb', line 19

def initialize
  require 'fluent/plugin/file_util'
  super
end

Instance Method Details

#configure(conf) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fluent/plugin/out_simplefile.rb', line 24

def configure(conf)
  if path = conf['path']
    @path = path
  end
  unless @path
    raise ConfigError, "'path' parameter is required on file output"
  end

  unless ::Fluent::FileUtil.writable_p?(path)
    raise ConfigError, "out_file: `#{path}` is not writable"
  end

  super

  @formatter = Plugin.new_formatter(@format)
  @formatter.configure(conf)
end

#format(tag, time, record) ⇒ Object



42
43
44
# File 'lib/fluent/plugin/out_simplefile.rb', line 42

def format(tag, time, record)
  @formatter.format(tag, time, record)
end

#secondary_init(primary) ⇒ Object



56
57
58
# File 'lib/fluent/plugin/out_simplefile.rb', line 56

def secondary_init(primary)
  # don't warn even if primary.class is not FileOutput
end

#write(chunk) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/fluent/plugin/out_simplefile.rb', line 46

def write(chunk)
  path = @path
  FileUtils.mkdir_p File.dirname(path), mode: DEFAULT_DIR_PERMISSION

  File.open(path, "a", DEFAULT_FILE_PERMISSION) {|f|
    chunk.write_to(f)
  }
  return path
end