Method: Logsly::Logging182::Layouts::Parseable.create_yaml_format_method

Defined in:
lib/logsly/logging182/layouts/parseable.rb

.create_yaml_format_method(layout) ⇒ Object

call-seq:

Pattern.create_yaml_format_methods( layout )

This method will create the format method in the given Parseable layout based on the configured items for the layout instance.



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/logsly/logging182/layouts/parseable.rb', line 119

def self.create_yaml_format_method( layout )
  code = "undef :format if method_defined? :format\n"
  code << "def format( event )\nstr = {\n"

  code << layout.items.map {|name|
    "'#{name}' => #{Parseable::DIRECTIVE_TABLE[name]}"
  }.join(",\n")
  code << "\n}.to_yaml\nreturn str\nend\n"

  (class << layout; self end).class_eval(code, __FILE__, __LINE__)
end