11
11
require_relative "file_listener"
12
12
require_relative "delete_completed_file_handler"
13
13
require_relative "log_completed_file_handler"
14
+ require_relative "friendly_durations"
14
15
require "filewatch/bootstrap"
15
16
16
17
# Stream events from files, normally by tailing them in a manner
@@ -109,7 +110,7 @@ class File < LogStash::Inputs::Base
109
110
# How often (in seconds) we stat files to see if they have been modified.
110
111
# Increasing this interval will decrease the number of system calls we make,
111
112
# but increase the time to detect new log lines.
112
- config :stat_interval , :validate => :number , :default => 1
113
+ config :stat_interval , :validate => [ FriendlyDurations , "seconds" ] , :default => 1
113
114
114
115
# How often (in seconds) we expand the filename patterns in the
115
116
# `path` option to discover new files to watch.
@@ -123,7 +124,7 @@ class File < LogStash::Inputs::Base
123
124
124
125
# How often (in seconds) to write a since database with the current position of
125
126
# monitored log files.
126
- config :sincedb_write_interval , :validate => :number , :default => 15
127
+ config :sincedb_write_interval , :validate => [ FriendlyDurations , "seconds" ] , :default => 15
127
128
128
129
# Choose where Logstash starts initially reading files: at the beginning or
129
130
# at the end. The default behavior treats files like live streams and thus
@@ -145,7 +146,7 @@ class File < LogStash::Inputs::Base
145
146
# After its discovery, if an ignored file is modified it is no
146
147
# longer ignored and any new data is read. By default, this option is
147
148
# disabled. Note this unit is in seconds.
148
- config :ignore_older , :validate => :number
149
+ config :ignore_older , :validate => [ FriendlyDurations , "seconds" ]
149
150
150
151
# The file input closes any files that were last read the specified
151
152
# timespan in seconds ago.
@@ -154,7 +155,7 @@ class File < LogStash::Inputs::Base
154
155
# reopening when new data is detected. If reading, the file will be closed
155
156
# after closed_older seconds from when the last bytes were read.
156
157
# The default is 1 hour
157
- config :close_older , :validate => :number , :default => 1 * 60 * 60
158
+ config :close_older , :validate => [ FriendlyDurations , "seconds" ] , :default => "1 hour"
158
159
159
160
# What is the maximum number of file_handles that this input consumes
160
161
# at any one time. Use close_older to close some files if you need to
@@ -191,7 +192,7 @@ class File < LogStash::Inputs::Base
191
192
# If no changes are detected in tracked files in the last N days their sincedb
192
193
# tracking record will expire and not be persisted.
193
194
# This option protects against the well known inode recycling problem. (add reference)
194
- config :sincedb_clean_after , :validate => :number , :default => 14 # days
195
+ config :sincedb_clean_after , :validate => [ FriendlyDurations , "days" ] , :default => "14 days" # days
195
196
196
197
# File content is read off disk in blocks or chunks, then using whatever the set delimiter
197
198
# is, lines are extracted from the chunk. Specify the size in bytes of each chunk.
@@ -222,6 +223,20 @@ class File < LogStash::Inputs::Base
222
223
config :file_sort_direction , :validate => [ "asc" , "desc" ] , :default => "asc"
223
224
224
225
public
226
+
227
+ class << self
228
+ alias_method :old_validate_value , :validate_value
229
+
230
+ def validate_value ( value , validator )
231
+ if validator . is_a? ( Array ) && validator . size == 2 && validator . first . respond_to? ( :call )
232
+ callable , units = *validator
233
+ # returns a ValidatedStruct having a `to_a` method suitable to return to the config mixin caller
234
+ return callable . call ( value , units ) . to_a
235
+ end
236
+ old_validate_value ( value , validator )
237
+ end
238
+ end
239
+
225
240
def register
226
241
require "addressable/uri"
227
242
require "digest/md5"
0 commit comments