Skip to content

Commit 04fbf8c

Browse files
cosmetic cleanups
1 parent f27b64e commit 04fbf8c

File tree

1 file changed

+26
-35
lines changed

1 file changed

+26
-35
lines changed

Diff for: lib/logstash/outputs/file.rb

+26-35
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ class LogStash::Outputs::File < LogStash::Outputs::Base
7676

7777
default :codec, "json_lines"
7878

79-
public
8079
def register
8180
require "fileutils" # For mkdir_p
8281

@@ -101,28 +100,8 @@ def register
101100

102101
@last_stale_cleanup_cycle = Time.now
103102
@stale_cleanup_interval = 10
104-
end # def register
105-
106-
private
107-
def validate_path
108-
if (root_directory =~ FIELD_REF) != nil
109-
@logger.error("File: The starting part of the path should not be dynamic.", :path => @path)
110-
raise LogStash::ConfigurationError.new("The starting part of the path should not be dynamic.")
111-
end
112103
end
113104

114-
private
115-
def root_directory
116-
parts = @path.split(File::SEPARATOR).select { |item| !item.empty? }
117-
if Gem.win_platform?
118-
# First part is the drive letter
119-
parts[1]
120-
else
121-
parts.first
122-
end
123-
end
124-
125-
public
126105
def multi_receive_encoded(events_and_encoded)
127106
encoded_by_path = Hash.new {|h,k| h[k] = []}
128107

@@ -147,9 +126,8 @@ def multi_receive_encoded(events_and_encoded)
147126

148127
close_stale_files
149128
end
150-
end # def receive
129+
end
151130

152-
public
153131
def close
154132
@flusher.stop unless @flusher.nil?
155133
@io_mutex.synchronize do
@@ -167,12 +145,29 @@ def close
167145
end
168146

169147
private
148+
149+
def validate_path
150+
if (root_directory =~ FIELD_REF) != nil
151+
@logger.error("File: The starting part of the path should not be dynamic.", :path => @path)
152+
raise LogStash::ConfigurationError.new("The starting part of the path should not be dynamic.")
153+
end
154+
end
155+
156+
def root_directory
157+
parts = @path.split(File::SEPARATOR).select { |item| !item.empty? }
158+
if Gem.win_platform?
159+
# First part is the drive letter
160+
parts[1]
161+
else
162+
parts.first
163+
end
164+
end
165+
170166
def inside_file_root?(log_path)
171167
target_file = File.expand_path(log_path)
172168
return target_file.start_with?("#{@file_root.to_s}/")
173169
end
174170

175-
private
176171
def event_path(event)
177172
file_output_path = generate_filepath(event)
178173
if path_with_field_ref? && !inside_file_root?(file_output_path)
@@ -186,24 +181,20 @@ def event_path(event)
186181
file_output_path
187182
end
188183

189-
private
190184
def generate_filepath(event)
191185
event.sprintf(@path)
192186
end
193187

194-
private
195188
def path_with_field_ref?
196189
path =~ FIELD_REF
197190
end
198191

199-
private
200192
def extract_file_root
201193
parts = File.expand_path(path).split(File::SEPARATOR)
202194
parts.take_while { |part| part !~ FIELD_REF }.join(File::SEPARATOR)
203195
end
204196

205197
# the back-bone of @flusher, our periodic-flushing interval.
206-
private
207198
def flush_pending_files
208199
@io_mutex.synchronize do
209200
@logger.debug("Starting flush cycle")
@@ -219,7 +210,6 @@ def flush_pending_files
219210
end
220211

221212
# every 10 seconds or so (triggered by events, but if there are no events there's no point closing files anyway)
222-
private
223213
def close_stale_files
224214
now = Time.now
225215
return unless now - @last_stale_cleanup_cycle >= @stale_cleanup_interval
@@ -237,17 +227,14 @@ def close_stale_files
237227
@last_stale_cleanup_cycle = now
238228
end
239229

240-
private
241230
def cached?(path)
242231
@files.include?(path) && !@files[path].nil?
243232
end
244233

245-
private
246234
def deleted?(path)
247235
!File.exist?(path)
248236
end
249237

250-
private
251238
def open(path)
252239
if !deleted?(path) && cached?(path)
253240
return @files[path]
@@ -362,24 +349,29 @@ def run
362349
ensure
363350
@sleeper.broadcast
364351
end
365-
end # class LogStash::Outputs::File::Interval
366-
end # class LogStash::Outputs::File
352+
end
353+
end
367354

368355
# wrapper class
369356
class IOWriter
357+
attr_accessor :active
358+
370359
def initialize(io)
371360
@io = io
372361
end
362+
373363
def write(*args)
374364
@io.write(*args)
375365
@active = true
376366
end
367+
377368
def flush
378369
@io.flush
379370
if @io.class == Zlib::GzipWriter
380371
@io.to_io.flush
381372
end
382373
end
374+
383375
def method_missing(method_name, *args, &block)
384376
if @io.respond_to?(method_name)
385377

@@ -388,5 +380,4 @@ def method_missing(method_name, *args, &block)
388380
super
389381
end
390382
end
391-
attr_accessor :active
392383
end

0 commit comments

Comments
 (0)