Parent

Class/Module Index [+]

Quicksearch

Fluent::TimeFormatter

Public Class Methods

configure(conf) click to toggle source
# File lib/fluent/mixin.rb, line 73
def self.configure(conf)
  if time_format = conf['time_format']
    @time_format = time_format
  end

  if localtime = conf['localtime']
    @localtime = true
  elsif utc = conf['utc']
    @localtime = false
  end

  @timef = new(@time_format, @localtime)
end
new(format, localtime) click to toggle source
# File lib/fluent/mixin.rb, line 22
def initialize(format, localtime)
  @tc1 = 0
  @tc1_str = nil
  @tc2 = 0
  @tc2_str = nil

  if format
    if localtime
      define_singleton_method(:format_nocache) {|time|
        Time.at(time).strftime(format)
      }
    else
      define_singleton_method(:format_nocache) {|time|
        Time.at(time).utc.strftime(format)
      }
    end
  else
    if localtime
      define_singleton_method(:format_nocache) {|time|
        Time.at(time).iso8601
      }
    else
      define_singleton_method(:format_nocache) {|time|
        Time.at(time).utc.iso8601
      }
    end
  end
end

Public Instance Methods

format(time) click to toggle source
# File lib/fluent/mixin.rb, line 51
def format(time)
  if @tc1 == time
    return @tc1_str
  elsif @tc2 == time
    return @tc2_str
  else
    str = format_nocache(time)
    if @tc1 < @tc2
      @tc1 = time
      @tc1_str = str
    else
      @tc2 = time
      @tc2_str = str
    end
    return str
  end
end
format_nocache(time) click to toggle source
# File lib/fluent/mixin.rb, line 69
def format_nocache(time)
  # will be overridden in initialize
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.