chore(providence-analytics): allow to config LogService better
This commit is contained in:
parent
a849f09fa9
commit
816f24f862
1 changed files with 33 additions and 4 deletions
|
|
@ -26,7 +26,10 @@ class LogService {
|
||||||
* @param {string} [title]
|
* @param {string} [title]
|
||||||
*/
|
*/
|
||||||
static debug(text, title) {
|
static debug(text, title) {
|
||||||
if (!this.debugEnabled) return;
|
if (this.allMuted || !this.debugEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
log(chalk.bgCyanBright.black.bold(` debug${printTitle(title)}`), text);
|
log(chalk.bgCyanBright.black.bold(` debug${printTitle(title)}`), text);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this._logHistory.push(`- debug -${printTitle(title)} ${text}`);
|
this._logHistory.push(`- debug -${printTitle(title)} ${text}`);
|
||||||
|
|
@ -37,6 +40,10 @@ class LogService {
|
||||||
* @param {string} [title]
|
* @param {string} [title]
|
||||||
*/
|
*/
|
||||||
static warn(text, title) {
|
static warn(text, title) {
|
||||||
|
if (this.allMuted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
log(chalk.bgYellowBright.black.bold(`warning${printTitle(title)}`), text);
|
log(chalk.bgYellowBright.black.bold(`warning${printTitle(title)}`), text);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this._logHistory.push(`- warning -${printTitle(title)} ${text}`);
|
this._logHistory.push(`- warning -${printTitle(title)} ${text}`);
|
||||||
|
|
@ -47,9 +54,18 @@ class LogService {
|
||||||
* @param {string} [title]
|
* @param {string} [title]
|
||||||
*/
|
*/
|
||||||
static error(text, title) {
|
static error(text, title) {
|
||||||
log(chalk.bgRedBright.black.bold(` error${printTitle(title)}`), text);
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this._logHistory.push(`- error -${printTitle(title)} ${text}`);
|
this._logHistory.push(`- error -${printTitle(title)} ${text}`);
|
||||||
|
|
||||||
|
if (this.throwsOnError) {
|
||||||
|
throw new Error(`${title ? `[${title}]: ` : ''}text`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.allMuted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log(chalk.bgRedBright.black.bold(` error${printTitle(title)}`), text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -57,9 +73,13 @@ class LogService {
|
||||||
* @param {string} [title]
|
* @param {string} [title]
|
||||||
*/
|
*/
|
||||||
static success(text, title) {
|
static success(text, title) {
|
||||||
log(chalk.bgGreen.black.bold(`success${printTitle(title)}`), text);
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this._logHistory.push(`- success -${printTitle(title)} ${text}`);
|
this._logHistory.push(`- success -${printTitle(title)} ${text}`);
|
||||||
|
if (this.allMuted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log(chalk.bgGreen.black.bold(`success${printTitle(title)}`), text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -67,9 +87,14 @@ class LogService {
|
||||||
* @param {string} [title]
|
* @param {string} [title]
|
||||||
*/
|
*/
|
||||||
static info(text, title) {
|
static info(text, title) {
|
||||||
log(chalk.bgBlue.black.bold(` info${printTitle(title)}`), text);
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this._logHistory.push(`- info -${printTitle(title)} ${text}`);
|
this._logHistory.push(`- info -${printTitle(title)} ${text}`);
|
||||||
|
|
||||||
|
if (this.allMuted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log(chalk.bgBlue.black.bold(` info${printTitle(title)}`), text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -123,7 +148,11 @@ class LogService {
|
||||||
this._logHistory = [];
|
this._logHistory = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LogService.debugEnabled = false;
|
LogService.debugEnabled = false;
|
||||||
|
LogService.allMuted = false;
|
||||||
|
LogService.throwsOnError = false;
|
||||||
|
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
LogService._logHistory = [];
|
LogService._logHistory = [];
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue