Class: Fluent::FileOutput
Defined Under Namespace
Modules: SymlinkBufferMixin
Constant Summary
collapse
- SUPPORTED_COMPRESS =
{
'gz' => :gz,
'gzip' => :gz,
}
- FILE_PERMISSION =
0644
- DIR_PERMISSION =
0755
Instance Method Summary
collapse
#system_config, #system_config_override
Constructor Details
Returns a new instance of FileOutput.
74
75
76
77
78
79
|
# File 'lib/fluent/plugin/out_file.rb', line 74
def initialize
require 'zlib'
require 'time'
require 'fluent/plugin/file_util'
super
end
|
Instance Method Details
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
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/fluent/plugin/out_file.rb', line 81
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)
if @symlink_path && @buffer.respond_to?(:path)
@buffer.extend SymlinkBufferMixin
@buffer.symlink_path = @symlink_path
end
@dir_perm = system_config.dir_permission || DIR_PERMISSION
@file_perm = system_config.file_permission || FILE_PERMISSION
end
|
118
119
120
|
# File 'lib/fluent/plugin/out_file.rb', line 118
def format(tag, time, record)
@formatter.format(tag, time, record)
end
|
#secondary_init(primary) ⇒ Object
142
143
144
|
# File 'lib/fluent/plugin/out_file.rb', line 142
def secondary_init(primary)
end
|
#write(chunk) ⇒ Object
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/fluent/plugin/out_file.rb', line 122
def write(chunk)
path = generate_path(chunk.key)
FileUtils.mkdir_p File.dirname(path), mode: @dir_perm
case @compress
when nil
File.open(path, "ab", @file_perm) {|f|
chunk.write_to(f)
}
when :gz
File.open(path, "ab", @file_perm) {|f|
gz = Zlib::GzipWriter.new(f)
chunk.write_to(gz)
gz.close
}
end
return path
end
|