Class: Krane::ContainerLogs
- Inherits:
-
Object
- Object
- Krane::ContainerLogs
- 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
-
#container_name ⇒ Object
readonly
Returns the value of attribute container_name.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(parent_id:, container_name:, namespace:, context:, logger:) ⇒ ContainerLogs
constructor
A new instance of ContainerLogs.
- #print_all ⇒ Object
- #print_latest(prefix: false) ⇒ Object
- #printing_started? ⇒ Boolean
- #sync ⇒ Object
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_name ⇒ Object (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 |
#lines ⇒ Object (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
25 26 27 |
# File 'lib/krane/container_logs.rb', line 25 def empty? lines.empty? end |
#print_all ⇒ Object
40 41 42 |
# File 'lib/krane/container_logs.rb', line 40 def print_all lines.each { |line| @logger.info("\t#{line}") } end |
#print_latest(prefix: false) ⇒ Object
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
44 45 46 |
# File 'lib/krane/container_logs.rb', line 44 def printing_started? @printed_latest end |
#sync ⇒ Object
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 |