cctail
Version:
Salesforce Commerce Cloud logs remote tail
82 lines (81 loc) • 2.53 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const colorette_1 = require("colorette");
const { log } = console;
const logger = {
debugPrefix: '*** ',
debug: 'debug',
error: 'error',
fatal: 'fatal',
info: 'info',
jobs: 'jobs',
profile: 'PROFILE',
warn: 'warn',
colormap: {
DEBUG: colorette_1.cyanBright,
debug: colorette_1.cyan,
ERROR: colorette_1.redBright,
error: colorette_1.red,
FATAL: colorette_1.redBright,
fatal: colorette_1.red,
INFO: colorette_1.greenBright,
info: colorette_1.green,
JOBS: colorette_1.blueBright,
jobs: colorette_1.blue,
PROFILE: colorette_1.magentaBright,
profile: colorette_1.magenta,
WARN: colorette_1.yellowBright,
warn: colorette_1.yellow
},
log: function (level, text, debug) {
if (level !== this.debug) {
log(this.colorize(level, text));
}
else if (debug) {
log(this.colorize(level, this.debugPrefix + text));
}
},
colorize: function (level, text) {
if (!level || level.length === 0) {
return text;
}
let color = this.colormap[level];
if (!color) {
switch (true) {
case this.checkFor(level, "info"):
color = this.colormap["info"];
break;
case this.checkFor(level, "warn"):
color = this.colormap["warn"];
break;
case this.checkFor(level, "error"):
color = this.colormap["error"];
break;
case this.checkFor(level, "fatal"):
color = this.colormap["fatal"];
break;
case this.checkFor(level, "jobs"):
color = this.colormap["jobs"];
break;
case this.checkFor(level, "debug"):
color = this.colormap["debug"];
break;
case this.checkFor(level, "profile"):
color = this.colormap["profile"];
break;
default:
break;
}
}
if (color) {
return color(text);
}
else {
return text;
}
},
checkFor: function (input, term) {
return (input.indexOf(term) != -1);
}
};
exports.default = logger;