将 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() 与电子一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
Ordinals in words javascript(javascript中的序数)
getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)