class Console::Capture

A general sink which captures all events into a buffer.

def call(subject = nil, *arguments, severity: UNKNOWN, event: nil, **options, &block)

def call(subject = nil, *arguments, severity: UNKNOWN, event: nil, **options, &block)
	record = {
		time: ::Time.now.iso8601,
		severity: severity,
		**options,
	}
	
	if subject
		record[:subject] = subject
	end
	
	if event
		record[:event] = event.to_hash
	end
	
	if arguments.any?
		record[:arguments] = arguments
	end
	
	if annotation = Fiber.current.annotation
		record[:annotation] = annotation
	end
	
	if block_given?
		if block.arity.zero?
			record[:message] = yield
		else
			buffer = StringIO.new
			yield buffer
			record[:message] = buffer.string
		end
	else
		record[:message] = arguments.join(" ")
	end
	
	@records << record
end

def clear

def clear
	@records.clear
end

def each(&block)

def each(&block)
	@records.each(&block)
end

def empty?

def empty?
	@records.empty?
end

def first

def first
	@records.first
end

def include?(pattern)

def include?(pattern)
	@records.any? do |record|
		record[:subject].to_s&.match?(pattern) or record[:message].to_s&.match?(pattern)
	end
end

def initialize

def initialize
	@records = []
	@verbose = false
end

def last

def last
	@records.last
end

def verbose!(value = true)

def verbose!(value = true)
	@verbose = value
end

def verbose?

def verbose?
	@verbose
end