1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Tidy up all console.log util.log from core nodes.

Try to make log,warn,error more consistent behaviour.

Especially make sure any existing catches produce errors
This commit is contained in:
dceejay 2015-02-25 19:10:44 +00:00
parent b6245bdef7
commit 71ff828947
13 changed files with 54 additions and 65 deletions

View File

@ -32,13 +32,13 @@ module.exports = function(RED) {
if (this.repeat && !isNaN(this.repeat) && this.repeat > 0) {
this.repeat = this.repeat * 1000;
this.log("repeat = "+this.repeat);
if (RED.settings.verbose) { this.log("repeat = "+this.repeat); }
this.interval_id = setInterval( function() {
node.emit("input",{});
}, this.repeat );
} else if (this.crontab) {
if (cron) {
this.log("crontab = "+this.crontab);
if (RED.settings.verbose) { this.log("crontab = "+this.crontab); }
this.cronjob = new cron.CronJob(this.crontab,
function() {
node.emit("input",{});
@ -72,10 +72,10 @@ module.exports = function(RED) {
InjectNode.prototype.close = function() {
if (this.interval_id != null) {
clearInterval(this.interval_id);
this.log("inject: repeat stopped");
if (RED.settings.verbose) { this.log("inject: repeat stopped"); }
} else if (this.cronjob != null) {
this.cronjob.stop();
this.log("inject: cronjob stopped");
if (RED.settings.verbose) { this.log("inject: cronjob stopped"); }
delete this.cronjob;
}
}
@ -89,7 +89,6 @@ module.exports = function(RED) {
} catch(err) {
res.send(500);
node.error("Inject failed:"+err);
console.log(err.stack);
}
} else {
res.send(404);

View File

@ -58,7 +58,7 @@ module.exports = function(RED) {
node.send([null,null,msg]);
});
ex.on('error', function (code) {
node.warn(code);
node.error(code);
});
}
else { node.error("Spawn command must be just the command - no spaces or extra parameters"); }

View File

@ -147,7 +147,6 @@ module.exports = function(RED) {
node.send(node.buffer.shift()); // send the first on the queue
}
node.status({text:node.buffer.length});
//console.log(node.buffer);
},node.rate);
this.on("input", function(msg) {

View File

@ -16,7 +16,6 @@
module.exports = function(RED) {
"use strict";
var util = require("util");
var ArduinoFirmata = require('arduino-firmata');
var fs = require('fs');
var plat = require('os').platform();
@ -33,14 +32,14 @@ module.exports = function(RED) {
var node = this;
node.board = new ArduinoFirmata();
if (portlist.indexOf(node.device) === -1) {
node.warn("Device "+node.device+" not found");
node.warn("device "+node.device+" not found");
}
else {
node.board.connect(node.device);
}
node.board.on('boardReady', function(){
node.log("version "+node.board.boardVersion);
if (RED.settings.verbose) { node.log("version "+node.board.boardVersion); }
});
node.on('close', function(done) {
@ -48,7 +47,7 @@ module.exports = function(RED) {
try {
node.board.close(function() {
done();
node.log("port closed");
if (RED.settings.verbose) { node.log("port closed"); }
});
} catch(e) { done(); }
} else { done(); }
@ -95,7 +94,7 @@ module.exports = function(RED) {
});
}
else {
util.log("[Firmata-arduino] port not configured");
this.warn("port not configured");
}
}
RED.nodes.registerType("arduino in",DuinoNodeIn);
@ -145,7 +144,7 @@ module.exports = function(RED) {
});
}
else {
util.log("[Firmata-arduino] port not configured");
this.warn("port not configured");
}
}
RED.nodes.registerType("arduino out",DuinoNodeOut);

View File

@ -16,7 +16,6 @@
module.exports = function(RED) {
"use strict";
var util = require("util");
var exec = require('child_process').exec;
var spawn = require('child_process').spawn;
var fs = require('fs');
@ -24,17 +23,17 @@ module.exports = function(RED) {
var gpioCommand = __dirname+'/nrgpio';
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
//util.log("Info : Ignoring Raspberry Pi specific node.");
//RED.log.info("Ignoring Raspberry Pi specific node.");
throw "Info : Ignoring Raspberry Pi specific node.";
}
if (!fs.existsSync("/usr/share/doc/python-rpi.gpio")) {
util.log("[rpi-gpio] Info : Can't find Pi RPi.GPIO python library.");
RED.log.warn("Can't find Pi RPi.GPIO python library.");
throw "Warning : Can't find Pi RPi.GPIO python library.";
}
if ( !(1 & parseInt ((fs.statSync(gpioCommand).mode & parseInt ("777", 8)).toString (8)[0]) )) {
util.log("[rpi-gpio] Error : "+gpioCommand+" needs to be executable.");
RED.log.error(gpioCommand+" needs to be executable.");
throw "Error : nrgpio must to be executable.";
}
@ -100,7 +99,7 @@ module.exports = function(RED) {
node.child.on('error', function (err) {
if (err.errno === "ENOENT") { node.error('nrgpio command not found'); }
else if (err.errno === "EACCES") { node.error('nrgpio command not executable'); }
else { node.log('error: ' + err); }
else { node.error('error: ' + err.errno); }
});
}
@ -191,7 +190,7 @@ module.exports = function(RED) {
node.child.on('error', function (err) {
if (err.errno === "ENOENT") { node.error('nrgpio command not found'); }
else if (err.errno === "EACCES") { node.error('nrgpio command not executable'); }
else { node.log('error: ' + err); }
else { node.error('error: ' + err.errno); }
});
}
@ -215,14 +214,14 @@ module.exports = function(RED) {
var pitype = { type:"" };
exec(gpioCommand+" rev 0", function(err,stdout,stderr) {
if (err) {
console.log('[rpi-gpio] Version command failed for some reason.');
RED.log.info('Version command failed for some reason.');
}
else {
if (stdout.trim() == "0") { pitype = { type:"Compute" }; }
else if (stdout.trim() == "1") { pitype = { type:"A/B v1" }; }
else if (stdout.trim() == "2") { pitype = { type:"A/B v2" }; }
else if (stdout.trim() == "3") { pitype = { type:"Model B+" }; }
else { console.log("SAW Pi TYPE",stdout.trim()); }
else { RED.log.info("Saw Pi Type",stdout.trim()); }
}
});
RED.nodes.registerType("rpi-gpio out",GPIOOutNode);
@ -259,7 +258,7 @@ module.exports = function(RED) {
node.child.on('error', function (err) {
if (err.errno === "ENOENT") { node.error('nrgpio command not found'); }
else if (err.errno === "EACCES") { node.error('nrgpio ommand not executable'); }
else { node.log('error: ' + err); }
else { node.error('error: ' + err.errno); }
});
node.on("close", function(done) {

View File

@ -38,11 +38,10 @@ if len(sys.argv) > 1:
while True:
try:
data = raw_input()
if data == "close":
GPIO.cleanup(pin)
if 'close' in data:
sys.exit(0)
p.ChangeDutyCycle(float(data))
except EOFError: # hopefully always caused by us sigint'ing the program
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
GPIO.cleanup(pin)
sys.exit(0)
except Exception as ex:
@ -57,15 +56,14 @@ if len(sys.argv) > 1:
while True:
try:
data = raw_input()
if data == "close":
GPIO.cleanup(pin)
if 'close' in data:
sys.exit(0)
elif float(data) == 0:
p.stop()
else:
p.start(50)
p.ChangeFrequency(float(data))
except EOFError: # hopefully always caused by us sigint'ing the program
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
GPIO.cleanup(pin)
sys.exit(0)
except Exception as ex:
@ -80,11 +78,10 @@ if len(sys.argv) > 1:
while True:
try:
data = raw_input()
if data == "close":
GPIO.cleanup(pin)
if 'close' in data:
sys.exit(0)
data = int(data)
except EOFError: # hopefully always caused by us sigint'ing the program
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
GPIO.cleanup(pin)
sys.exit(0)
except:
@ -113,10 +110,9 @@ if len(sys.argv) > 1:
while True:
try:
data = raw_input()
if data == "close":
GPIO.cleanup(pin)
if 'close' in data:
sys.exit(0)
except EOFError: # hopefully always caused by us sigint'ing the program
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
GPIO.cleanup(pin)
sys.exit(0)
@ -128,11 +124,10 @@ if len(sys.argv) > 1:
while True:
try:
data = raw_input()
if data == "close":
GPIO.cleanup()
if 'close' in data:
sys.exit(0)
data = int(data)
except EOFError: # hopefully always caused by us sigint'ing the program
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
GPIO.cleanup()
sys.exit(0)
except:
@ -159,14 +154,13 @@ if len(sys.argv) > 1:
while True:
try:
data = raw_input()
if data == "close":
GPIO.cleanup()
if 'close' in data:
sys.exit(0)
c = data.split(",")
r.ChangeDutyCycle(float(c[0]))
g.ChangeDutyCycle(float(c[1]))
b.ChangeDutyCycle(float(c[2]))
except EOFError: # hopefully always caused by us sigint'ing the program
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
GPIO.cleanup()
sys.exit(0)
except:

View File

@ -174,7 +174,7 @@ module.exports = function(RED) {
i = 0;
}
}
else { console.log("Should never get here"); }
else { node.log("should never get here"); }
}
});
this.port.on('ready', function() {
@ -235,7 +235,7 @@ module.exports = function(RED) {
// },true, function(err, results) { if (err) obj.serial.emit('error',err); });
//}
obj.serial.on('error', function(err) {
util.log("[serial] serial port "+port+" error "+err);
RED.log.error("serial port "+port+" error "+err);
obj._emitter.emit('closed');
obj.tout = setTimeout(function() {
setupSerial();
@ -243,7 +243,7 @@ module.exports = function(RED) {
});
obj.serial.on('close', function() {
if (!obj._closing) {
util.log("[serial] serial port "+port+" closed unexpectedly");
RED.log.error("serial port "+port+" closed unexpectedly");
obj._emitter.emit('closed');
obj.tout = setTimeout(function() {
setupSerial();
@ -251,7 +251,7 @@ module.exports = function(RED) {
}
});
obj.serial.on('open',function() {
util.log("[serial] serial port "+port+" opened at "+baud+" baud "+databits+""+parity.charAt(0).toUpperCase()+stopbits);
RED.log.info("serial port "+port+" opened at "+baud+" baud "+databits+""+parity.charAt(0).toUpperCase()+stopbits);
if (obj.tout) { clearTimeout(obj.tout); }
//obj.serial.flush();
obj._emitter.emit('ready');
@ -269,7 +269,7 @@ module.exports = function(RED) {
//}
});
obj.serial.on("disconnect",function() {
util.log("[serial] serial port "+port+" gone away");
RED.log.error("serial port "+port+" gone away");
});
}
setupSerial();
@ -286,7 +286,7 @@ module.exports = function(RED) {
connections[port]._closing = true;
try {
connections[port].close(function() {
util.log("[serial] serial port closed");
RED.log.info("serial port closed");
done();
});
}

View File

@ -81,7 +81,9 @@ module.exports = function(RED) {
}
});
server.bind(node.port,node.iface);
// Hack for when you have both in and out udp nodes sharing a port
// if udp in starts last it shares better - so give it a chance to be last
setTimeout( function() { server.bind(node.port,node.iface); }, 250);;
}
RED.nodes.registerType("udp in",UDPin);

View File

@ -61,7 +61,6 @@
access_token: {type: "password"},
access_token_secret: {type:"password"}
},
label: function() {
return this.screen_name;
},
@ -181,7 +180,6 @@
});
$("#node-input-user").change();
}
});
</script>

View File

@ -218,7 +218,7 @@ module.exports = function(RED) {
}
});
stream.on('limit', function(tweet) {
node.log("tweet rate limit hit");
node.warn("tweet rate limit hit");
});
stream.on('error', function(tweet,rc) {
if (rc == 420) {
@ -367,8 +367,8 @@ module.exports = function(RED) {
credentials.oauth_verifier,
function(error, oauth_access_token, oauth_access_token_secret, results){
if (error){
console.log(error);
res.send("yeah something broke.");
RED.log.error(error);
res.send("something in twitter oauth broke.");
} else {
credentials = {};
credentials.access_token = oauth_access_token;

View File

@ -57,7 +57,7 @@ module.exports = function(RED) {
});
tail.stderr.on("data", function(data) {
node.warn(data.toString());
node.error(data.toString());
});
this.on("close", function() {

View File

@ -40,7 +40,7 @@ module.exports = function(RED) {
} else if (msg.hasOwnProperty('delete')) {
node.warn("Deprecated: please use specific delete option in config dialog.");
fs.unlink(filename, function (err) {
if (err) { node.warn('Failed to delete file : '+err); }
if (err) { node.error('Failed to delete file : '+err); }
});
} else if (typeof msg.payload != "undefined") {
var data = msg.payload;
@ -53,13 +53,13 @@ module.exports = function(RED) {
// using "binary" not {encoding:"binary"} to be 0.8 compatible for a while
//fs.writeFile(filename, data, {encoding:"binary"}, function (err) {
fs.writeFile(filename, data, "binary", function (err) {
if (err) { node.warn('Failed to write to file : '+err); }
if (err) { node.error('Failed to write to file : '+err); }
else if (RED.settings.verbose) { node.log('wrote to file: '+filename); }
});
}
else if (this.overwriteFile === "delete") {
fs.unlink(filename, function (err) {
if (err) { node.warn('Failed to delete file : '+err); }
if (err) { node.error('Failed to delete file : '+err); }
else if (RED.settings.verbose) { node.log("deleted file: "+filename); }
});
}
@ -67,7 +67,7 @@ module.exports = function(RED) {
// using "binary" not {encoding:"binary"} to be 0.8 compatible for a while longer
//fs.appendFile(filename, data, {encoding:"binary"}, function (err) {
fs.appendFile(filename, data, "binary", function (err) {
if (err) { node.warn('Failed to append to file : '+err); }
if (err) { node.error('Failed to append to file : '+err); }
else if (RED.settings.verbose) { node.log('appended to file: '+filename); }
});
}
@ -103,7 +103,7 @@ module.exports = function(RED) {
msg.filename = filename;
fs.readFile(filename,options,function(err,data) {
if (err) {
node.warn(err);
node.error(err);
msg.error = err;
delete msg.payload;
} else {

View File

@ -16,7 +16,6 @@
module.exports = function(RED) {
"use strict";
var util = require("util");
var redis = require("redis");
var hashFieldRE = /^([^=]+)=(.*)$/;
@ -29,10 +28,10 @@ module.exports = function(RED) {
if (!connections[id]) {
connections[id] = redis.createClient(port,host);
connections[id].on("error",function(err) {
util.log("[redis] "+err);
RED.log.error(err);
});
connections[id].on("connect",function() {
util.log("[redis] connected to "+host+":"+port);
if (RED.settings.verbose) { RED.log.info("connected to "+host+":"+port); }
});
connections[id]._id = id;
connections[id]._nodeCount = 0;