feat: 新增日志等级Notice (#454)

Fixed #454
This commit is contained in:
shanmite 2025-05-19 09:08:03 +08:00
parent 737feae41e
commit bcf87a9d00
4 changed files with 24 additions and 12 deletions

View File

@ -12,7 +12,7 @@ module.exports = Object.freeze({
* - `ENABLE_MULTIPLE_ACCOUNT` 是否启用多账号 * - `ENABLE_MULTIPLE_ACCOUNT` 是否启用多账号
* - `MULTIPLE_ACCOUNT_PARM` 多账号参数(JSON格式) <不推荐使用 * - `MULTIPLE_ACCOUNT_PARM` 多账号参数(JSON格式) <不推荐使用
* ## 调试相关 * ## 调试相关
* - `LOTTERY_LOG_LEVEL` 输出日志等级 Error<Warn<Info<Debug 1<2<3<4 * - `LOTTERY_LOG_LEVEL` 输出日志等级 Error<Warn<Notice<Info<Debug 0<1<2<3<4
* - `NOT_GO_LOTTERY` 关闭抽奖行为 * - `NOT_GO_LOTTERY` 关闭抽奖行为
* *
* ## 多账号 * ## 多账号

View File

@ -92,10 +92,10 @@ async function isMe(num) {
log.info('中奖检测', '--> OK'); log.info('中奖检测', '--> OK');
} }
if (desp) { if (desp) {
log.info('可能中奖了', desp); log.notice('可能中奖了', desp);
await sendNotify(`帐号${num}可能中奖了`, desp); await sendNotify(`帐号${num}可能中奖了`, desp);
} else { } else {
log.info('中奖检测', '暂未中奖'); log.notice('中奖检测', '暂未中奖');
} }
return; return;
} }

View File

@ -83,7 +83,7 @@ async function update(isDdownload) {
log.info('自动下载', '成功下载到当前目录'); log.info('自动下载', '成功下载到当前目录');
log.info('检查更新', '请手动解压替换可执行文件'); log.info('检查更新', '请手动解压替换可执行文件');
} }
log.info('更新说明', '\n' + text + '\n'); log.notice('更新说明', '\n' + text + '\n');
} else { } else {
throw `未找到能在此平台(${process.platform})-(${process.arch})上运行的版本,建议以源码运行`; throw `未找到能在此平台(${process.platform})-(${process.arch})上运行的版本,建议以源码运行`;
} }

View File

@ -191,7 +191,7 @@ const utils = {
_level: 3, _level: 3,
_colors: [ _colors: [
chalk.hex('#64B3FF'), chalk.grey, chalk.hex('#FFA500'), chalk.hex('#64B3FF'), chalk.grey, chalk.hex('#FFA500'),
chalk.hex('#0070BB'), chalk.hex('#48BB31'), chalk.hex('#BBBB23'), chalk.hex('#FF0006') chalk.hex('#0070BB'), chalk.hex('#48BB31'), chalk.hex('#BFFF00'), chalk.hex('#BBBB23'), chalk.hex('#FF0006')
], ],
_iso_time: () => new Date(Date.now() + 288e5).toISOString().slice(0, -1) + '+08', _iso_time: () => new Date(Date.now() + 288e5).toISOString().slice(0, -1) + '+08',
_cache: [], _cache: [],
@ -231,7 +231,7 @@ const utils = {
process.stdout.write(status_bar); process.stdout.write(status_bar);
}, },
debug(context, msg) { debug(context, msg) {
if (this._level > 3) { if (this._level >= 4) {
if (msg instanceof Object) msg = JSON.stringify(msg, null, 4); if (msg instanceof Object) msg = JSON.stringify(msg, null, 4);
let color_text_pair = [ let color_text_pair = [
[this._colors[0], `[${this._iso_time()}]`], [this._colors[0], `[${this._iso_time()}]`],
@ -243,7 +243,7 @@ const utils = {
} }
}, },
info(context, msg) { info(context, msg) {
if (this._level > 2) { if (this._level >= 3) {
let color_text_pair = [ let color_text_pair = [
[this._colors[0], `[${this._iso_time()}]`], [this._colors[0], `[${this._iso_time()}]`],
[this._colors[1], '[Info]'], [this._colors[1], '[Info]'],
@ -254,25 +254,37 @@ const utils = {
this.proPrint(color_text_pair.map(([color, text]) => color(text))); this.proPrint(color_text_pair.map(([color, text]) => color(text)));
} }
}, },
notice(context, msg) {
if (this._level >= 2) {
let color_text_pair = [
[this._colors[0], `[${this._iso_time()}]`],
[this._colors[1], '[Notice]'],
[this._colors[2], `[帐号${process.env['NUMBER']} ${context}]`],
[this._colors[5], `[${msg}]`],
];
this._cache.push(color_text_pair.map(it => it[1]).join(' '));
this.proPrint(color_text_pair.map(([color, text]) => color(text)));
}
},
warn(context, msg) { warn(context, msg) {
if (this._level > 1) { if (this._level >= 1) {
let color_text_pair = [ let color_text_pair = [
[this._colors[0], `[${this._iso_time()}]`], [this._colors[0], `[${this._iso_time()}]`],
[this._colors[1], '[Warn]'], [this._colors[1], '[Warn]'],
[this._colors[2], `[帐号${process.env['NUMBER']} ${context}]`], [this._colors[2], `[帐号${process.env['NUMBER']} ${context}]`],
[this._colors[5], `[\n${msg}\n]`], [this._colors[6], `[\n${msg}\n]`],
]; ];
this._cache.push(color_text_pair.map(it => it[1]).join(' ')); this._cache.push(color_text_pair.map(it => it[1]).join(' '));
this.proPrint(color_text_pair.map(([color, text]) => color(text))); this.proPrint(color_text_pair.map(([color, text]) => color(text)));
} }
}, },
error(context, msg) { error(context, msg) {
if (this._level > 0) { if (this._level >= 0) {
let color_text_pair = [ let color_text_pair = [
[this._colors[0], `[${this._iso_time()}]`], [this._colors[0], `[${this._iso_time()}]`],
[this._colors[1], '[Error]'], [this._colors[1], '[Error]'],
[this._colors[2], `[帐号${process.env['NUMBER']} ${context}]`], [this._colors[2], `[帐号${process.env['NUMBER']} ${context}]`],
[this._colors[6], `[\n${msg}\n]`], [this._colors[7], `[\n${msg}\n]`],
]; ];
this._cache.push(color_text_pair.map(it => it[1]).join(' ')); this._cache.push(color_text_pair.map(it => it[1]).join(' '));
this.proPrint(color_text_pair.map(([color, text]) => color(text))); this.proPrint(color_text_pair.map(([color, text]) => color(text)));