Sha256: 7de7b982ac6b2a70baeb202076941540cec4c94bd8f990022333b248ee6b4d4d

Contents?: true

Size: 695 Bytes

Versions: 74

Compression:

Stored size: 695 Bytes

Contents

module LogHelpers
  def capture_logs(&block)
    log = std_stream
    use_logger_with(log, &block)
    log_contents(log)
  end

  def use_logger_with(log)
    Appsignal.logger = test_logger(log)
    yield
    Appsignal.logger = nil
  end

  def test_logger(log)
    Appsignal::Utils::IntegrationLogger.new(log).tap do |logger|
      logger.formatter = logger_formatter
    end
  end

  def logger_formatter
    proc do |severity, _datetime, _progname, msg|
      log_line(severity, msg)
    end
  end

  def log_line(severity, message)
    # This format is used in the `contains_log` matcher.
    "[#{severity}] #{message}\n"
  end

  def log_contents(log)
    log.rewind
    log.read
  end
end

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
appsignal-3.4.2-java spec/support/helpers/log_helpers.rb
appsignal-3.4.2 spec/support/helpers/log_helpers.rb
appsignal-3.4.1-java spec/support/helpers/log_helpers.rb
appsignal-3.4.1 spec/support/helpers/log_helpers.rb
appsignal-3.4.0-java spec/support/helpers/log_helpers.rb
appsignal-3.4.0 spec/support/helpers/log_helpers.rb
appsignal-3.3.10-java spec/support/helpers/log_helpers.rb
appsignal-3.3.10 spec/support/helpers/log_helpers.rb
appsignal-3.3.9-java spec/support/helpers/log_helpers.rb
appsignal-3.3.9 spec/support/helpers/log_helpers.rb
appsignal-3.3.8-java spec/support/helpers/log_helpers.rb
appsignal-3.3.8 spec/support/helpers/log_helpers.rb
appsignal-3.3.7-java spec/support/helpers/log_helpers.rb
appsignal-3.3.7 spec/support/helpers/log_helpers.rb
appsignal-3.3.6-java spec/support/helpers/log_helpers.rb
appsignal-3.3.6 spec/support/helpers/log_helpers.rb
appsignal-3.3.5-java spec/support/helpers/log_helpers.rb
appsignal-3.3.5 spec/support/helpers/log_helpers.rb
appsignal-3.3.4-java spec/support/helpers/log_helpers.rb
appsignal-3.3.4 spec/support/helpers/log_helpers.rb