unify format of console output with stored logs

This commit is contained in:
ansuz 2020-04-28 17:05:15 -04:00
parent 8a5d012edf
commit 37d3995ac1
1 changed files with 8 additions and 24 deletions

View File

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