Binato/ConsoleHelper.ts

75 lines
1.7 KiB
TypeScript
Raw Permalink Normal View History

2023-08-20 13:03:01 +01:00
import * as dyetty from "dyetty";
2022-11-16 11:59:23 +00:00
2023-09-10 20:37:46 +01:00
console.clear();
2022-11-16 11:59:23 +00:00
enum LogType {
INFO,
WARN,
ERROR
2023-10-04 15:52:18 +01:00
}
2022-11-16 11:59:23 +00:00
const LogTags = {
2023-08-20 13:03:01 +01:00
INFO: dyetty.bgGreen(dyetty.black(" INFO ")),
BANCHO: dyetty.bgMagenta(dyetty.black(" BANCHO ")),
WEBREQ: dyetty.bgGreen(dyetty.black(" WEBREQ ")),
CHAT: dyetty.bgCyan(dyetty.black(" CHAT ")),
WARN: dyetty.bgYellow(dyetty.black(" WARN ")),
ERROR: dyetty.bgRed(" ERRR "),
REDIS: dyetty.bgRed(dyetty.white(" bREDIS ")),
STREAM: dyetty.bgBlue(dyetty.black(" STREAM "))
2022-11-16 11:59:23 +00:00
} as const;
function correctValue(i:number) : string {
if (i <= 9) return `0${i}`;
else return i.toString();
}
function getTime() : string {
const time = new Date();
2023-08-20 13:03:01 +01:00
return dyetty.green(`[${correctValue(time.getHours())}:${correctValue(time.getMinutes())}:${correctValue(time.getSeconds())}]`);
2022-11-16 11:59:23 +00:00
}
function log(tag:string, log:string, logType:LogType = LogType.INFO) : void {
switch (logType) {
case LogType.INFO:
return console.log(`${getTime()} ${tag} ${log}`);
case LogType.WARN:
return console.warn(`${getTime()} ${tag} ${log}`);
case LogType.ERROR:
return console.error(`${getTime()} ${tag} ${log}`);
}
}
export class ConsoleHelper {
public static printWebReq(s:string) : void {
log(LogTags.WEBREQ, s);
}
2022-11-19 01:06:03 +00:00
public static printStream(s:string) : void {
log(LogTags.STREAM, s);
}
public static printInfo(s:string) : void {
log(LogTags.INFO, s);
}
2022-11-16 11:59:23 +00:00
public static printBancho(s:string) : void {
log(LogTags.BANCHO, s);
}
public static printRedis(s:string) : void {
log(LogTags.REDIS, s);
}
public static printChat(s:string) : void {
log(LogTags.CHAT, s);
}
public static printWarn(s:string) : void {
log(LogTags.WARN, s);
}
public static printError(s:string) : void {
log(LogTags.ERROR, s);
}
}