Skip to content

Commit

Permalink
logging
Browse files Browse the repository at this point in the history
  • Loading branch information
firepick1 committed Mar 7, 2016
1 parent ca525c5 commit df385d9
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FireSight
node-v*
node
npm
logs
*.log
*.class
*.wiki
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
firenodejs
----------

0.18.1
------
* NEW: Save firenodejs log files in logs

0.18.0
------
* NEW: DeltaMesh dual z-plane scans (required for z-calibration)
Expand Down
28 changes: 14 additions & 14 deletions js/firestep/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ try {
that.firestep_proc.stdout.on('data', function(buffer) {
var data = buffer.toString();
data = data.substr(0, data.length - 1); // chop LF to match serialport
//console.log("TTY\t: firestep stdout:" + data);
//console.log("TTY \t: firestep stdout:" + data);
that.onSerialData(data);
});
that.firestep_proc.stderr.on('data', function(data) {
Expand All @@ -92,11 +92,11 @@ try {
Logger.start("FireStepDriver(" + that.model.rest.serialPath + ") " + cmd);
var child1 = child_process.exec(cmd, function(error, stdout, stdin) {
if (error instanceof Error) {
console.log("TTY\t: FireStepDriver(" + that.model.rest.serialPath + ") attempt #1:" + error);
console.log("TTY \t: FireStepDriver(" + that.model.rest.serialPath + ") attempt #1:" + error);
var child2 = child_process.exec(cmd, function(error, stdout, stdin) {
if (error instanceof Error) {
reset_serialDriver(that);
console.log("TTY\t: FireStepDriver(" + that.model.rest.serialPath + ") RETRY #1:" + error);
console.log("TTY \t: FireStepDriver(" + that.model.rest.serialPath + ") RETRY #1:" + error);
} else {
onOpenSuccess(that, stdout, 2);
}
Expand All @@ -106,7 +106,7 @@ try {
}
});
} catch (e) {
console.log("TTY\t: FireStepDriver(" + that.model.rest.serialPath + ") UNAVAILABLE:" + e);
console.log("TTY \t: FireStepDriver(" + that.model.rest.serialPath + ") UNAVAILABLE:" + e);
reset_serialDriver(that);
}
}
Expand Down Expand Up @@ -181,7 +181,7 @@ try {
FireStepDriver.prototype.write = function(cmd) {
var that = this;
that.model.writes++;
console.log("TTY\t: WRITE(" + that.model.writes + ") " + cmd + "\\n");
console.log("TTY \t: WRITE(" + that.model.writes + ") " + cmd + "\\n");
try {
if (that.serial) {
that.serial.write(cmd);
Expand All @@ -197,7 +197,7 @@ try {
that.firestep_proc.stdin.write("\n");
} else {
// FireStep spawn failed
console.log("TTY\t: firestep response TIMEOUT:" + that.msLaunchTimeout + "ms");
console.log("TTY \t: firestep response TIMEOUT:" + that.msLaunchTimeout + "ms");
reset_serialDriver(that);
}
}, that.msLaunchTimeout);
Expand All @@ -206,19 +206,19 @@ try {
throw new Error("no serial driver");
}
} catch (e) {
console.log("TTY\t: FireStepDriver(" + that.model.rest.serialPath + ") UNAVAILABLE:" + e);
console.log("TTY \t: FireStepDriver(" + that.model.rest.serialPath + ") UNAVAILABLE:" + e);
reset_serialDriver(that);
}
}
FireStepDriver.prototype.processQueue = function() {
var that = this;
if (that.serialQueue.length <= 0) {
//console.log("TTY\t: FireStepDriver.processQueue(empty) ");
//console.log("TTY \t: FireStepDriver.processQueue(empty) ");
} else if (!that.model.available) {
console.log("TTY\t: FireStepDriver.processQueue(unavailable) ", that.serialQueue.length,
console.log("TTY \t: FireStepDriver.processQueue(unavailable) ", that.serialQueue.length,
" items");
} else if (that.serialInProgress) {
//console.log("TTY\t: FireStepDriver.processQueue(busy) ", that.serialQueue.length, " items");
//console.log("TTY \t: FireStepDriver.processQueue(busy) ", that.serialQueue.length, " items");
} else {
that.serialInProgress = true;
var jcmd = that.serialQueue.shift();
Expand All @@ -231,7 +231,7 @@ try {
FireStepDriver.prototype.onSerialData = function(data) {
var that = this;
that.model.reads++;
console.log("TTY\t: READ(" + that.model.reads + ") " + data + "\\n");
console.log("TTY \t: READ(" + that.model.reads + ") " + data + "\\n");
if (typeof data !== 'string') {
throw new Error("expected Javascript string for serial data return");
}
Expand All @@ -244,8 +244,8 @@ try {
that.handlers.response(response);
request.resp = response;
if (response.s < 0) {
console.log("TTY\t: FireStep COMMAND FAILED:" + data);
console.log("TTY\t: FireStepDriver() COMMAND QUEUE CLEARED " + that.serialQueue.length + " ITEMS");
console.log("TTY \t: FireStep COMMAND FAILED:" + data);
console.log("TTY \t: FireStepDriver() COMMAND QUEUE CLEARED " + that.serialQueue.length + " ITEMS");
that.serialQueue = [];
}
}
Expand All @@ -255,7 +255,7 @@ try {
try {
request.onDone && request.onDone(request.resp);
} catch (e) {
console.log("TTY\t: ERROR(response handler failed):" + data, e);
console.log("TTY \t: ERROR(response handler failed):" + data, e);
}
that.processQueue();
if (that.serialQueue.length == 0) {
Expand Down
6 changes: 3 additions & 3 deletions js/firestep/mock-driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function mockAsync(callback) {
var mockSerial = function(that, cmd) { // CANNOT BLOCK!!!
that.model.writes = that.model.writes ? that.model.writes + 1 : 1;
var serialData = JSON.stringify(cmd);
console.log("TTY\t: WRITE(" + that.model.writes + ") " + serialData + "\\n");
console.log("TTY \t: WRITE(" + that.model.writes + ") " + serialData + "\\n");

// SEND SERIAL DATA HERE

Expand Down Expand Up @@ -138,10 +138,10 @@ function mockAsync(callback) {
};
that.handlers = {
idle: function() {
// console.log("TTY\t: idle");
// console.log("TTY \t: idle");
},
response: function(response) {
// console.log("TTY\t: response(" + JSON.stringify(response) + ")");
// console.log("TTY \t: response(" + JSON.stringify(response) + ")");
},
};

Expand Down
6 changes: 3 additions & 3 deletions js/firestep/planner.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ var MockFPD = require("./mock-fpd");
if (!onDone) {
onDone = function(data) {
if (data.s) {
console.log("TTY\t: FireStepPlanner: FireStep response:" + data.s);
console.log("TTY \t: FireStepPlanner: FireStep response:" + data.s);
}
}
}
Expand All @@ -347,7 +347,7 @@ var MockFPD = require("./mock-fpd");
}
that.driver.processQueue();
if (that.driver.queueLength()) {
console.log("TTY\t: FireStepPlanner.send() queued:", that.driver.queueLength());
console.log("TTY \t: FireStepPlanner.send() queued:", that.driver.queueLength());
}
return that;
}
Expand Down Expand Up @@ -396,7 +396,7 @@ var MockFPD = require("./mock-fpd");
log: "FireStepPlanner.onIdle(initialized)"
});
} else {
that.verbose && console.log("TTY\t: FireStepPlanner.onIdle(waiting) ...");
that.verbose && console.log("TTY \t: FireStepPlanner.onIdle(waiting) ...");
}
if (that.mpoPlan) {
that.model.mpo = that.model.mpo || {};
Expand Down
2 changes: 1 addition & 1 deletion js/firestep/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function millis() {
}
that.send(cmd, function(data) {
var msElapsed = millis() - msStart;
console.log("TTY\t: FireStepService.test(dvs) msElapsed:", msElapsed);
console.log("TTY \t: FireStepService.test(dvs) msElapsed:", msElapsed);
});
that.send(that.cmd_mpo(), function(data) {
var msElapsed = millis() - msStart;
Expand Down
16 changes: 8 additions & 8 deletions js/firestep/tinyg-driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function mockAsync(callback) {
var mockSerial = function(that, cmd) { // CANNOT BLOCK!!!
that.model.writes = that.model.writes ? that.model.writes + 1 : 1;
var serialData = JSON.stringify(cmd);
console.log("TTY\t: WRITE(" + that.model.writes + ") " + serialData + "\\n");
console.log("TTY \t: WRITE(" + that.model.writes + ") " + serialData + "\\n");

// SEND SERIAL DATA HERE
if (cmd.hasOwnProperty("id")) { // identify machine
Expand Down Expand Up @@ -112,10 +112,10 @@ function mockAsync(callback) {
};
that.handlers = {
idle: function() {
// console.log("TTY\t: idle");
// console.log("TTY \t: idle");
},
response: function(response) {
// console.log("TTY\t: response(" + JSON.stringify(response) + ")");
// console.log("TTY \t: response(" + JSON.stringify(response) + ")");
},
};

Expand Down Expand Up @@ -194,7 +194,7 @@ function mockAsync(callback) {
console.log("Config changed: " + util.inspect(changed));
});

console.log("TTY\t: tinyg-driver: opened serial connection to:" + that.model.rest.serialPath);
console.log("TTY \t: tinyg-driver: opened serial connection to:" + that.model.rest.serialPath);

// MAKE IT WORK OR THROW
that.model.driver = that.name;
Expand Down Expand Up @@ -222,12 +222,12 @@ function mockAsync(callback) {
var that = this;

if (that.serialQueue.length <= 0) {
//console.log("TTY\t: TinyGDriver.processQueue(empty) ");
//console.log("TTY \t: TinyGDriver.processQueue(empty) ");
} else if (!that.model.available) {
//console.log("TTY\t: TinyGDriver.processQueue(unavailable) ", that.serialQueue.length, " items");
//console.log("TTY \t: TinyGDriver.processQueue(unavailable) ", that.serialQueue.length, " items");
//console.log(that.serialQueue);
} else if (that.serialInProgress) {
//console.log("TTY\t: TinyGDriver.processQueue(busy) ", that.serialQueue.length, " items");
//console.log("TTY \t: TinyGDriver.processQueue(busy) ", that.serialQueue.length, " items");
//console.log(that.serialQueue);
} else {
that.serialInProgress = true;
Expand All @@ -240,7 +240,7 @@ function mockAsync(callback) {
TinyGDriver.prototype.onSerialData = function(data) {
var that = this;
that.model.reads = that.model.reads ? that.model.reads + 1 : 1;
console.log("TTY\t: READ(" + that.model.reads + ") " + data + "\\n");
console.log("TTY \t: READ(" + that.model.reads + ") " + data + "\\n");
var parsed = JSON.parse(data);
var retData = parsed;

Expand Down
2 changes: 1 addition & 1 deletion js/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var options = {
version: {
major: 0,
minor: 18,
patch: 0,
patch: 1,
},
};

Expand Down
11 changes: 7 additions & 4 deletions scripts/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
scripts/shutdown.sh

pushd $(dirname "$0")/.. > /dev/null
rm -f firenodejs.log
echo -e "START\t: `pwd`/$0\t`date`" | tee -a firenodejs.log
mkdir -p logs
LOGNAME=logs/firenodejs`date +%F-%H%M`.log
ln -sf $LOGNAME firenodejs.log
echo -e "START\t: `pwd`/$0\t`date`" | tee $LOGNAME
echo -e "INFO\t: logging to $LOGNAME" | tee -a $LOGNAME
echo -e "INFO\t: launching firenodejs server daemon as user:`whoami`" | tee -a firenodejs.log
nohup ./node js/server.js $@ 0<&- &>> firenodejs.log &
nohup ./node js/server.js $@ 0<&- &>> $LOGNAME &
popd > /dev/null
echo -e "END\t: `pwd`/$0\t`date`" | tee -a firenodejs.log
echo -e "END \t: `pwd`/$0\t`date`" | tee -a $LOGNAME

exit 0
4 changes: 2 additions & 2 deletions www/js/shared/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ var should = require("should");
logLevel: "warn"
});
Logger.start = function(msg) {
Logger.logger.write("START+" + (new Date() - msLaunch) + "ms\t: " + Logger.logger.message(arguments));
Logger.logger.write("T+" + (new Date() - msLaunch) + "\t: " + Logger.logger.message(arguments));
}
Logger.validate = function(value) {
should.exist(value);
Expand All @@ -145,7 +145,7 @@ var should = require("should");
value.setLevel.should.be.a.function;
}
Logger.msLaunch = function() {
return "T+" + (new Date() - msLaunch) + "ms";
return "+" + (new Date() - msLaunch);
}

module.exports = exports.Logger = Logger;
Expand Down

0 comments on commit df385d9

Please sign in to comment.