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

.build_formatter(formatter_type) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/logstash-logger/formatter.rb', line 17

def self.build_formatter(formatter_type)
  formatter_type ||= DEFAULT_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
end

.custom_formatter_class?(formatter_type) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/logstash-logger/formatter.rb', line 44

def self.custom_formatter_class?(formatter_type)
  formatter_type.is_a?(Class) && formatter_type.method_defined?(:call)
end

.custom_formatter_instance?(formatter_type) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/logstash-logger/formatter.rb', line 40

def self.custom_formatter_instance?(formatter_type)
  formatter_type.respond_to?(:call)
end

.formatter_klass(formatter_type) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/logstash-logger/formatter.rb', line 29

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