在 Linux 上“开启 JS 日志”具体要看你说的是哪种 JS 运行环境,常见有下面几种情况,你对照看看:
console.log('普通日志');
console.log('错误日志', err);
运行:
node app.js
日志会直接打印到终端。
node app.js > app.log 2>&1
或实时查看:
tail -f app.log
如 winston、pino:
npm install winston
const winston = require('winston');
winston.info('服务启动');
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
page.on('console', msg => console.log('浏览器日志:', msg.text()));
await page.goto('https://example.com');
})();
JS 错误不会写进 Nginx 日志,只能:
window.onerrorwindow.onerror = function(msg, url, line) {
console.log(`JS错误: ${msg} @ ${url}:${line}`);
};
electron . --enable-logging
你可以告诉我:
我可以直接给你对应的开启命令。