Class: Logging::Layouts::Parseable

Inherits:
Object
  • Object
show all
Defined in:
lib/logging/lumberjack.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_lumberjack_format_method(layout) ⇒ Object

addition



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/logging/lumberjack.rb', line 45

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

	code << layout.items.map {|name|
		"'#{name}' => #{Parseable::DIRECTIVE_TABLE[name]}"
	}.join(",\n")
	code << "\n}\n\"@cee: \" + MultiJson.encode(h) << \"\\n\"\nend\n"

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

.lumberjack(opts = {}) ⇒ Object

addition



29
30
31
32
# File 'lib/logging/lumberjack.rb', line 29

def self.lumberjack( opts = {} )
	opts[:style] = "lumberjack"
	new(opts)
end

Instance Method Details

#create_format_methodObject

monkey patch



35
36
37
38
39
40
41
# File 'lib/logging/lumberjack.rb', line 35

def create_format_method
	case @style
	when :json; Parseable.create_json_format_method(self)
	when :yaml; Parseable.create_yaml_format_method(self)
	when :lumberjack; Parseable.create_lumberjack_format_method(self)
	else raise ArgumentError, "unknown format style '#@style'" end
end