Sha256: 20c7bd63568ef6292cdd82c252c5243607ad42f2eae702808a842758d4ff8566

Contents?: true

Size: 677 Bytes

Versions: 140

Compression:

Stored size: 677 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::Logger.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

140 entries across 140 versions & 1 rubygems

Version Path
appsignal-3.1.6-java spec/support/helpers/log_helpers.rb
appsignal-3.1.6 spec/support/helpers/log_helpers.rb
appsignal-3.1.5-java spec/support/helpers/log_helpers.rb
appsignal-3.1.5 spec/support/helpers/log_helpers.rb
appsignal-3.1.4-java spec/support/helpers/log_helpers.rb
appsignal-3.1.4 spec/support/helpers/log_helpers.rb
appsignal-3.1.3-java spec/support/helpers/log_helpers.rb
appsignal-3.1.3 spec/support/helpers/log_helpers.rb
appsignal-3.1.2-java spec/support/helpers/log_helpers.rb
appsignal-3.1.2 spec/support/helpers/log_helpers.rb
appsignal-3.1.1-java spec/support/helpers/log_helpers.rb
appsignal-3.1.1 spec/support/helpers/log_helpers.rb
appsignal-3.1.0-java spec/support/helpers/log_helpers.rb
appsignal-3.1.0 spec/support/helpers/log_helpers.rb
appsignal-3.0.27-java spec/support/helpers/log_helpers.rb
appsignal-3.0.27 spec/support/helpers/log_helpers.rb
appsignal-3.0.26-java spec/support/helpers/log_helpers.rb
appsignal-3.0.26 spec/support/helpers/log_helpers.rb
appsignal-3.0.25-java spec/support/helpers/log_helpers.rb
appsignal-3.0.25 spec/support/helpers/log_helpers.rb