Skip to content

Commit

Permalink
Merge pull request #806 from cosmo0920/v0.12-hash-syntax
Browse files Browse the repository at this point in the history
 Back port enforce new hash syntax by `rubocop --only HashSyntax --auto-correct` (#795)
  • Loading branch information
repeatedly committed Feb 16, 2016
2 parents 14bfef2 + eb1478d commit 9beac48
Show file tree
Hide file tree
Showing 42 changed files with 368 additions and 369 deletions.
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'fileutils'
require 'rake/testtask'
require 'rake/clean'

task :test => [:base_test]
task test: [:base_test]

desc 'Run test_unit based test'
Rake::TestTask.new(:base_test) do |t|
Expand All @@ -30,4 +30,4 @@ task :coverage do |t|
Rake::Task["test"].invoke
end

task :default => [:test, :build]
task default: [:test, :build]
12 changes: 6 additions & 6 deletions lib/fluent/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def shutdown
log.info "shutting down filter#{@context.nil? ? '' : " in #{@context}"}", type: Plugin.lookup_name_from_class(f.class), plugin_id: f.plugin_id
f.shutdown
rescue => e
log.warn "unexpected error while shutting down filter plugins", :plugin => f.class, :plugin_id => f.plugin_id, :error_class => e.class, :error => e
log.warn "unexpected error while shutting down filter plugins", plugin: f.class, plugin_id: f.plugin_id, error_class: e.class, error: e
log.warn_backtrace
end
end
Expand All @@ -95,7 +95,7 @@ def shutdown
log.info "shutting down output#{@context.nil? ? '' : " in #{@context}"}", type: Plugin.lookup_name_from_class(o.class), plugin_id: o.plugin_id
o.shutdown
rescue => e
log.warn "unexpected error while shutting down output plugins", :plugin => o.class, :plugin_id => o.plugin_id, :error_class => e.class, :error => e
log.warn "unexpected error while shutting down output plugins", plugin: o.class, plugin_id: o.plugin_id, error_class: e.class, error: e
log.warn_backtrace
end
end
Expand All @@ -115,7 +115,7 @@ def flush_recursive(array)
flush_recursive(o.outputs)
end
rescue => e
log.debug "error while force flushing", :error_class => e.class, :error => e
log.debug "error while force flushing", error_class: e.class, error: e
log.debug_backtrace
end
}
Expand Down Expand Up @@ -163,16 +163,16 @@ def emit(tag, es, chain)
c = (@count += 1)
if c < 512
if Math.log(c) / Math.log(2) % 1.0 == 0
@log.warn "no patterns matched", :tag => tag
@log.warn "no patterns matched", tag: tag
return
end
else
if c % 512 == 0
@log.warn "no patterns matched", :tag => tag
@log.warn "no patterns matched", tag: tag
return
end
end
@log.on_trace { @log.trace "no patterns matched", :tag => tag }
@log.on_trace { @log.trace "no patterns matched", tag: tag }
end

def start
Expand Down
6 changes: 3 additions & 3 deletions lib/fluent/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ def enable_parallel(b=true)
# Local file based plugins which should provide more reliability and efficiency
# should override buffer_chunk_limit with a larger size.
desc 'The size of each buffer chunk.'
config_param :buffer_chunk_limit, :size, :default => 8*1024*1024
config_param :buffer_chunk_limit, :size, default: 8*1024*1024
desc 'The length limit of the chunk queue.'
config_param :buffer_queue_limit, :integer, :default => 256
config_param :buffer_queue_limit, :integer, default: 256
desc 'The action when the size of buffer queue exceeds the buffer_queue_limit.'
config_param :buffer_queue_full_action, :enum, :list => [:exception, :block], :default => :exception
config_param :buffer_queue_full_action, :enum, list: [:exception, :block], default: :exception

alias chunk_limit buffer_chunk_limit
alias chunk_limit= buffer_chunk_limit=
Expand Down
4 changes: 2 additions & 2 deletions lib/fluent/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def log_event_loop
begin
@event_router.emit(tag, time, record)
rescue => e
$log.error "failed to emit fluentd's log event", :tag => tag, :event => record, :error_class => e.class, :error => e
$log.error "failed to emit fluentd's log event", tag: tag, event: record, error_class: e.class, error: e
end
}
end
Expand Down Expand Up @@ -197,7 +197,7 @@ def run
end

rescue => e
$log.error "unexpected error", :error_class=>e.class, :error=>e
$log.error "unexpected error", error_class: e.class, error: e
$log.error_backtrace
ensure
$log.info "shutting down fluentd"
Expand Down
46 changes: 23 additions & 23 deletions lib/fluent/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ module TextFormatter
module HandleTagAndTimeMixin
def self.included(klass)
klass.instance_eval {
config_param :include_time_key, :bool, :default => false
config_param :time_key, :string, :default => 'time'
config_param :time_format, :string, :default => nil
config_param :include_tag_key, :bool, :default => false
config_param :tag_key, :string, :default => 'tag'
config_param :localtime, :bool, :default => true
config_param :timezone, :string, :default => nil
config_param :include_time_key, :bool, default: false
config_param :time_key, :string, default: 'time'
config_param :time_format, :string, default: nil
config_param :include_tag_key, :bool, default: false
config_param :tag_key, :string, default: 'tag'
config_param :localtime, :bool, default: true
config_param :timezone, :string, default: nil
}
end

Expand All @@ -65,9 +65,9 @@ def filter_record(tag, time, record)
class OutFileFormatter < Formatter
include HandleTagAndTimeMixin

config_param :output_time, :bool, :default => true
config_param :output_tag, :bool, :default => true
config_param :delimiter, :default => "\t" do |val|
config_param :output_time, :bool, default: true
config_param :output_tag, :bool, default: true
config_param :delimiter, default: "\t" do |val|
case val
when /SPACE/i then ' '
when /COMMA/i then ','
Expand All @@ -85,7 +85,7 @@ def format(tag, time, record)
end

class StdoutFormatter < Formatter
config_param :output_type, :string, :default => 'json'
config_param :output_type, :string, default: 'json'

def configure(conf)
super
Expand All @@ -103,7 +103,7 @@ def format(tag, time, record)
module StructuredFormatMixin
def self.included(klass)
klass.instance_eval {
config_param :time_as_epoch, :bool, :default => false
config_param :time_as_epoch, :bool, default: false
}
end

Expand Down Expand Up @@ -131,15 +131,15 @@ class JSONFormatter < Formatter
include HandleTagAndTimeMixin
include StructuredFormatMixin

config_param :json_parser, :string, :default => 'oj'
config_param :json_parser, :string, default: 'oj'

def configure(conf)
super

begin
raise LoadError unless @json_parser == 'oj'
require 'oj'
Oj.default_options = {:mode => :compat}
Oj.default_options = {mode: :compat}
@dump_proc = Oj.method(:dump)
rescue LoadError
@dump_proc = Yajl.method(:dump)
Expand Down Expand Up @@ -172,8 +172,8 @@ def format_record(record)
class LabeledTSVFormatter < Formatter
include HandleTagAndTimeMixin

config_param :delimiter, :string, :default => "\t"
config_param :label_delimiter, :string, :default => ":"
config_param :delimiter, :string, default: "\t"
config_param :label_delimiter, :string, default: ":"

def format(tag, time, record)
filter_record(tag, time, record)
Expand All @@ -189,11 +189,11 @@ def format(tag, time, record)
class CsvFormatter < Formatter
include HandleTagAndTimeMixin

config_param :delimiter, :default => ',' do |val|
config_param :delimiter, default: ',' do |val|
['\t', 'TAB'].include?(val) ? "\t" : val
end
config_param :force_quotes, :bool, :default => true
config_param :fields, :default => [] do |val|
config_param :force_quotes, :bool, default: true
config_param :fields, default: [] do |val|
val.split(',').map do |f|
f.strip!
f.size > 0 ? f : nil
Expand All @@ -211,14 +211,14 @@ def format(tag, time, record)
memo << record[key]
memo
end
CSV.generate_line(row, :col_sep => @delimiter,
:force_quotes => @force_quotes)
CSV.generate_line(row, col_sep: @delimiter,
force_quotes: @force_quotes)
end
end

class SingleValueFormatter < Formatter
config_param :message_key, :string, :default => 'message'
config_param :add_newline, :bool, :default => true
config_param :message_key, :string, default: 'message'
config_param :add_newline, :bool, default: true

def format(tag, time, record)
text = record[@message_key].to_s.dup
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ module PluginLoggerMixin
def self.included(klass)
klass.instance_eval {
desc 'Allows the user to set different levels of logging for each plugin.'
config_param :log_level, :string, :default => nil, :alias => :@log_level
config_param :log_level, :string, default: nil, alias: :@log_level
}
end

Expand Down
45 changes: 22 additions & 23 deletions lib/fluent/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def shutdown

def secondary_init(primary)
if primary.class != self.class
$log.warn "type of secondary output should be same as primary output", :primary=>primary.class.to_s, :secondary=>self.class.to_s
$log.warn "type of secondary output should be same as primary output", primary: primary.class.to_s, secondary: self.class.to_s
end
end
end
Expand Down Expand Up @@ -152,7 +152,7 @@ def run
@mutex.unlock
end
rescue
$log.error "error on output thread", :error=>$!.to_s
$log.error "error on output thread", error: $!.to_s
$log.error_backtrace
raise
ensure
Expand Down Expand Up @@ -180,22 +180,22 @@ def initialize
end

desc 'The buffer type (memory, file)'
config_param :buffer_type, :string, :default => 'memory'
config_param :buffer_type, :string, default: 'memory'
desc 'The interval between data flushes.'
config_param :flush_interval, :time, :default => 60
config_param :try_flush_interval, :float, :default => 1
config_param :flush_interval, :time, default: 60
config_param :try_flush_interval, :float, default: 1
desc 'If true, the value of `retry_value` is ignored and there is no limit'
config_param :disable_retry_limit, :bool, :default => false
config_param :disable_retry_limit, :bool, default: false
desc 'The limit on the number of retries before buffered data is discarded'
config_param :retry_limit, :integer, :default => 17
config_param :retry_limit, :integer, default: 17
desc 'The initial intervals between write retries.'
config_param :retry_wait, :time, :default => 1.0
config_param :retry_wait, :time, default: 1.0
desc 'The maximum intervals between write retries.'
config_param :max_retry_wait, :time, :default => nil
config_param :max_retry_wait, :time, default: nil
desc 'The number of threads to flush the buffer.'
config_param :num_threads, :integer, :default => 1
config_param :num_threads, :integer, default: 1
desc 'The interval between data flushes for queued chunk.'
config_param :queued_chunk_flush_interval, :time, :default => 1
config_param :queued_chunk_flush_interval, :time, default: 1

def configure(conf)
super
Expand Down Expand Up @@ -334,7 +334,7 @@ def try_flush
@num_errors = 0
# Note: don't notify to other threads to prevent
# burst to recovered server
$log.warn "retry succeeded.", :plugin_id=>plugin_id
$log.warn "retry succeeded.", plugin_id: plugin_id
end

if has_next
Expand All @@ -359,28 +359,28 @@ def try_flush
end

if @disable_retry_limit || error_count < @retry_limit
$log.warn "temporarily failed to flush the buffer.", :next_retry=>Time.at(@next_retry_time), :error_class=>e.class.to_s, :error=>e.to_s, :plugin_id=>plugin_id
$log.warn "temporarily failed to flush the buffer.", next_retry: Time.at(@next_retry_time), error_class: e.class.to_s, error: e.to_s, plugin_id: plugin_id
$log.warn_backtrace e.backtrace

elsif @secondary
if error_count == @retry_limit
$log.warn "failed to flush the buffer.", :error_class=>e.class.to_s, :error=>e.to_s, :plugin_id=>plugin_id
$log.warn "failed to flush the buffer.", error_class: e.class.to_s, error: e.to_s, plugin_id: plugin_id
$log.warn "retry count exceededs limit. falling back to secondary output."
$log.warn_backtrace e.backtrace
retry # retry immediately
elsif error_count <= @retry_limit + @secondary_limit
$log.warn "failed to flush the buffer, next retry will be with secondary output.", :next_retry=>Time.at(@next_retry_time), :error_class=>e.class.to_s, :error=>e.to_s, :plugin_id=>plugin_id
$log.warn "failed to flush the buffer, next retry will be with secondary output.", next_retry: Time.at(@next_retry_time), error_class: e.class.to_s, error: e.to_s, plugin_id: plugin_id
$log.warn_backtrace e.backtrace
else
$log.warn "failed to flush the buffer.", :error_class=>e.class, :error=>e.to_s, :plugin_id=>plugin_id
$log.warn "failed to flush the buffer.", error_class: e.class, error: e.to_s, plugin_id: plugin_id
$log.warn "secondary retry count exceededs limit."
$log.warn_backtrace e.backtrace
write_abort
@num_errors = 0
end

else
$log.warn "failed to flush the buffer.", :error_class=>e.class.to_s, :error=>e.to_s, :plugin_id=>plugin_id
$log.warn "failed to flush the buffer.", error_class: e.class.to_s, error: e.to_s, plugin_id: plugin_id
$log.warn "retry count exceededs limit."
$log.warn_backtrace e.backtrace
write_abort
Expand All @@ -403,7 +403,7 @@ def before_shutdown
begin
@buffer.before_shutdown(self)
rescue
$log.warn "before_shutdown failed", :error=>$!.to_s
$log.warn "before_shutdown failed", error: $!.to_s
$log.warn_backtrace
end
end
Expand All @@ -425,7 +425,7 @@ def write_abort
begin
@buffer.clear!
rescue
$log.error "unexpected error while aborting", :error=>$!.to_s
$log.error "unexpected error while aborting", error: $!.to_s
$log.error_backtrace
end
end
Expand Down Expand Up @@ -483,11 +483,11 @@ def initialize
end

desc 'The time format used as part of the file name.'
config_param :time_slice_format, :string, :default => '%Y%m%d'
config_param :time_slice_format, :string, default: '%Y%m%d'
desc 'The amount of time Fluentd will wait for old logs to arrive.'
config_param :time_slice_wait, :time, :default => 10*60
config_param :time_slice_wait, :time, default: 10*60
desc 'Parse the time value in the specified timezone'
config_param :timezone, :string, :default => nil
config_param :timezone, :string, default: nil
config_set_default :buffer_type, 'file' # overwrite default buffer_type
config_set_default :buffer_chunk_limit, 256*1024*1024 # overwrite default buffer_chunk_limit
config_set_default :flush_interval, nil
Expand Down Expand Up @@ -609,4 +609,3 @@ class MultiOutput < Output
#end
end
end

Loading

0 comments on commit 9beac48

Please sign in to comment.