How to implement logging

Hi,

what is the best way to implement request logging in java Rsocket? I’m using RSocket-RPC + Protobuf with generated stubs and do not see any request/response interceptor options. There is a micrometer option and some tracing. Is there some example to implement it in generic way?

I would like to log any request received and invoked method name.

Thanks
Matous

Hi Matous,

If you wanted to do something like this (assuming its java) you’d need to create a version of the RequestHandlingRSocket (https://github.com/rsocket/rsocket-rpc-java/blob/master/rsocket-rpc-core/src/main/java/io/rsocket/rpc/rsocket/RequestHandlingRSocket.java) logged the metadata of every request.

In each interaction method you need to do something like:

ByteBuf metadata = payload.sliceMetadata();
String service = Metadata.getService(metadata);
String method = Metadata.getMethod(metadata);
// Log the service and method ^ 
System.out.println("calling service -> " + service + " and method -> " + method);

Or you could do it with an RSocket interceptor, and then log the metadata (https://github.com/rsocket/rsocket-java/blob/develop/rsocket-core/src/main/java/io/rsocket/plugins/RSocketInterceptor.java)

Thanks,
Robert

Thanks, will look into that interceptor

Hi,

Did the interceptor work for logging?

Thanks,
Robert