优化log.js代码 防止特定情况下spawn报错 ; 细节优化README.md排版

This commit is contained in:
SmallK111407 2024-06-09 04:00:28 +08:00
parent b5e873532d
commit 8826627e5c
2 changed files with 21 additions and 8 deletions

View File

@ -51,6 +51,8 @@ node app
## 常见问题
<details><summary>展开/收起</summary>
### 无头浏览器相关
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
```
</details>
## 与原版Yunzai-Bot的差异
**【注意】:** 由于是独立新的仓库,【只建议新部署/部署后迁移】不建议原Bot直接换源强更

View File

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