metarhia / jstp

Fast RPC for browser and Node.js based on TCP, WebSocket, and MDSF
https://metarhia.github.io/jstp
Other
142 stars 10 forks source link

Add a possibility for client-side message logging before passing connection to client #349

Closed belochub closed 6 years ago

belochub commented 6 years ago

At the moment, there is no way to log messages on the client-side before the connection is being passed into callback of the connect and connectAndInspect methods, meaning that you can't log any of handshake or inspect messages being sent before the callback call.

I think we need to provide a way for the client to pass some kind of "logger function" into the aforementioned methods that will be called whenever the client is sending or receiving a message before this functions' callback call.

belochub commented 6 years ago

Ping @lundibundi, @nechaido.

nechaido commented 6 years ago

We can accept an event emitter and emit all logging events using it. If none is provided we can emit logging events on a connection.

lundibundi commented 6 years ago

Honestly, this looks like a hack and adds even more parameters to client object, but with our current logging strategy, I see no other way, so that may be it. I'd much prefer having usual pluggable logger via some general interface instead of using events, but that's not the route we have decided on before unfortunately.