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.0.24-java spec/support/helpers/log_helpers.rb
appsignal-3.0.24 spec/support/helpers/log_helpers.rb
appsignal-3.0.23-java spec/support/helpers/log_helpers.rb
appsignal-3.0.23 spec/support/helpers/log_helpers.rb
appsignal-3.0.22-java spec/support/helpers/log_helpers.rb
appsignal-3.0.22 spec/support/helpers/log_helpers.rb
appsignal-3.0.21-java spec/support/helpers/log_helpers.rb
appsignal-3.0.21 spec/support/helpers/log_helpers.rb
appsignal-3.0.21.alpha.1-java spec/support/helpers/log_helpers.rb
appsignal-3.0.21.alpha.1 spec/support/helpers/log_helpers.rb
appsignal-3.0.20-java spec/support/helpers/log_helpers.rb
appsignal-3.0.20 spec/support/helpers/log_helpers.rb
appsignal-3.0.19-java spec/support/helpers/log_helpers.rb
appsignal-3.0.19 spec/support/helpers/log_helpers.rb
appsignal-3.0.18-java spec/support/helpers/log_helpers.rb
appsignal-3.0.18 spec/support/helpers/log_helpers.rb
appsignal-3.0.17-java spec/support/helpers/log_helpers.rb
appsignal-3.0.17 spec/support/helpers/log_helpers.rb
appsignal-3.0.16-java spec/support/helpers/log_helpers.rb
appsignal-3.0.16 spec/support/helpers/log_helpers.rb