Module: LogStashLogger::Formatter
- Defined in:
- lib/logstash-logger/formatter.rb,
lib/logstash-logger/formatter/cee.rb,
lib/logstash-logger/formatter/base.rb,
lib/logstash-logger/formatter/json.rb,
lib/logstash-logger/formatter/cee_syslog.rb,
lib/logstash-logger/formatter/json_lines.rb,
lib/logstash-logger/formatter/logstash_event.rb
Defined Under Namespace
Classes: Base, Cee, CeeSyslog, Json, JsonLines, LogStashEvent
Constant Summary
collapse
- DEFAULT_FORMATTER =
:json_lines
- HOST =
::Socket.gethostname
Class Method Summary
collapse
Class Method Details
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/logstash-logger/formatter.rb', line 17
def self.build_formatter(formatter_type)
formatter_type ||= DEFAULT_FORMATTER
formatter = if custom_formatter_instance?(formatter_type)
formatter_type
elsif custom_formatter_class?(formatter_type)
formatter_type.new
else
formatter_klass(formatter_type).new
end
formatter.send(:extend, ::LogStashLogger::TaggedLogging::Formatter)
formatter
end
|
47
48
49
|
# File 'lib/logstash-logger/formatter.rb', line 47
def self.custom_formatter_class?(formatter_type)
formatter_type.is_a?(Class) && formatter_type.method_defined?(:call)
end
|
43
44
45
|
# File 'lib/logstash-logger/formatter.rb', line 43
def self.custom_formatter_instance?(formatter_type)
formatter_type.respond_to?(:call)
end
|
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/logstash-logger/formatter.rb', line 32
def self.formatter_klass(formatter_type)
case formatter_type.to_sym
when :json_lines then JsonLines
when :json then Json
when :logstash_event then LogStashEvent
when :cee then Cee
when :cee_syslog then CeeSyslog
else fail ArgumentError, 'Invalid formatter'
end
end
|
.new(formatter_type) ⇒ Object
13
14
15
|
# File 'lib/logstash-logger/formatter.rb', line 13
def self.new(formatter_type)
build_formatter(formatter_type)
end
|