Thesis Grpc Logging
0.1.x-dev 2026-08-03 15:49 UTC
This package is auto-updated.
Last update: 2026-08-03 18:10:51 UTC
PSR-3 logging middleware for thesis/grpc: client and server interceptors that log every unary and streaming RPC with its method, type, status code and duration, at a log level derived from the gRPC status.
Contents Installationcomposer require thesis/grpc-loggingUsage
There are two interceptors — one per side. Each implements both the unary and stream contracts of its side, so a single instance covers all RPC types.
use Psr\Log\LoggerInterface; use Thesis\Grpc\Client; use Thesis\Grpc\Logging; use Thesis\Grpc\Server; /** @var LoggerInterface $logger */ $config = new Logging\Config($logger); // Client $client = new Client\Builder() ->withUnaryInterceptors(new Logging\ClientInterceptor($config)) ->withStreamInterceptors(new Logging\ClientInterceptor($config)) ->build(); // Server $server = new Server\Builder() ->withUnaryInterceptors(new Logging\ServerInterceptor($config)) ->withStreamInterceptors(new Logging\ServerInterceptor($config)) ->build();
The $logger is any PSR-3 logger (Monolog, etc.).
Logging\Config is an immutable dto:
use Thesis\Grpc\Logging\Config; use Thesis\Grpc\Logging\Event; new Config( logger: $logger, // required PSR-3 logger levels: new Logging\DefaultLevels(), // gRPC status → PSR-3 level events: [Event::Start, Event::Finish], // which points of the call to log );
Event cases:
Start — a started call record when the call begins.Finish — a finished call record with the status and duration when it ends.PayloadSent / PayloadReceived — a record for each message, named by role and direction:
the client logs request sent / response received, the server response sent / request received,
with the message object under grpc.request.content / grpc.response.content. Off by default.To log only completed calls, pass events: [Event::Finish]. To also log message payloads (verbose,
and potentially sensitive), add Event::PayloadSent / Event::PayloadReceived.
The finish record's level is derived from the call's gRPC status by a Levels implementation.
DefaultLevels mirrors the grpc-ecosystem mapping — client-caused and expected statuses stay
informational, transient ones warn, and genuine server faults are errors:
| Level | Statuses |
|---|---|
info |
OK, CANCELLED, INVALID_ARGUMENT, NOT_FOUND, ALREADY_EXISTS, UNAUTHENTICATED |
warning |
DEADLINE_EXCEEDED, PERMISSION_DENIED, RESOURCE_EXHAUSTED, FAILED_PRECONDITION, ABORTED, OUT_OF_RANGE, UNAVAILABLE |
error |
UNKNOWN, UNIMPLEMENTED, INTERNAL, DATA_LOSS |
Provide your own by implementing Levels:
use Google\Rpc\Code; use Psr\Log\LogLevel; use Thesis\Grpc\Logging\Levels; final class QuietLevels implements Levels { public function level(Code $code): string { return $code === Code::OK ? LogLevel::DEBUG : LogLevel::WARNING; } }
The start record is emitted at the OK level.
Each record carries a structured PSR-3 context:
| Field | Example | Notes |
|---|---|---|
grpc.component |
client / server |
Which side emitted the record. |
grpc.method |
/acme.Api/Get |
Full method name. |
grpc.type |
unary, server_stream, client_stream, bidi_stream |
RPC type. |
grpc.code |
0 |
Numeric gRPC status (finish record only). |
grpc.code_name |
OK |
Status name (finish record only). |
grpc.time_ms |
4.21 |
Wall-clock duration in milliseconds (finish record only). |
grpc.error |
(exception object) | The thrown exception (finish record of a failed call only). |
grpc.request.content / grpc.response.content |
(message object) | The payload (payload records only); format it in your PSR-3 handler. |
grpc.send.time_ms / grpc.recv.time_ms |
0.18 |
Duration of that individual send/receive (streaming payload records only). |
Record messages are started call, finished call, and — for payload records — request sent,
response sent, request received and response received.
OK on success, or the failure's status (an InvokeError's
code, CANCELLED for a cancellation, UNKNOWN otherwise) before the error is rethrown.Invoke::$type), the way Go's grpc-middleware keys off the stream descriptor:
receive() — success is the finish (OK), a throw is the failure;receive() has no clean end-of-stream — it throws even on success — so a
server stream drained via raw receive() calls logs its messages but not a finish record.)| # | Наименование новости | Тональность | Информативность | Дата публикации |
|---|---|---|---|---|
| 1 | thesis/grpc-deadline | 0 | 43.33 | 03-08-2026 |
| 2 | thesis/grpc-retry | 0 | 27.38 | 03-08-2026 |
| 3 | thesis/grpc-auth | 0 | 17.78 | 03-08-2026 |
| 4 | tobento/app-logging-web | 0 | 14.17 | 03-08-2026 |
| 5 | ailog-cli 2.1.1 | 0 | 7 | 10-07-2026 |
| 6 | karelwintersky/arris.config | 0 | 10 | 03-08-2026 |
| 7 | How Clients and Servers Communicate: Full Handbook on HTTP/1.1, HTTP/2, REST, WebSockets, GraphQL, gRPC, and Protocol Buffers | 0 | 9.64 | 23-07-2026 |
| 8 | tensor-grep 1.58.0 | 0 | 5 | 10-07-2026 |
| 9 | BTC — | 0 | 0 | 12-02-2026 |
| 10 | Pactos | 0 | 0 | 13-07-2026 |