electron-egg中childJob中使用consolelog输入日志在vscode的终端中看不到内容
在Electron-Egg中,使用console.log输出日志的时候,默认是输出到主进程的控制台窗口中,而不是终端中。如果希望在终端中看到输出的内容,可以使用以下方法:
-
在终端中启动Electron-Egg应用程序时,添加
--inspect参数,例如:npm run dev -- --inspect。这样会启动Chrome开发者工具,并将控制台输出信息输出到终端中。 -
在childJob中使用
process.send()方法将日志信息发送给主进程,然后在主进程中打印日志。示例如下:
// childJob.js
console.log('Log message');
process.send({ type: 'log', message: 'Log message' });
// main.js
const { app, EggChildProcess } = require('electron-egg');
app.ready(async ({ logger }) => {
const childProcess = new EggChildProcess('childJob', { execArgv: [] });
childProcess.on('message', (message) => {
if (message.type === 'log') {
logger.info(message.message); // 在主进程中打印日志
}
});
await childProcess.ready();
});
通过以上方法,可以将childJob中的日志输出到终端中
原文地址: https://www.cveoy.top/t/topic/iLhi 著作权归作者所有。请勿转载和采集!