Class: Fluent::SameFileOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_samefile.rb

Instance Method Summary collapse

Constructor Details

#initializeSameFileOutput

Returns a new instance of SameFileOutput.



10
11
12
# File 'lib/fluent/plugin/out_samefile.rb', line 10

def initialize
  super
end

Instance Method Details

#configure(conf) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fluent/plugin/out_samefile.rb', line 14

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

  super

  FileUtils.mkdir_p File.dirname(@path)

  conf['format'] = @format
  @formatter = TextFormatter.create(conf)
end

#emit(tag, es, chain, key = "") ⇒ Object



40
41
42
43
# File 'lib/fluent/plugin/out_samefile.rb', line 40

def emit(tag, es, chain, key="")
  data = format_stream(tag, es)
  write(data)
end

#format(tag, time, record) ⇒ Object



30
31
32
# File 'lib/fluent/plugin/out_samefile.rb', line 30

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

#format_stream(tag, es) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/fluent/plugin/out_samefile.rb', line 45

def format_stream(tag, es)
  out = ''
  es.each {|time,record|
    out << format(tag, time, record)
  }
  out
end

#write(data) ⇒ Object



34
35
36
37
38
# File 'lib/fluent/plugin/out_samefile.rb', line 34

def write(data)
  File.open(@path, "a", DEFAULT_FILE_PERMISSION) do |f|
    f.write(data)
  end
end