show log level, fix bug with leading space in logs

This commit is contained in:
jomo 2015-01-31 20:28:59 +01:00
parent 08706e56bd
commit 5ccff8474d

View File

@ -2,20 +2,36 @@ var config = require("./config");
var exp = {}; var exp = {};
function log() { function split_args(args) {
var time = new Date().toISOString(); var text = "";
var text = ''; for (var i = 0, l = args.length; i < l; i++) {
for (var i = 0, l = arguments.length; i < l; i++) { if (i > 0) {
text += ' ' + arguments[i]; text += " " + args[i];
} else {
text += args[i];
} }
console.log(time + ": " + text); }
return text;
} }
exp.log = log; function log(level, args) {
exp.warn = log; var time = new Date().toISOString();
exp.error = log; console.log(time + ": " + level + ": " + split_args(args));
}
exp.log = function() {
log(" INFO", arguments);
};
exp.warn = function() {
log(" WARN", arguments);
};
exp.error = function() {
log("ERROR", arguments);
};
if (config.debug_enabled) { if (config.debug_enabled) {
exp.debug = log; exp.debug = function() {
log("DEBUG", arguments);
};
} else { } else {
exp.debug = function(){}; exp.debug = function(){};
} }