diff --git a/lib/fluent/compat/output.rb b/lib/fluent/compat/output.rb index f10105b7ea..8a70fd8190 100644 --- a/lib/fluent/compat/output.rb +++ b/lib/fluent/compat/output.rb @@ -404,14 +404,14 @@ def start end end - def detach_process(&block) + def detach_process log.warn "detach_process is not supported in this version. ignored." - block.call + yield end - def detach_multi_process(&block) + def detach_multi_process log.warn "detach_process is not supported in this version. ignored." - block.call + yield end end @@ -541,14 +541,14 @@ def start end end - def detach_process(&block) + def detach_process log.warn "detach_process is not supported in this version. ignored." - block.call + yield end - def detach_multi_process(&block) + def detach_multi_process log.warn "detach_process is not supported in this version. ignored." - block.call + yield end end @@ -698,14 +698,14 @@ def start end end - def detach_process(&block) + def detach_process log.warn "detach_process is not supported in this version. ignored." - block.call + yield end - def detach_multi_process(&block) + def detach_multi_process log.warn "detach_process is not supported in this version. ignored." - block.call + yield end # Original TimeSlicedOutput#emit doesn't call #format_stream diff --git a/lib/fluent/config/element.rb b/lib/fluent/config/element.rb index 30bd93e9f3..72e83137d1 100644 --- a/lib/fluent/config/element.rb +++ b/lib/fluent/config/element.rb @@ -127,10 +127,10 @@ def [](key) super end - def check_not_fetched(&block) + def check_not_fetched each_key { |key| if @unused.include?(key) - block.call(key, self) + yield(key, self) if block_given? end } @elements.each { |e| diff --git a/lib/fluent/event.rb b/lib/fluent/event.rb index 9c2ffbbf8e..4049ec0d65 100644 --- a/lib/fluent/event.rb +++ b/lib/fluent/event.rb @@ -106,8 +106,8 @@ def slice(index, num) end end - def each(unpacker: nil, &block) - block.call(@time, @record) + def each(unpacker: nil) + yield(@time, @record) nil end end @@ -189,11 +189,11 @@ def slice(index, num) MultiEventStream.new(@time_array.slice(index, num), @record_array.slice(index, num)) end - def each(unpacker: nil, &block) + def each(unpacker: nil) time_array = @time_array record_array = @record_array for i in 0..time_array.length-1 - block.call(time_array[i], record_array[i]) + yield(time_array[i], record_array[i]) end nil end @@ -253,10 +253,10 @@ def slice(index, num) MultiEventStream.new(@unpacked_times.slice(index, num), @unpacked_records.slice(index, num)) end - def each(unpacker: nil, &block) + def each(unpacker: nil) ensure_unpacked!(unpacker: unpacker) @unpacked_times.each_with_index do |time, i| - block.call(time, @unpacked_records[i]) + yield(time, @unpacked_records[i]) end nil end diff --git a/lib/fluent/log.rb b/lib/fluent/log.rb index f8175fd911..9d186343cc 100644 --- a/lib/fluent/log.rb +++ b/lib/fluent/log.rb @@ -309,11 +309,11 @@ def on_trace yield end - def trace(*args, &block) + def trace(*args) return if @level > LEVEL_TRACE type = log_type(args) return if skipped_type?(type) - args << block.call if block + args << yield if block_given? time, msg = event(:trace, args) return if time.nil? puts [@color_trace, @formatter.call(type, time, LEVEL_TRACE, msg), @color_reset].join @@ -331,11 +331,11 @@ def on_debug yield end - def debug(*args, &block) + def debug(*args) return if @level > LEVEL_DEBUG type = log_type(args) return if skipped_type?(type) - args << block.call if block + args << yield if block_given? time, msg = event(:debug, args) return if time.nil? puts [@color_debug, @formatter.call(type, time, LEVEL_DEBUG, msg), @color_reset].join @@ -352,11 +352,11 @@ def on_info yield end - def info(*args, &block) + def info(*args) return if @level > LEVEL_INFO type = log_type(args) return if skipped_type?(type) - args << block.call if block + args << yield if block_given? time, msg = event(:info, args) return if time.nil? puts [@color_info, @formatter.call(type, time, LEVEL_INFO, msg), @color_reset].join @@ -373,11 +373,11 @@ def on_warn yield end - def warn(*args, &block) + def warn(*args) return if @level > LEVEL_WARN type = log_type(args) return if skipped_type?(type) - args << block.call if block + args << yield if block_given? time, msg = event(:warn, args) return if time.nil? puts [@color_warn, @formatter.call(type, time, LEVEL_WARN, msg), @color_reset].join @@ -394,11 +394,11 @@ def on_error yield end - def error(*args, &block) + def error(*args) return if @level > LEVEL_ERROR type = log_type(args) return if skipped_type?(type) - args << block.call if block + args << yield if block_given? time, msg = event(:error, args) return if time.nil? puts [@color_error, @formatter.call(type, time, LEVEL_ERROR, msg), @color_reset].join @@ -415,11 +415,11 @@ def on_fatal yield end - def fatal(*args, &block) + def fatal(*args) return if @level > LEVEL_FATAL type = log_type(args) return if skipped_type?(type) - args << block.call if block + args << yield if block_given? time, msg = event(:fatal, args) return if time.nil? puts [@color_fatal, @formatter.call(type, time, LEVEL_FATAL, msg), @color_reset].join diff --git a/lib/fluent/plugin/buffer.rb b/lib/fluent/plugin/buffer.rb index 6ba36c4318..bf97e96432 100644 --- a/lib/fluent/plugin/buffer.rb +++ b/lib/fluent/plugin/buffer.rb @@ -650,7 +650,7 @@ class ShouldRetry < StandardError; end # 3. enqueue existing chunk & retry whole method if chunk was not empty # 4. go to step_by_step writing - def write_once(metadata, data, format: nil, size: nil, &block) + def write_once(metadata, data, format: nil, size: nil) return if data.empty? stored = false @@ -701,7 +701,7 @@ def write_once(metadata, data, format: nil, size: nil, &block) end if stored - block.call(chunk, adding_bytesize) + yield(chunk, adding_bytesize) end end @@ -726,7 +726,7 @@ def write_once(metadata, data, format: nil, size: nil, &block) # 2. append splits into the staged chunks as much as possible # 3. create unstaged chunk and append rest splits -> repeat it for all splits - def write_step_by_step(metadata, data, format, splits_count, &block) + def write_step_by_step(metadata, data, format, splits_count) splits = [] if splits_count > data.size splits_count = data.size @@ -855,7 +855,7 @@ def write_step_by_step(metadata, data, format, splits_count, &block) modified_chunks.last[:adding_bytesize] = chunk.bytesize - original_bytesize end modified_chunks.each do |data| - block.call(data[:chunk], data[:adding_bytesize], data[:errors]) + yield(data[:chunk], data[:adding_bytesize], data[:errors]) end rescue ShouldRetry modified_chunks.each do |data| diff --git a/lib/fluent/plugin/in_forward.rb b/lib/fluent/plugin/in_forward.rb index 0c2216883c..fb052ab8a8 100644 --- a/lib/fluent/plugin/in_forward.rb +++ b/lib/fluent/plugin/in_forward.rb @@ -239,7 +239,7 @@ def handle_connection(conn) end end - def read_messages(conn, &block) + def read_messages(conn) feeder = nil serializer = nil bytes = 0 @@ -250,7 +250,7 @@ def read_messages(conn, &block) if first == '{' || first == '[' # json parser = Yajl::Parser.new parser.on_parse_complete = ->(obj){ - block.call(obj, bytes, serializer) + yield(obj, bytes, serializer) bytes = 0 } serializer = :to_json.to_proc @@ -260,7 +260,7 @@ def read_messages(conn, &block) serializer = :to_msgpack.to_proc feeder = ->(d){ parser.feed_each(d){|obj| - block.call(obj, bytes, serializer) + yield(obj, bytes, serializer) bytes = 0 } } diff --git a/lib/fluent/plugin/output.rb b/lib/fluent/plugin/output.rb index a987937b67..83b3b9dfe3 100644 --- a/lib/fluent/plugin/output.rb +++ b/lib/fluent/plugin/output.rb @@ -972,9 +972,9 @@ def execute_chunking(tag, es, enqueue: false) end end - def write_guard(&block) + def write_guard begin - block.call + yield rescue Fluent::Plugin::Buffer::BufferOverflowError log.warn "failed to write data into buffer by buffer overflow", action: @buffer_config.overflow_action case @buffer_config.overflow_action diff --git a/lib/fluent/plugin/parser_json.rb b/lib/fluent/plugin/parser_json.rb index 05d2fe4921..6623270aad 100644 --- a/lib/fluent/plugin/parser_json.rb +++ b/lib/fluent/plugin/parser_json.rb @@ -93,10 +93,10 @@ def parser_type :text end - def parse_io(io, &block) + def parse_io(io) y = Yajl::Parser.new y.on_parse_complete = ->(record){ - block.call(parse_time(record), record) + yield(parse_time(record), record) } y.parse(io, @stream_buffer_size) end diff --git a/lib/fluent/plugin/storage_local.rb b/lib/fluent/plugin/storage_local.rb index 3cd8addc12..d191daf463 100644 --- a/lib/fluent/plugin/storage_local.rb +++ b/lib/fluent/plugin/storage_local.rb @@ -158,8 +158,8 @@ def delete(key) @store.delete(key.to_s) end - def update(key, &block) - @store[key.to_s] = block.call(@store[key.to_s]) + def update(key) + @store[key.to_s] = yield(@store[key.to_s]) end end end diff --git a/lib/fluent/plugin_helper/compat_parameters.rb b/lib/fluent/plugin_helper/compat_parameters.rb index bd2819f64b..f669f7461e 100644 --- a/lib/fluent/plugin_helper/compat_parameters.rb +++ b/lib/fluent/plugin_helper/compat_parameters.rb @@ -324,13 +324,13 @@ def compat_parameters_formatter(conf) conf end - def compat_parameters_copy_to_subsection_attributes(conf, params, &block) + def compat_parameters_copy_to_subsection_attributes(conf, params) hash = {} params.each do |compat, current| next unless current if conf.has_key?(compat) if block_given? - hash[current] = block.call(compat, conf[compat]) + hash[current] = yield(compat, conf[compat]) else hash[current] = conf[compat] end diff --git a/lib/fluent/plugin_helper/formatter.rb b/lib/fluent/plugin_helper/formatter.rb index de0dc60b71..da26727d1c 100644 --- a/lib/fluent/plugin_helper/formatter.rb +++ b/lib/fluent/plugin_helper/formatter.rb @@ -100,11 +100,11 @@ def start end end - def formatter_operate(method_name, &block) + def formatter_operate(method_name) @_formatters.each_pair do |usage, formatter| begin formatter.__send__(method_name) - block.call(formatter) if block_given? + yield(formatter) if block_given? rescue => e log.error "unexpected error while #{method_name}", usage: usage, formatter: formatter, error: e end diff --git a/lib/fluent/plugin_helper/parser.rb b/lib/fluent/plugin_helper/parser.rb index 7d1c91a0a2..916262862a 100644 --- a/lib/fluent/plugin_helper/parser.rb +++ b/lib/fluent/plugin_helper/parser.rb @@ -100,11 +100,11 @@ def start end end - def parser_operate(method_name, &block) + def parser_operate(method_name) @_parsers.each_pair do |usage, parser| begin parser.__send__(method_name) - block.call(parser) if block_given? + yield(parser) if block_given? rescue => e log.error "unexpected error while #{method_name}", usage: usage, parser: parser, error: e end diff --git a/lib/fluent/plugin_helper/storage.rb b/lib/fluent/plugin_helper/storage.rb index 21cc6d05c9..b6761b99ec 100644 --- a/lib/fluent/plugin_helper/storage.rb +++ b/lib/fluent/plugin_helper/storage.rb @@ -134,10 +134,10 @@ def start end end - def storage_operate(method_name, &block) + def storage_operate(method_name) @_storages.each_pair do |usage, s| begin - block.call(s) if block_given? + yield(s) if block_given? s.storage.__send__(method_name) rescue => e log.error "unexpected error while #{method_name}", usage: usage, storage: s.storage, error: e @@ -275,7 +275,7 @@ def delete(key) def update(key, &block) @monitor.synchronize do @storage.load - v = block.call(@storage.get(key)) + v = yield(@storage.get(key)) @storage.put(key, v) @storage.save v @@ -338,7 +338,7 @@ def delete(key) def update(key, &block) @monitor.synchronize do - v = block.call(@storage.get(key)) + v = yield(@storage.get(key)) @storage.put(key, v) v end diff --git a/lib/fluent/rpc.rb b/lib/fluent/rpc.rb index bcee80592b..1e496abdaa 100644 --- a/lib/fluent/rpc.rb +++ b/lib/fluent/rpc.rb @@ -39,10 +39,10 @@ def mount(path, servlet, *args) @log.debug "register #{path} RPC servlet" end - def mount_proc(path, &block) + def mount_proc(path) @server.mount_proc(path) { |req, res| begin - code, header, response = block.call(req, res) + code, header, response = yield(req, res) rescue => e @log.warn "failed to handle RPC request", path: path, error: e.to_s @log.warn_backtrace e.backtrace diff --git a/lib/fluent/supervisor.rb b/lib/fluent/supervisor.rb index 34d9dadceb..08b08ee24d 100644 --- a/lib/fluent/supervisor.rb +++ b/lib/fluent/supervisor.rb @@ -1142,7 +1142,7 @@ def logging_with_console_output end end - def main_process(&block) + def main_process if @system_config.process_name if @system_config.workers > 1 Process.setproctitle("worker:#{@system_config.process_name}#{ENV['SERVERENGINE_WORKER_ID']}") @@ -1154,7 +1154,7 @@ def main_process(&block) unrecoverable_error = false begin - block.call + yield rescue Fluent::ConfigError => e logging_with_console_output do |log| log.error "config error", file: @config_path, error: e diff --git a/lib/fluent/test/driver/base.rb b/lib/fluent/test/driver/base.rb index 9ba26edaf6..b76c0cf180 100644 --- a/lib/fluent/test/driver/base.rb +++ b/lib/fluent/test/driver/base.rb @@ -185,7 +185,7 @@ def instance_shutdown(log: Logger.new($stdout)) end end - def run_actual(timeout: DEFAULT_TIMEOUT, &block) + def run_actual(timeout: DEFAULT_TIMEOUT) if @instance.respond_to?(:_threads) sleep 0.1 until @instance._threads.values.all?(&:alive?) end @@ -201,7 +201,7 @@ def run_actual(timeout: DEFAULT_TIMEOUT, &block) return_value = nil begin Timeout.timeout(timeout * 2) do |sec| - return_value = block.call if block_given? + return_value = yield if block_given? end rescue Timeout::Error raise TestTimedOut, "Test case timed out with hard limit." diff --git a/lib/fluent/test/filter_test.rb b/lib/fluent/test/filter_test.rb index 7495a268d9..054b8589e0 100644 --- a/lib/fluent/test/filter_test.rb +++ b/lib/fluent/test/filter_test.rb @@ -59,9 +59,9 @@ def filtered_as_array alias_method :emits, :filtered_as_array # emits is for consistent with other drivers # Almost filters don't use threads so default is 0. It reduces test time. - def run(num_waits = 0, &block) + def run(num_waits = 0) super(num_waits) { - block.call if block + yield if block_given? @events.each { |tag, es| processed = @instance.filter_stream(tag, es) diff --git a/lib/fluent/test/input_test.rb b/lib/fluent/test/input_test.rb index 0490c6a031..2e4f824bb4 100644 --- a/lib/fluent/test/input_test.rb +++ b/lib/fluent/test/input_test.rb @@ -109,7 +109,7 @@ def emit_stream(tag, es) end end - def run(num_waits = 10, &block) + def run(num_waits = 10) m = method(:emit_stream) unless Engine.singleton_class.ancestors.include?(EmitStreamWrapper) Engine.singleton_class.prepend EmitStreamWrapper @@ -121,7 +121,7 @@ def run(num_waits = 10, &block) instance.router.emit_stream_callee = m super(num_waits) { - block.call if block + yield if block_given? if @expected_emits_length || @expects || @run_post_conditions # counters for emits and emit_streams diff --git a/lib/fluent/test/output_test.rb b/lib/fluent/test/output_test.rb index bb18884dc2..3cfc1a86a0 100644 --- a/lib/fluent/test/output_test.rb +++ b/lib/fluent/test/output_test.rb @@ -71,10 +71,10 @@ def expect_format(str) (@expected_buffer ||= '') << str end - def run(num_waits = 10, &block) + def run(num_waits = 10) result = nil super(num_waits) { - block.call if block + yield if block_given? es = ArrayEventStream.new(@entries) buffer = @instance.format_stream(@tag, es) @@ -119,10 +119,10 @@ def expect_format(str) (@expected_buffer ||= '') << str end - def run(&block) + def run result = [] super { - block.call if block + yield if block_given? buffer = '' lines = {}