Class: Fluent::FileOutput
Constant Summary
collapse
- SUPPORTED_COMPRESS =
{
'gz' => :gz,
'gzip' => :gz,
}
Instance Attribute Summary
#localtime
Attributes included from Configurable
#config
Instance Method Summary
collapse
#emit, #enqueue_buffer
#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
#shutdown, #start
Methods included from PluginId
#plugin_id, #require_id
included
Constructor Details
Returns a new instance of FileOutput.
41
42
43
44
45
|
# File 'lib/fluent/plugin/out_file.rb', line 41
def initialize
require 'zlib'
require 'time'
super
end
|
Instance Method Details
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/fluent/plugin/out_file.rb', line 47
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
super
@timef = TimeFormatter.new(@time_format, @localtime)
end
|
70
71
72
73
|
# File 'lib/fluent/plugin/out_file.rb', line 70
def format(tag, time, record)
time_str = @timef.format(time)
"#{time_str}\t#{tag}\t#{Yajl.dump(record)}\n"
end
|
#secondary_init(primary) ⇒ Object
104
105
106
|
# File 'lib/fluent/plugin/out_file.rb', line 104
def secondary_init(primary)
end
|
#write(chunk) ⇒ Object
75
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
|
# File 'lib/fluent/plugin/out_file.rb', line 75
def write(chunk)
case @compress
when nil
suffix = ''
when :gz
suffix = ".gz"
end
i = 0
begin
path = "#{@path_prefix}#{chunk.key}_#{i}#{@path_suffix}#{suffix}"
i += 1
end while File.exist?(path)
FileUtils.mkdir_p File.dirname(path)
case @compress
when nil
File.open(path, "a") {|f|
chunk.write_to(f)
}
when :gz
Zlib::GzipWriter.open(path) {|f|
chunk.write_to(f)
}
end
return path end
|