Class: Krane::ContainerLogs

Inherits:
Object
  • Object
show all
Defined in:
lib/krane/container_logs.rb

Constant Summary collapse

DEFAULT_LINE_LIMIT =
Integer(ENV.fetch('KRANE_LOG_LINE_LIMIT', 25))

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent_id:, container_name:, namespace:, context:, logger:) ⇒ ContainerLogs

Returns a new instance of ContainerLogs.



8
9
10
11
12
13
14
15
16
17
# File 'lib/krane/container_logs.rb', line 8

def initialize(parent_id:, container_name:, namespace:, context:, logger:)
  @parent_id = parent_id
  @container_name = container_name
  @namespace = namespace
  @context = context
  @logger = logger
  @lines = []
  @next_print_index = 0
  @printed_latest = false
end

Instance Attribute Details

#container_nameObject (readonly)

Returns the value of attribute container_name.



4
5
6
# File 'lib/krane/container_logs.rb', line 4

def container_name
  @container_name
end

#linesObject (readonly)

Returns the value of attribute lines.



4
5
6
# File 'lib/krane/container_logs.rb', line 4

def lines
  @lines
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/krane/container_logs.rb', line 25

def empty?
  lines.empty?
end


40
41
42
# File 'lib/krane/container_logs.rb', line 40

def print_all
  lines.each { |line| @logger.info("\t#{line}") }
end


29
30
31
32
33
34
35
36
37
38
# File 'lib/krane/container_logs.rb', line 29

def print_latest(prefix: false)
  prefix_str = "[#{container_name}]  " if prefix

  lines[@next_print_index..-1].each do |msg|
    @logger.info("#{prefix_str}#{msg}")
  end

  @next_print_index = lines.length
  @printed_latest = true
end

#printing_started?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/krane/container_logs.rb', line 44

def printing_started?
  @printed_latest
end

#syncObject



19
20
21
22
23
# File 'lib/krane/container_logs.rb', line 19

def sync
  new_logs = fetch_latest
  return unless new_logs.present?
  @lines += sort_and_deduplicate(new_logs)
end