Method: Logging::Layout#initialize

Defined in:
lib/logging/layout.rb

#initialize(opts = {}) ⇒ Layout

call-seq:

Layout.new( :format_as => :string )

Creates a new layout that will format objecs as strings using the given :format_as style. This can be one of :string, :inspect, or :yaml. These formatting commands map to the following object methods:

  • :string => to_s

  • :inspect => inspect

  • :yaml => to_yaml

If the format is not specified then the global object format is used (see Logging#format_as). If the global object format is not specified then :string is used.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/logging/layout.rb', line 32

def initialize( opts = {} )
  default = ::Logging.const_defined?('OBJ_FORMAT') ?
            ::Logging::OBJ_FORMAT : nil

  f = opts.getopt(:format_as, default)
  f = f.intern if f.instance_of? String

  @obj_format = case f
                when :inspect, :yaml; f
                else :string end

  b = opts.getopt(:backtrace, ::Logging.backtrace)
  @backtrace = case b
      when :on, 'on', true;    true
      when :off, 'off', false; false
      else
        raise ArgumentError, "backtrace must be true or false"
      end
end