@@ -76,7 +76,6 @@ class LogStash::Outputs::File < LogStash::Outputs::Base
76
76
77
77
default :codec , "json_lines"
78
78
79
- public
80
79
def register
81
80
require "fileutils" # For mkdir_p
82
81
@@ -101,28 +100,8 @@ def register
101
100
102
101
@last_stale_cleanup_cycle = Time . now
103
102
@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
112
103
end
113
104
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
126
105
def multi_receive_encoded ( events_and_encoded )
127
106
encoded_by_path = Hash . new { |h , k | h [ k ] = [ ] }
128
107
@@ -147,9 +126,8 @@ def multi_receive_encoded(events_and_encoded)
147
126
148
127
close_stale_files
149
128
end
150
- end # def receive
129
+ end
151
130
152
- public
153
131
def close
154
132
@flusher . stop unless @flusher . nil?
155
133
@io_mutex . synchronize do
@@ -167,12 +145,29 @@ def close
167
145
end
168
146
169
147
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
+
170
166
def inside_file_root? ( log_path )
171
167
target_file = File . expand_path ( log_path )
172
168
return target_file . start_with? ( "#{ @file_root . to_s } /" )
173
169
end
174
170
175
- private
176
171
def event_path ( event )
177
172
file_output_path = generate_filepath ( event )
178
173
if path_with_field_ref? && !inside_file_root? ( file_output_path )
@@ -186,24 +181,20 @@ def event_path(event)
186
181
file_output_path
187
182
end
188
183
189
- private
190
184
def generate_filepath ( event )
191
185
event . sprintf ( @path )
192
186
end
193
187
194
- private
195
188
def path_with_field_ref?
196
189
path =~ FIELD_REF
197
190
end
198
191
199
- private
200
192
def extract_file_root
201
193
parts = File . expand_path ( path ) . split ( File ::SEPARATOR )
202
194
parts . take_while { |part | part !~ FIELD_REF } . join ( File ::SEPARATOR )
203
195
end
204
196
205
197
# the back-bone of @flusher, our periodic-flushing interval.
206
- private
207
198
def flush_pending_files
208
199
@io_mutex . synchronize do
209
200
@logger . debug ( "Starting flush cycle" )
@@ -219,7 +210,6 @@ def flush_pending_files
219
210
end
220
211
221
212
# every 10 seconds or so (triggered by events, but if there are no events there's no point closing files anyway)
222
- private
223
213
def close_stale_files
224
214
now = Time . now
225
215
return unless now - @last_stale_cleanup_cycle >= @stale_cleanup_interval
@@ -237,17 +227,14 @@ def close_stale_files
237
227
@last_stale_cleanup_cycle = now
238
228
end
239
229
240
- private
241
230
def cached? ( path )
242
231
@files . include? ( path ) && !@files [ path ] . nil?
243
232
end
244
233
245
- private
246
234
def deleted? ( path )
247
235
!File . exist? ( path )
248
236
end
249
237
250
- private
251
238
def open ( path )
252
239
if !deleted? ( path ) && cached? ( path )
253
240
return @files [ path ]
@@ -362,24 +349,29 @@ def run
362
349
ensure
363
350
@sleeper . broadcast
364
351
end
365
- end # class LogStash::Outputs::File::Interval
366
- end # class LogStash::Outputs::File
352
+ end
353
+ end
367
354
368
355
# wrapper class
369
356
class IOWriter
357
+ attr_accessor :active
358
+
370
359
def initialize ( io )
371
360
@io = io
372
361
end
362
+
373
363
def write ( *args )
374
364
@io . write ( *args )
375
365
@active = true
376
366
end
367
+
377
368
def flush
378
369
@io . flush
379
370
if @io . class == Zlib ::GzipWriter
380
371
@io . to_io . flush
381
372
end
382
373
end
374
+
383
375
def method_missing ( method_name , *args , &block )
384
376
if @io . respond_to? ( method_name )
385
377
@@ -388,5 +380,4 @@ def method_missing(method_name, *args, &block)
388
380
super
389
381
end
390
382
end
391
- attr_accessor :active
392
383
end
0 commit comments