Class: Rack::Rreplay

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/rreplay.rb

Class Method Summary collapse

Class Method Details

.Middleware(directory:, format: :msgpack, logger: nil) ⇒ Object

sample

use Rack::Rreplay.Middleware(directory: ‘./tmp’, format: :json),

sample: 5, extra_header_keys: %w[ACCESS_TOKEN], debug: true

Parameters:

  • directory (String)

    rreplay dump file directory, and if nil, use logger as debug

  • logger (IO) (defaults to: nil)

    if directory is nil, logger can be given



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rack/rreplay.rb', line 21

def Middleware(directory:, format: :msgpack, logger: nil)
  if directory.nil? && logger.nil?
    raise "Invalid arguments. directory: or logger: must be given", ArgumentError
  end
  format = ::Rreplay::Format.of(format)
  if directory
    ::FileUtils.mkdir_p(directory)
    logger = ::Logger::LogDevice.new(
      ::File.join(directory, ::Rreplay::LOG_FILE_NAME_PREFIX + format.file_suffix),
      shift_age: 10,
      shift_size: 1048576,
      binmode: format.is_binary?
    )
  end
  class_definition(logger, format)
end