class Lumberjack::Formatter::DateTimeFormatter

Format a Date, Time, or DateTime object. If you don't specify a format in the constructor, it will use the ISO-8601 format.

Attributes

format[R]

Public Class Methods

new(format = nil) click to toggle source
# File lib/lumberjack/formatter/date_time_formatter.rb, line 10
def initialize(format = nil)
  @format = format.dup.to_s.freeze unless format.nil?
end

Public Instance Methods

call(obj) click to toggle source
# File lib/lumberjack/formatter/date_time_formatter.rb, line 14
def call(obj)
  if @format && obj.respond_to?(:strftime)
    obj.strftime(@format)
  elsif obj.respond_to?(:iso8601)
    obj.iso8601
  else
    obj.to_s
  end
end