Logging websocket messages

Is it possible to create middleware (maybe with plugin) which will do something with incoming messages from websocket.

I need that to collect metrics and saving logs based on messages from websocket.