Sha256: 245797c624e72f7c4534d14cdb533fc3082b5973fa3b0fe4753881fe20b7cbd5

Contents?: true

Size: 1.29 KB

Versions: 10

Compression:

Stored size: 1.29 KB

Contents

require 'thread'
module OrigenSim
  class StderrReader < Thread
    attr_reader :socket, :logged_errors

    def initialize(socket)
      @socket = socket
      @continue = true
      @logged_errors = false
      @last_message_at = Time.now
      super do
        begin
          while @continue
            line = @socket.gets
            if line
              line = line.chomp
              if OrigenSim.fail_on_stderr && !line.empty? &&
                 !OrigenSim.stderr_string_exceptions.any? { |s| s.is_a?(Regexp) ? s.match?(line) : line =~ /#{s}/i }
                # We're failing on stderr, so print its results and log as errors if its not an exception.
                @logged_errors = true
                Origen.log.error "(STDERR): #{line}", from_origen_sim: true
              elsif OrigenSim.verbose?
                Origen.log.info line, from_origen_sim: true
              else
                Origen.log.debug line, from_origen_sim: true
              end
              @last_message_at = Time.now
            end
          end
        rescue IOError => e
          unless e.message =~ /stream closed/
            raise e
          end
        end
      end
    end

    def stop
      @continue = false
    end

    def time_since_last_message
      Time.now - @last_message_at
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
origen_sim-0.20.7 lib/origen_sim/stderr_reader.rb
origen_sim-0.20.6 lib/origen_sim/stderr_reader.rb
origen_sim-0.20.5 lib/origen_sim/stderr_reader.rb
origen_sim-0.20.4 lib/origen_sim/stderr_reader.rb
origen_sim-0.20.3 lib/origen_sim/stderr_reader.rb
origen_sim-0.20.2 lib/origen_sim/stderr_reader.rb
origen_sim-0.20.1 lib/origen_sim/stderr_reader.rb
origen_sim-0.20.0 lib/origen_sim/stderr_reader.rb
origen_sim-0.16.1 lib/origen_sim/stderr_reader.rb
origen_sim-0.16.0 lib/origen_sim/stderr_reader.rb