unify format of console output with stored logs

pull/1/head
ansuz 5 years ago
parent 8a5d012edf
commit 37d3995ac1

@ -23,29 +23,13 @@ var write = function (ctx, content) {
// various degrees of logging // various degrees of logging
const logLevels = Logger.levels = ['silly', 'verbose', 'debug', 'feedback', 'info', 'warn', 'error']; const logLevels = Logger.levels = ['silly', 'verbose', 'debug', 'feedback', 'info', 'warn', 'error'];
var handlers = { var handlers = {};
silly: function (ctx, time, tag, info) { ['silly', 'debug', 'verbose', 'feedback', 'info'].forEach(function (level) {
console.log('[SILLY]', time, tag, info); handlers[level] = function (ctx, content) { console.log(content); };
}, });
debug: function (ctx, time, tag, info) { ['warn', 'error'].forEach(function (level) {
console.log('[DEBUG]', time, tag, info); handlers[level] = function (ctx, content) { console.error(content); }
}, });
verbose: function (ctx, time, tag, info) {
console.log('[VERBOSE]', time, tag, info);
},
feedback: function (ctx, time, tag, info) {
console.log('[FEEDBACK]', time, tag, info);
},
info: function (ctx, time, tag, info) {
console.info('[INFO]', time, tag, info);
},
warn: function (ctx, time, tag, info) {
console.warn('[WARN]', time, tag, info);
},
error: function (ctx, time, tag, info) {
console.error('[ERROR]', time, tag, info);
}
};
var noop = function () {}; var noop = function () {};
@ -65,7 +49,7 @@ var createLogType = function (ctx, type) {
return; return;
} }
if (ctx.logToStdout && typeof(handlers[type]) === 'function') { if (ctx.logToStdout && typeof(handlers[type]) === 'function') {
handlers[type](ctx, time, tag, info); handlers[type](ctx, content);
} }
write(ctx, content); write(ctx, content);
}; };

Loading…
Cancel
Save