diff --git a/src/app.js b/src/app.js index 31cfbfe4a..e00588be2 100644 --- a/src/app.js +++ b/src/app.js @@ -189,6 +189,8 @@ async function main() { (async () => { try { await main(); + //等待日志文件写入 + await delay(1000); } finally { const logs = catLogs(); const events = recording.replay(); diff --git a/src/logger.js b/src/logger.js index a457e3ce8..c51536df1 100644 --- a/src/logger.js +++ b/src/logger.js @@ -23,7 +23,7 @@ log4js.configure({ compress: true, layout: { type: "pattern", - pattern: "%X{user} %m", + pattern: "[账号:%X{user}] %m", }, }, }, diff --git a/src/push/index.js b/src/push/index.js index 9d03dbe25..352cc4acc 100644 --- a/src/push/index.js +++ b/src/push/index.js @@ -7,6 +7,7 @@ const wxpush = require("./wxPusher"); const pushPlus = require("./pushPlus"); const logger = log4js.getLogger("push"); +logger.addContext("user", "push"); const pushServerChan = (title, desp) => { if (!serverChan.sendKey) { @@ -45,17 +46,15 @@ const pushTelegramBot = (title, desp) => { .post(`https://api.telegram.org/bot${telegramBot.botToken}/sendMessage`) .type("form") .send(data) - .end((err, res) => { - if (err) { - logger.error(`TelegramBot推送失败:${JSON.stringify(err)}`); - return; - } - const json = JSON.parse(res.text); - if (!json.ok) { - logger.error(`TelegramBot推送失败:${JSON.stringify(json)}`); - } else { + .then((res) => { + if (res.body?.ok) { logger.info("TelegramBot推送成功"); + } else { + logger.error(`TelegramBot推送失败:${JSON.stringify(res.body)}`); } + }) + .catch((err) => { + logger.error(`TelegramBot推送失败:${JSON.stringify(err)}`); }); }; @@ -75,17 +74,15 @@ const pushWecomBot = (title, desp) => { `https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${wecomBot.key}` ) .send(data) - .end((err, res) => { - if (err) { - logger.error(`wecomBot推送失败:${JSON.stringify(err)}`); - return; - } - const json = JSON.parse(res.text); - if (json.errcode) { - logger.error(`wecomBot推送失败:${JSON.stringify(json)}`); + .then((res) => { + if (res.body?.errcode) { + logger.error(`wecomBot推送失败:${JSON.stringify(res.body)}`); } else { logger.info("wecomBot推送成功"); } + }) + .catch((err) => { + logger.error(`wecomBot推送失败:${JSON.stringify(err)}`); }); }; @@ -104,7 +101,7 @@ const pushWxPusher = (title, desp) => { .post("https://wxpusher.zjiecode.com/api/send/message") .send(data) .then((res) => { - if (res.body?.code === 100) { + if (res.body?.code === 1000) { logger.info("wxPusher推送成功"); } else { logger.error(`wxPusher推送失败:${JSON.stringify(res.body)}`); @@ -130,17 +127,15 @@ const pushPlusPusher = (title, desp) => { superagent .post("http://www.pushplus.plus/send/") .send(data) - .end((err, res) => { - if (err) { - logger.error(`pushPlus 推送失败:${JSON.stringify(err)}`); - return; - } - const json = JSON.parse(res.text); - if (json.code !== 200) { - logger.error(`pushPlus 推送失败:${JSON.stringify(json)}`); - } else { + .then((res) => { + if (res.body?.code === 200) { logger.info("pushPlus 推送成功"); + } else { + logger.error(`pushPlus 推送失败:${JSON.stringify(res.body)}`); } + }) + .catch((err) => { + logger.error(`pushPlus 推送失败:${JSON.stringify(err)}`); }); };