ably-js
ably-js copied to clipboard
Unique logHandler
Passing a custom log handler to the REST or Realtime libraries configures the Logger handler to use the provided callback, see https://github.com/ably/ably-js/blob/master/common/lib/util/logger.js#L44. However, if you have two separate instances of the library with unique custom log handlers (perhaps so that each logger can output the connection ID of that client), then instancing the second library overrides the first libraries configuration as Logger is global.
I find this is quite problematic when trying to debug lots of concurrent clients. Example:
var client1 = new Ably.Realtime({ log: { handler: function() { console.log('client1', args) } } });
var client2 = new Ably.Realtime({ log: { handler: function() { console.log('client2', args) } } });
All output from both libraries will be prefixed with client2
NB: when this issue is resolved the documentation at https://ably.com/documentation/realtime/usage#client-options for ClientOptions.log
will need to be updated.
My expectation would be that client options should only influence client instances (whether REST or Realtime) created with those specific options. Therefore this sounds like a bug
to me, not an enhancement
. WDYT, @owenpearson @Peter-Maguire @mikelee638 ?
@QuintinWillison I would agree that this is a bug, although I can see how it could be an enhancement as the log handler wasn't designed to work with multiple clients and therefore is working as intended.