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.5.4-java spec/support/helpers/log_helpers.rb
appsignal-3.5.4 spec/support/helpers/log_helpers.rb
appsignal-3.5.3-java spec/support/helpers/log_helpers.rb
appsignal-3.5.3 spec/support/helpers/log_helpers.rb
appsignal-3.5.2-java spec/support/helpers/log_helpers.rb
appsignal-3.5.2 spec/support/helpers/log_helpers.rb
appsignal-3.5.1-java spec/support/helpers/log_helpers.rb
appsignal-3.5.1 spec/support/helpers/log_helpers.rb
appsignal-3.5.0-java spec/support/helpers/log_helpers.rb
appsignal-3.5.0 spec/support/helpers/log_helpers.rb
appsignal-3.4.16-java spec/support/helpers/log_helpers.rb
appsignal-3.4.16 spec/support/helpers/log_helpers.rb
appsignal-3.4.15-java spec/support/helpers/log_helpers.rb
appsignal-3.4.15 spec/support/helpers/log_helpers.rb
appsignal-3.4.14-java spec/support/helpers/log_helpers.rb
appsignal-3.4.14 spec/support/helpers/log_helpers.rb
appsignal-3.4.13-java spec/support/helpers/log_helpers.rb
appsignal-3.4.13 spec/support/helpers/log_helpers.rb
appsignal-3.4.12-java spec/support/helpers/log_helpers.rb
appsignal-3.4.12 spec/support/helpers/log_helpers.rb