mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-21 23:41:18 +01:00
prepend log prefix to each log line, use console.warn & console.error
this has two effects: 1. errors will go to stderr 2. errors (and other multi-line messages) will have the log prefix on *each line*
This commit is contained in:
parent
3958ad6a26
commit
7162562cdc
@ -15,19 +15,24 @@ function split_args(args) {
|
||||
return text;
|
||||
}
|
||||
|
||||
function log(level, args) {
|
||||
function log(level, args, logger) {
|
||||
logger = logger || console.log;
|
||||
var time = new Date().toISOString();
|
||||
console.log(time + " " + (cluster.worker && cluster.worker.id || "M") + " " + level + ": " + split_args(args));
|
||||
var clid = (cluster.worker && cluster.worker.id || "M");
|
||||
var lines = split_args(args).split("\n");
|
||||
for (var i = 0, l = lines.length; i < l; i++) {
|
||||
logger(time + " " + clid + " " + level + ": " + lines[i]);
|
||||
}
|
||||
}
|
||||
|
||||
exp.log = function() {
|
||||
log(" INFO", arguments);
|
||||
};
|
||||
exp.warn = function() {
|
||||
log(" WARN", arguments);
|
||||
log(" WARN", arguments, console.warn);
|
||||
};
|
||||
exp.error = function() {
|
||||
log("ERROR", arguments);
|
||||
log("ERROR", arguments, console.error);
|
||||
};
|
||||
if (config.debug_enabled || process.env.DEBUG === "true") {
|
||||
exp.debug = function() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user