Don't stringify every packet if debug not enabled (#797)

This commit is contained in:
Evan Goode 2020-12-27 20:42:19 -05:00 committed by GitHub
parent c7a021d689
commit 7492025d65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -83,8 +83,10 @@ class Client extends EventEmitter {
parsed.data = parsed.data.params
parsed.metadata.state = state
debug('read packet ' + state + '.' + parsed.metadata.name)
const s = JSON.stringify(parsed.data, null, 2)
debug(s && s.length > 10000 ? parsed.data : s)
if (debug.enabled) {
const s = JSON.stringify(parsed.data, null, 2)
debug(s && s.length > 10000 ? parsed.data : s)
}
this.emit('packet', parsed.data, parsed.metadata, parsed.buffer)
this.emit(parsed.metadata.name, parsed.data, parsed.metadata)
this.emit('raw.' + parsed.metadata.name, parsed.buffer, parsed.metadata)