2022-02-20 05:50:17 +08:00
|
|
|
import chalk from 'chalk';
|
2021-10-22 22:52:03 +08:00
|
|
|
|
|
|
|
export enum LogStyle {
|
2022-02-20 05:50:17 +08:00
|
|
|
None = 'None',
|
|
|
|
Info = 'Info',
|
|
|
|
Warning = 'Warning',
|
|
|
|
Failure = 'Failure',
|
|
|
|
Success = 'Success'
|
2021-10-22 22:52:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const LogStyleDetails: {[style: string]: {style: chalk.Chalk, prefix: string}} = {};
|
2022-02-20 08:42:30 +08:00
|
|
|
LogStyleDetails[LogStyle.Info] = {style: chalk.blue, prefix: chalk.blue.inverse('INFO')};
|
2022-02-20 05:50:17 +08:00
|
|
|
LogStyleDetails[LogStyle.Warning] = {style: chalk.yellow, prefix: chalk.yellow.inverse('WARN')};
|
|
|
|
LogStyleDetails[LogStyle.Failure] = {style: chalk.red, prefix: chalk.red.inverse('UHOH')};
|
|
|
|
LogStyleDetails[LogStyle.Success] = {style: chalk.green, prefix: chalk.green.inverse(' OK ')};
|
2021-10-22 22:52:03 +08:00
|
|
|
|
|
|
|
export function log(style: LogStyle, message: string) {
|
|
|
|
if (style === LogStyle.None) {
|
2022-02-20 05:50:17 +08:00
|
|
|
/* eslint-disable */
|
2021-10-22 22:52:03 +08:00
|
|
|
console.log(chalk.whiteBright(message));
|
2022-02-20 05:50:17 +08:00
|
|
|
/* eslint-enable */
|
2021-10-22 22:52:03 +08:00
|
|
|
} else {
|
|
|
|
const details: {style: chalk.Chalk, prefix: string} = LogStyleDetails[style];
|
2022-02-20 05:50:17 +08:00
|
|
|
/* eslint-disable */
|
|
|
|
console.log(details.prefix + ' ' + details.style(message));
|
|
|
|
/* eslint-enable */
|
2021-10-22 22:52:03 +08:00
|
|
|
}
|
2022-02-20 05:50:17 +08:00
|
|
|
}
|
2022-02-20 08:42:30 +08:00
|
|
|
|
|
|
|
export function logBreak() {
|
|
|
|
/* eslint-disable */
|
|
|
|
console.log()
|
|
|
|
/* eslint-enable */
|
|
|
|
}
|