Class: Fluent::Plugin::OutFileFormatter
- Defined in:
- lib/fluent/plugin/formatter_out_file.rb
Direct Known Subclasses
Constant Summary
Constants included from Configurable
Configurable::CONFIG_TYPE_REGISTRY
Instance Method Summary collapse
Methods included from OwnedByMixin
Methods inherited from Base
#after_shutdown, #after_shutdown?, #after_start, #after_started?, #before_shutdown, #before_shutdown?, #close, #closed?, #configured?, #has_router?, #initialize, #inspect, #shutdown, #shutdown?, #start, #started?, #stop, #stopped?, #terminate, #terminated?
Methods included from SystemConfig::Mixin
#system_config, #system_config_override
Methods included from Configurable
#config, included, #initialize, lookup_type, register_type
Constructor Details
This class inherits a constructor from Fluent::Plugin::Base
Instance Method Details
#configure(conf) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/fluent/plugin/formatter_out_file.rb', line 40 def configure(conf) # TODO: make a utility method in TimeFormatter to handle these conversion # copies of this code: plugin_helper/compat_parameters, compat/formatter_utils and here if conf.has_key?('time_as_epoch') && Fluent::Config.bool_value(conf['time_as_epoch']) conf['time_type'] = 'unixtime' end if conf.has_key?('localtime') || conf.has_key?('utc') if conf.has_key?('localtime') && conf.has_key?('utc') raise Fluent::ConfigError, "both of utc and localtime are specified, use only one of them" elsif conf.has_key?('localtime') conf['localtime'] = Fluent::Config.bool_value(conf['localtime']) elsif conf.has_key?('utc') conf['localtime'] = !(Fluent::Config.bool_value(conf['utc'])) # Specifying "localtime false" means using UTC in TimeFormatter # And specifying "utc" is different from specifying "timezone +0000"(it's not always UTC). # There are difference between "Z" and "+0000" in timezone formatting. # TODO: add kwargs to TimeFormatter to specify "using localtime", "using UTC" or "using specified timezone" in more explicit way end end super @timef = case @time_type when :float then ->(time){ time.to_r.to_f } when :unixtime then ->(time){ time.to_i } else Fluent::TimeFormatter.new(@time_format, @localtime, @timezone) end end |
#format(tag, time, record) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/fluent/plugin/formatter_out_file.rb', line 70 def format(tag, time, record) header = '' header << "#{@timef.format(time)}#{@delimiter}" if @output_time header << "#{tag}#{@delimiter}" if @output_tag "#{header}#{Yajl.dump(record)}\n" end |