Skip to content

Commit

Permalink
修改日志
Browse files Browse the repository at this point in the history
  • Loading branch information
wesl authored and wesl committed Feb 27, 2025
1 parent 752e3e2 commit 90d00d3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
2 changes: 2 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ async function main() {
(async () => {
try {
await main();
//等待日志文件写入
await delay(1000);
} finally {
const logs = catLogs();
const events = recording.replay();
Expand Down
2 changes: 1 addition & 1 deletion src/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ log4js.configure({
compress: true,
layout: {
type: "pattern",
pattern: "%X{user} %m",
pattern: "[账号:%X{user}] %m",
},
},
},
Expand Down
49 changes: 22 additions & 27 deletions src/push/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)}`);
});
};

Expand All @@ -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)}`);
});
};

Expand All @@ -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)}`);
Expand All @@ -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)}`);
});
};

Expand Down

0 comments on commit 90d00d3

Please sign in to comment.