ably-js icon indicating copy to clipboard operation
ably-js copied to clipboard

Unique logHandler

Open mattheworiordan opened this issue 8 years ago • 3 comments

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

┆Issue is synchronized with this Jira Task by Unito

mattheworiordan avatar Nov 07 '15 21:11 mattheworiordan

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.

owenpearson avatar Oct 24 '21 09:10 owenpearson

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 avatar Dec 05 '22 12:12 QuintinWillison

@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.

Peter-Maguire avatar Dec 05 '22 13:12 Peter-Maguire