Sha256: 4f7162993dc9fef929e238d5aaf0a9a00651c5fd8a4f9cd4d7b1f118a6c2e56e

Contents?: true

Size: 1.34 KB

Versions: 24

Compression:

Stored size: 1.34 KB

Contents

# encoding: ascii-8bit

# Copyright 2018 Ball Aerospace & Technologies Corp.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
# under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt

require 'cosmos'
require 'stringio'

# Creates a MessageLog in the DART_LOGS System path for DART logging
class DartLogging
  def initialize(message_log_name)
    @output_sleeper = Cosmos::Sleeper.new
    @string_output = StringIO.new("", "r+")
    $stdout = @string_output
    @message_log = Cosmos::MessageLog.new(message_log_name, Cosmos::System.paths['DART_LOGS'])

    @output_thread = Thread.new do
      while true
        handle_string_output()
        break if @output_sleeper.sleep(1)
      end
    end
  end

  def handle_string_output
    if @string_output.string[-1..-1] == "\n"
      string = @string_output.string.clone
      @string_output.string = @string_output.string[string.length..-1]
      @message_log.write(string, true)
      STDOUT.print string if STDIN.isatty # Have a console
    end
  end

  def graceful_kill
    # Do Nothing
  end

  def stop
    handle_string_output()
    @output_sleeper.cancel
    Cosmos.kill_thread(self, @output_thread)
    handle_string_output()
    @message_log.stop
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
cosmos-4.5.2-java lib/cosmos/dart/lib/dart_logging.rb
cosmos-4.5.2 lib/cosmos/dart/lib/dart_logging.rb
cosmos-4.5.1-java lib/cosmos/dart/lib/dart_logging.rb
cosmos-4.5.1 lib/cosmos/dart/lib/dart_logging.rb
cosmos-4.5.0-java lib/cosmos/dart/lib/dart_logging.rb
cosmos-4.5.0 lib/cosmos/dart/lib/dart_logging.rb
cosmos-4.4.2-java lib/cosmos/dart/lib/dart_logging.rb
cosmos-4.4.2 lib/cosmos/dart/lib/dart_logging.rb
cosmos-4.4.1-java lib/cosmos/dart/lib/dart_logging.rb
cosmos-4.4.1 lib/cosmos/dart/lib/dart_logging.rb
cosmos-4.4.0-java lib/cosmos/dart/lib/dart_logging.rb
cosmos-4.4.0 lib/cosmos/dart/lib/dart_logging.rb
cosmos-4.3.0-java lib/cosmos/dart/lib/dart_logging.rb
cosmos-4.3.0 lib/cosmos/dart/lib/dart_logging.rb
cosmos-4.2.4-java lib/cosmos/dart/lib/dart_logging.rb
cosmos-4.2.4 lib/cosmos/dart/lib/dart_logging.rb
cosmos-4.2.3-java lib/cosmos/dart/lib/dart_logging.rb
cosmos-4.2.3 lib/cosmos/dart/lib/dart_logging.rb
cosmos-4.2.2-java lib/cosmos/dart/lib/dart_logging.rb
cosmos-4.2.2 lib/cosmos/dart/lib/dart_logging.rb