abstract class AbstractLogger implements LoggerInterface (View source)

Shared foundation for brand loggers: implement {format()}, inherit the destination.

The format is the part that varies per brand — CNR joins command, POST body, error and plain response with newlines; IBS emits a labelled REQUEST/RESPONSE block — while the destination does not. So the brand supplies format() and a {\CNIC\LogSinkInterface} supplies the destination: one formatter serves every sink, instead of each sink carrying a copy of the format.

{\CNIC\log()} is final on purpose. A subclass reintroducing its own log() would be behaviour-identical under the default {\CNIC\EchoSink} and would silently ignore any injected sink — exactly the erosion this class exists to prevent. A logger that genuinely owns its destination implements {\CNIC\LoggerInterface} directly instead of extending this class.

Methods

__construct(LogSinkInterface $sink = new EchoSink())

No description

string
format(string $post, ResponseInterface $response, string|null $error = null)

Build the debug record for the given request/response pair.

void
log(string $post, ResponseInterface $response, string|null $error = null)

Format the record, then hand it to the sink. The whole implementation of the contract — see the class docblock for why it may not be overridden.

Details

__construct(LogSinkInterface $sink = new EchoSink())

No description

Parameters

LogSinkInterface $sink

Destination for formatted records; defaults to standard output

abstract string format(string $post, ResponseInterface $response, string|null $error = null)

Build the debug record for the given request/response pair.

Callers get the record as a string; nothing is written. Both arguments are already masked when they arrive — the response masks its own stored command ({\CNIC\AbstractResponse::sanitizeCommand()}, so getCommand() and getCommandPlain() are safe) and the client passes a secured POST body — so implementations must not undo that. The exception is {\CNIC\ResponseInterface::getContext()}, which is caller-supplied and deliberately untouched: an implementation logging it masks it itself.

Parameters

string $post

Post request data in string format (already masked)

ResponseInterface $response
string|null $error

Return Value

string

final void log(string $post, ResponseInterface $response, string|null $error = null)

Format the record, then hand it to the sink. The whole implementation of the contract — see the class docblock for why it may not be overridden.

Parameters

string $post

Post request data in string format (already masked)

ResponseInterface $response
string|null $error

Return Value

void