Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Commit

Permalink
[Dawn] Better Debug Output (#330)
Browse files Browse the repository at this point in the history
* [Dawn] Show what is being received

* [Dawn] New debug function in logger to show more things explicitly
  • Loading branch information
kevinmasd authored Apr 29, 2017
1 parent 67ccd93 commit bc951a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 5 additions & 4 deletions dawn/main/ansible/Ansible.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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);
}

Expand Down
10 changes: 9 additions & 1 deletion dawn/renderer/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('*');
Expand Down

0 comments on commit bc951a9

Please sign in to comment.