matrix-js-sdk
matrix-js-sdk copied to clipboard
Modules using a variable binding to `logger.log` do not respect `logger.setLevel`
Issue
I'm getting noisy logs from this library despite setting loglevel.getLogger("matrix").disableAll()
.
Cause
https://github.com/matrix-org/matrix-js-sdk/blob/acbcb4658a5d5903dfd557e3e115241d0a6f38bb/src/models/event-timeline-set.ts#L30-L38 https://github.com/matrix-org/matrix-js-sdk/blob/acbcb4658a5d5903dfd557e3e115241d0a6f38bb/src/timeline-window.ts#L34
loglevel
applies setLevel
by replacing the relevant methods on the logger object: https://github.com/pimterry/loglevel/blob/f0187213feb6495630545a34a3b91633db47a1ee/lib/loglevel.js#L86-L97
If debuglog
binds logger.log
at the time of module load, debuglog
will not be updated to respect setLevel
. This causes noisy logs in my application even when running loglevel.getLogger("matrix").disableAll()
.
Possible fixes
- Use
logger.log
directly instead ofdebuglog
. I don't understand why the library is disablingdebuglog
based on the localDEBUG
constant, but I bet this could be achieved withloglevel
'ssetLevel
. - Forfeit line numbers and use a reference to
logger.log
(e.g.const debuglog = (...args) => logger.log(...args)
) - Some galaxy-brain
Proxy
implementation that I wasn't able to achieve (feel like there's a solution here that would keep the currentDEBUG
behavior and get line numbers with logs)
I've implemented option 1 in my branch: https://github.com/davidisaaclee/matrix-js-sdk/commit/9849818efa1d9101e68126af60fba180d7a5f756
Please let me know if there's a better way to get these changes moving than filing Github issues – it seems like you have a lot on your plate, and I'd like to help in an effective way.
have you tried logger.disableAll()
? seems to work here
@vractal I haven't, but that would prevent me from using my own logger
instances, right?