Class: Kubetailrb::Formatter::JsonFormatter

Inherits:
Object
  • Object
show all
Includes:
Painter, Validated
Defined in:
lib/kubetailrb/formatter/json_formatter.rb

Overview

Format JSON to human readable.

Instance Method Summary collapse

Methods included from Validated

#raise_if_blank, #raise_if_nil, #validate_boolean, #validate_last_nb_lines

Methods included from Painter

#blue, #cyan, #highlight_blue, #highlight_grey, #highlight_red, #highlight_yellow, #red

Constructor Details

#initialize(mdcs = []) ⇒ JsonFormatter

Returns a new instance of JsonFormatter.



13
14
15
16
17
# File 'lib/kubetailrb/formatter/json_formatter.rb', line 13

def initialize(mdcs = [])
  @mdcs = mdcs

  validate
end

Instance Method Details

#format(log) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/kubetailrb/formatter/json_formatter.rb', line 19

def format(log)
  json = JSON.parse(log)

  return format_access_log(json) if access_log?(json)

  format_application_log(json)
rescue JSON::ParserError
  log
end