使用带电子的console.log()

aid*_*lig 1 javascript node.js console.log electron

我已经看到很多人试图从渲染过程中控制日志的问题,这不是我的问题我有console.log乱丢我的主要代码,我在控制台中看不到任何东西,这是我的代码.

/* eslint-disable no-undef */
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const url = require('url');
/* eslint-enable */

let win;

console.log('console log test');

function createWindow() {
  win = new BrowserWindow({
    width: 800,
    height: 800
  });

  win.loadURL(url.format({
    pathname: path.join(__dirname, 'index.html'),
    protocol: 'file:',
    slashes: true
  }));

  win.on('close', () => {
    win = null;
  });

  console.log('console log test');
}

app.on('ready', createWindow);

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('activate', () => {
  if (win == null) {
    console.log('console log test');
    createWindow();
    console.log('console log test');
  }
});
Run Code Online (Sandbox Code Playgroud)

我没有看到除了电子本身产生的日志之外的其他日志我已经尝试过抛出错误而且那些工作正常但是任何控制台.*相关根本不起作用,我尝试在PowerShell中运行它并重新从GitHub拉出来,我的朋友可以在他拉动项目时看到控制台日志,所以看起来我已经被孤立了.我还更新了NPM和与项目相关的所有模块我已经尝试创建一个新的控制台并登录到那个但它似乎没有出现,我错过了什么?我花了几个小时,准备放弃.

her*_*rve 7

在 Windows 上,如果您想查看包含来自 console.log() 的所有消息的控制台,则必须使用参数--enable-logging启动应用程序,例如:

MyApp.exe --enable-logging
Run Code Online (Sandbox Code Playgroud)


Ber*_*ert 5

我感觉到你的痛苦.我的一个盒子(Server2012盒子)上有这个问题.在我偶然发现关于其中一个电子问题线程的评论之前,没有什么对我有用.

通常,当你安装电子时,你的package.json中会有一个如下所示的脚本.

"scripts": {
    "start": "electron .",
}
Run Code Online (Sandbox Code Playgroud)

我改变了我的意思

"scripts": {
    "start": "C:/path/to/project/node_modules/electron-prebuilt/dist/electron.exe .",
}
Run Code Online (Sandbox Code Playgroud)

我开始从powershell中的主电子过程中获取记录.

请注意,如果您使用较新版本的电子,则可能需要更改electron-prebuiltelectron.