fix: color logs and notification

Signed-off-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
Jef LeCompte
2020-09-23 18:43:25 -04:00
parent a154e95681
commit 76b28a6dbd
4 changed files with 53 additions and 28 deletions
+33 -9
View File
@@ -10,7 +10,7 @@ const prettyJson = format.printf(info => {
info.message = JSON.stringify(info.message, null, 4);
}
return `[${timestamp}] ${info.level} :: ${info.message}`;
return colors.grey(`[${timestamp}]`) + ` ${info.level} ` + colors.grey('::') + ` ${info.message}`;
});
export const Logger = winston.createLogger({
@@ -26,16 +26,40 @@ export const Logger = winston.createLogger({
});
export const Print = {
captcha(link: Link, store: Store): string {
return colors.cyan(`✖ [${store.name}]`) + colors.grey(` [${link.brand} (${link.series})] ${link.model}`) + colors.yellow(' :: CAPTCHA');
captcha(link: Link, store: Store, color?: boolean): string {
if (color) {
return '✖ ' + buildProductString(link, store, true) + ' :: ' + colors.yellow('CAPTCHA');
}
return `${buildProductString(link, store)} :: CAPTCHA`;
},
inStock(link: Link, store: Store): string {
return colors.cyan(`✖ [${store.name}]`) + colors.grey(` [${link.brand} (${link.series})] ${link.model}`) + colors.green.bold(' :: IN STOCK 🚨🚀');
inStock(link: Link, store: Store, color?: boolean): string {
if (color) {
return colors.rainbow(`🚀🚨 ${buildProductString(link, store, true)} :: IN STOCK 🚨🚀`);
}
return `🚀🚨 ${buildProductString(link, store)} :: IN STOCK 🚨🚀`;
},
outOfStock(link: Link, store: Store): string {
return colors.cyan(`✖ [${store.name}]`) + colors.grey(` [${link.brand} (${link.series})] ${link.model}`) + colors.red(' :: OUT OF STOCK');
outOfStock(link: Link, store: Store, color?: boolean): string {
if (color) {
return '✖ ' + buildProductString(link, store, true) + ' :: ' + colors.red('OUT OF STOCK');
}
return `${buildProductString(link, store)} :: OUT OF STOCK`;
},
rateLimit(link: Link, store: Store): string {
return colors.cyan(`✖ [${store.name}]`) + colors.grey(` [${link.brand} (${link.series})] ${link.model}`) + colors.yellow(' :: RATE LIMIT EXCEEDED');
rateLimit(link: Link, store: Store, color?: boolean): string {
if (color) {
return '✖ ' + buildProductString(link, store, true) + ' :: ' + colors.yellow('RATE LIMIT EXCEEDED');
}
return `${buildProductString(link, store)} :: RATE LIMIT EXCEEDED`;
}
};
function buildProductString(link: Link, store: Store, color?: boolean): string {
if (color) {
return colors.cyan(`[${store.name}]`) + colors.grey(` [${link.brand} (${link.series})] ${link.model}`);
}
return `[${store.name}] [${link.brand} (${link.series})] ${link.model}`;
}