Closed cheanrod closed 4 years ago
😬..... since you already found the solution, can you fix it in your next PR?
I was a bit fast filing the issue. The described behavior only applies if sonos2mqtt is run within the VS Code debugger. Obviously the debugger captures the object to be logged before it reaches the log() method. The object is then printed by the debugger itself.
When running sonos2mqtt on the console all works as expected. %j is replaced with the JSON representation of the object.
So, I'm closing the issue.
%j placeholder doesn't work in log statements as e.g.
log.debug('Error parsing json %j', e)
The statement leads to the following output:
2020-01-18 12:51:27.628 <debug> Error parsing json %j
Substituted by %s the output show the correct output:
2020-01-18 12:53:34.046 <debug> Error parsing json SyntaxError: Unexpected token o in JSON at position 1 at JSON.parse (<anonymous>) at ConvertToObjectIfPossible (/Users/swerner/Documents/src/sonos2mqtt/src/bridge.js:401:17) at setalarm (/Users/swerner/Documents/src/sonos2mqtt/src/bridge.js:277:13) at handleGenericCommand (/Users/swerner/Documents/src/sonos2mqtt/src/bridge.js:255:14) at MqttClient.handleIncomingMessage (/Users/swerner/Documents/src/sonos2mqtt/src/bridge.js:113:12) at MqttClient.emit (events.js:223:5) at MqttClient._handlePublish (/Users/swerner/Documents/src/sonos2mqtt/node_modules/mqtt/lib/client.js:1162:12) at MqttClient._handlePacket (/Users/swerner/Documents/src/sonos2mqtt/node_modules/mqtt/lib/client.js:351:12) at work (/Users/swerner/Documents/src/sonos2mqtt/node_modules/mqtt/lib/client.js:283:12) at Writable.writable._write (/Users/swerner/Documents/src/sonos2mqtt/node_modules/mqtt/lib/client.js:294:5)
I didn't figure out the cause until now. https://nodejs.org/en/knowledge/getting-started/the-console-module/ suggests that %j is a valid placeholder and should print the JSON representation of the object.