修改代码, 添加新的日志输出

This commit is contained in:
xys20071111 2022-12-06 20:33:48 +08:00
parent f39c3b628f
commit 7a5475b93c
No known key found for this signature in database
GPG Key ID: 29CB7FFE349CFD03
3 changed files with 26 additions and 12 deletions

View File

@ -19,7 +19,9 @@ if (!config.disable_super_chat_action) {
if (!config.disable_super_chat_action) {
danmakuReceiver.on('SUPER_CHAT_MESSAGE', onSuperChat)
}
globalThis.onunload = () => {
printLog('主程序', '退出')
}
danmakuReceiver.on('closed', () => danmakuReceiver.connect())
danmakuReceiver.on('LIVE', onLiveStart)
danmakuReceiver.on('PREPARING', onLiveEnd)

View File

@ -1,3 +1,5 @@
import { printErr } from "./utils/PrintLog.ts"
const pluginSet: Set<Deno.Process> = new Set()
export async function launchAllPlugins() {
@ -6,23 +8,30 @@ export async function launchAllPlugins() {
if (plugin.name === '.gitkeep') {
continue
}
try {
const pluginProcess = Deno.run({
cmd: [`./plugins/${plugin.name}/${plugin.name}`, `./plugins/${plugin.name}/config.json`]
cmd: [`./plugins/${plugin.name}/main`, `./plugins/${plugin.name}/config.json`]
})
pluginSet.add(pluginProcess)
} catch {
printErr('主程序', `启动插件${plugin.name}失败`)
}
}
}
Deno.addSignalListener("SIGTERM", () => {
function stopAllPlugins() {
for (const pluginProcess of pluginSet) {
pluginProcess.kill()
}
Deno.exit()
})
Deno.addSignalListener("SIGINT", () => {
for (const pluginProcess of pluginSet) {
pluginProcess.kill()
}
Deno.addSignalListener('SIGTERM', () => {
stopAllPlugins()
Deno.exit()
})
Deno.addSignalListener('SIGINT', () => {
stopAllPlugins()
Deno.exit()
})

View File

@ -1,4 +1,7 @@
import { getTimeString } from './GetTimeString.ts'
export function printLog(type: string, msg: unknown) {
console.log(`[${type}][${getTimeString()}] ${msg}`)
export function printLog(source: string, msg: unknown) {
console.log(`[log][${source}][${getTimeString()}] ${msg}`)
}
export function printErr(source: string, msg: unknown) {
console.error(`[err][${source}][${getTimeString()}] ${msg}`)
}