将 console.log() 与电子一起使用

using console.log() with electron(将 console.log() 与电子一起使用)
本文介绍了将 console.log() 与电子一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

I have seen a lot of questions from people trying to console log from the rendering process, this is NOT my problem I have console.log littering my main code and I don't see anything in my console here is my code.

/* 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');
  }
});

除了电子本身产生的日志之外,我没有看到任何日志我尝试抛出错误并且这些工作正常,但是任何与控制台相关的东西都不起作用,我尝试在 PowerShell 中运行它并从 GitHub 重新拉取,我的朋友在拉取项目时可以看到控制台日志虽然如此看来我是孤立的.我还更新了 NPM 和与项目相关的所有模块,并且我尝试创建一个新控制台并登录到该控制台,但它似乎没有出现,我错过了什么吗?我已经为此投入了数小时,并准备放弃.

I don't see a single log other than the ones produced by electron itself I've tried throwing errors and those work fine but anything console.* related doesn't work at all, I've tried running it in PowerShell and re-pulling from GitHub, my friend can see the console logs when he pulls the project though so it seems I'm isolated. I've also updated NPM and all modules associated with the project AND I've tried creating a new console and logging to that one but it doesn't seem to show up, am I missing something? I've put hours into this and am ready to give up.

推荐答案

我感觉到你的痛苦.我的一个盒子(一个 Server2012 盒子)有这个问题.直到我偶然发现 此评论 上的一个电子对我有用问题线程.

I feel your pain. I have this issue on one of my boxes (a Server2012 box). Nothing worked for me until I stumbled across this comment on one of the electron issues threads.

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

Typically when you install electron you will have a script in your package.json that looks like this.

"scripts": {
    "start": "electron .",
}

我改成了

"scripts": {
    "start": "C:/path/to/project/node_modules/electron-prebuilt/dist/electron.exe .",
}

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

And I started to get logging from the main electron process in powershell.

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

Note that if you are using newer versions of electron, you may need to change electron-prebuilt to electron.

这篇关于将 console.log() 与电子一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Google apps script get range of bytes from binary file(谷歌应用程序脚本从二进制文件中获取字节范围)
Sending Multiple attachments with Google Script from Google Drive(使用 Google 脚本从 Google Drive 发送多个附件)
Distributing Google Apps Scripts for Sheets in your company network(在您的公司网络中分发适用于表格的 Google Apps 脚本)
Upload file to my google drive from anyone using javascript(使用 javascript 将文件从任何人上传到我的谷歌驱动器)
quot;Shared Drivequot; support in Google Apps Script(“共享驱动器Google Apps 脚本中的支持)
Angular 2+ HTTP POST and GDrive API. Resumable file upload with name(Angular 2+ HTTP POST 和 GDrive API.带名称的可恢复文件上传)