Class: Kontena::Cli::LogFormatter::Compact

Inherits:
Logger::Formatter
  • Object
show all
Defined in:
lib/kontena/cli/log_formatters/compact.rb

Constant Summary collapse

DEBUG_INDICATOR =
Kontena.pastel.inverse.bright_blue('DEBUG').freeze
WARN_INDICATOR =
Kontena.pastel.inverse.yellow('WARN ').freeze
INFO_INDICATOR =
Kontena.pastel.inverse.cyan('INFO ').freeze
ERROR_INDICATOR =
Kontena.pastel.inverse.red('ERROR').freeze
TS_FORMAT =
'%4d'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.__init_timers__Object



17
18
19
20
# File 'lib/kontena/cli/log_formatters/compact.rb', line 17

def self.__init_timers__
  @first_log = $KONTENA_START_TIME || Time.now.to_f
  @last_log = @first_log
end

.ms_since_firstObject



7
8
9
# File 'lib/kontena/cli/log_formatters/compact.rb', line 7

def self.ms_since_first
  Time.now.to_f - @first_log
end

.ms_since_lastObject



11
12
13
14
15
# File 'lib/kontena/cli/log_formatters/compact.rb', line 11

def self.ms_since_last
  ((Time.now.to_f - @last_log) * 1000).to_i
ensure
  @last_log = Time.now.to_f
end

Instance Method Details

#colorize_severity(severity) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/kontena/cli/log_formatters/compact.rb', line 29

def colorize_severity(severity)
  case severity[0..0]
  when 'D' then DEBUG_INDICATOR
  when 'W' then WARN_INDICATOR
  when 'I' then INFO_INDICATOR
  when 'E', 'F' then ERROR_INDICATOR
  else severity[0..0]
  end
end

#colorized_timeObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/kontena/cli/log_formatters/compact.rb', line 41

def colorized_time
  elapsed = self.class.ms_since_last
  ts = TS_FORMAT % [elapsed]
  if elapsed > 300
    Kontena.pastel.red(ts)
  elsif elapsed > 100
    Kontena.pastel.yellow(ts)
  else
    ts
  end
end