From bc951a988e30036d821dc3a1c7770ea3bf0a5b52 Mon Sep 17 00:00:00 2001 From: Kevin Ma Date: Fri, 28 Apr 2017 22:39:13 -0700 Subject: [PATCH] [Dawn] Better Debug Output (#330) * [Dawn] Show what is being received * [Dawn] New debug function in logger to show more things explicitly --- dawn/main/ansible/Ansible.js | 9 +++++---- dawn/renderer/utils/utils.js | 10 +++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/dawn/main/ansible/Ansible.js b/dawn/main/ansible/Ansible.js index b44369ca..457024ed 100644 --- a/dawn/main/ansible/Ansible.js +++ b/dawn/main/ansible/Ansible.js @@ -77,7 +77,7 @@ class ListenSocket { robot_state: stateRobot, sensor_data: sensorData, } = RuntimeData.decode(msg); - this.logger.log('Dawn received UDP'); + this.logger.debug(`Dawn received UDP with state ${stateRobot}`); RendererBridge.reduxDispatch(infoPerMessage(stateRobot)); if (stateRobot === RuntimeData.State.STUDENT_STOPPED) { if (this.statusUpdateTimeout > 0) { @@ -87,16 +87,17 @@ class ListenSocket { RendererBridge.reduxDispatch(updateCodeStatus(robotState.IDLE)); } } + this.logger.debug(sensorData); RendererBridge.reduxDispatch(updatePeripherals(sensorData)); } catch (err) { this.logger.log('Error decoding UDP'); - this.logger.log(err); + this.logger.debug(err); } }); this.socket.on('error', (err) => { this.logger.log('UDP listening error'); - this.logger.log(err); + this.logger.debug(err); }); this.socket.on('close', () => { @@ -156,7 +157,7 @@ class SendSocket { */ sendGamepadMessages(event, data) { const message = buildProto(data).encode().toBuffer(); - this.logger.log(`Dawn sent UDP to ${this.runtimeIP}`); + this.logger.debug(`Dawn sent UDP to ${this.runtimeIP}`); this.socket.send(message, SEND_PORT, this.runtimeIP); } diff --git a/dawn/renderer/utils/utils.js b/dawn/renderer/utils/utils.js index eaa0ca27..d99afcb4 100644 --- a/dawn/renderer/utils/utils.js +++ b/dawn/renderer/utils/utils.js @@ -96,13 +96,21 @@ export class Logger { this.log_file = fs.createWriteStream(`${path}/Dawn/${processname}.log`, { flags: 'a' }); this.log_file.write(`\n${firstline}`); this.lastStr = ''; + this._write = this._write.bind(this); } log(output) { console.log(output); + this._write(output, `\n[${(new Date()).toString()}]`); + } + debug(output) { + this._write(output, `\n[${(new Date()).toString()} DEBUG]`); + } + + _write(output, prefix) { output = String(output); if (output !== this.lastStr) { - this.log_file.write(`\n[${(new Date()).toString()}] ${output}`); + this.log_file.write(`${prefix} ${output}`); this.lastStr = output; } else { this.log_file.write('*');