class Console::Output::Serialized

Serialize log messages in a structured format.

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

@parameter block [Proc] An optional block used to generate the log message.
@parameter options [Hash] Additional options.
@parameter severity [Symbol] The severity of the log message.
@parameter arguments [Array] The arguments to log.
@parameter subject [String] The subject of the log message.

Output the given log message.
def call(subject = nil, *arguments, severity: UNKNOWN, **options, &block)
	record = {
		time: Time.now.iso8601,
		severity: severity,
		oid: subject.object_id,
		pid: Process.pid,
	}
	
	# We want to log just a brief subject:
	if subject.is_a?(String)
		record[:subject] = subject
	elsif subject.is_a?(Module)
		record[:subject] = subject.name
	else
		record[:subject] = subject.class.name
	end
	
	if annotation = Fiber.current.annotation
		record[:annotation] = annotation
	end
	
	message = arguments
	
	if block_given?
		if block.arity.zero?
			message << yield
		else
			buffer = StringIO.new
			yield buffer
			message << buffer.string
		end
	end
	
	if message.size == 1
		record[:message] = message.first
	elsif message.any?
		record[:message] = message
	end
	
	record.update(options)
	
	@stream.write(self.dump(record) << "\n")
end

def dump(record)

@returns [String] The serialized record.
@parameter record [Hash] The record to serialize.

Serialize the given record.
def dump(record)
	@format.dump(record)
end

def initialize(stream, format: Format.default, **options)

@parameter options [Hash] Additional options to customize the output.
@parameter format [Console::Format] The format to use for serializing log messages.
@parameter io [IO] The output stream.

Create a new serialized output.
def initialize(stream, format: Format.default, **options)
	@stream = stream
	@format = format
end

def last_output

This a final output that then writes to an IO object.
def last_output
	self
end