From 8826627e5cf006a22ff8a01057464bc8a7b7f8e5 Mon Sep 17 00:00:00 2001 From: SmallK111407 <3399280843@qq.com> Date: Sun, 9 Jun 2024 04:00:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96log.js=E4=BB=A3=E7=A0=81=20?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=E7=89=B9=E5=AE=9A=E6=83=85=E5=86=B5=E4=B8=8B?= =?UTF-8?q?spawn=E6=8A=A5=E9=94=99=20;=20=E7=BB=86=E8=8A=82=E4=BC=98?= =?UTF-8?q?=E5=8C=96README.md=E6=8E=92=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++++ lib/tools/log.js | 25 +++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ef3f317..93a13e7 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,8 @@ node app ## 常见问题 +
展开/收起 + ### 无头浏览器相关 linux环境,其他环境请自行探索 @@ -82,6 +84,8 @@ sudo mv libstdc++.so.6 libstdc++.so.6.bak sudo ln -s libstdc++.so.6.0.29 libstdc++.so.6 ``` +
+ ## 与原版Yunzai-Bot的差异 **【注意】:** 由于是独立新的仓库,【只建议新部署/部署后迁移】,不建议原Bot直接换源强更 diff --git a/lib/tools/log.js b/lib/tools/log.js index 33799aa..5cbacaa 100644 --- a/lib/tools/log.js +++ b/lib/tools/log.js @@ -3,9 +3,9 @@ import childProcess from "child_process" const _path = process.cwd() -fs.readFile(`${_path}/config/pm2/pm2.json`, `utf8`, (err, data) => { +fs.readFile(`${_path}/config/pm2/pm2.json`, "utf8", (err, data) => { if (err) { - console.log('pm2.json文件读取错误:', err) + console.error("pm2.json文件读取错误:", err) return } @@ -15,18 +15,27 @@ fs.readFile(`${_path}/config/pm2/pm2.json`, `utf8`, (err, data) => { const appName = config.apps[0].name runPm2Logs(appName) } else { - console.log('读取失败:无法在pm2.json中找到name数组') + console.error("读取失败:无法在pm2.json中找到name数组") } } catch (parseError) { - console.log('读取失败:json文件解析发生了错误', parseError) + console.error("读取失败:json文件解析发生了错误", parseError) } }) function runPm2Logs(appName) { - const command = process.platform === 'win32' ? 'pm2.cmd' : 'pm2' - const args = ['logs', '--lines', '400', appName] - const pm2LogsProcess = childProcess.spawn(command, args, { stdio: 'inherit' }) - pm2LogsProcess.on('exit', (code) => { + const command = process.platform === "win32" ? "pm2.cmd" : "pm2" + const args = ["logs", "--lines", "400", appName] + + console.log(`Command: ${command}`) + console.log(`Args: ${args.join(" ")}`) + + const pm2LogsProcess = childProcess.spawn(command, args, { stdio: "inherit", shell: true }) + + pm2LogsProcess.on("error", (error) => { + console.error("Error spawning pm2 logs process:", error) + }) + + pm2LogsProcess.on("exit", (code) => { if (code !== 0) { console.error(`pm2 logs process exited with code ${code}`) }