gpt4 book ai didi

javascript - node.js 错误日志包含更多信息

转载 作者:搜寻专家 更新时间:2023-11-01 00:34:20 24 4
gpt4 key购买 nike

我正在这样启动我的 node.js 服务器:

sudo NODE_ENV=production forever start -o out.log -e err.log server.js

有时我会在错误日志中收到错误。

但我得到的是这样的:

Cannot read property 'length' of undefined
at eval at <anonymous> (/home/ubuntu/www/node_modules/jade/lib/jade.js:161:8)
at anonymous (eval at <anonymous> (/home/ubuntu/www/node_modules/jade/lib/jade.js:161:8))
at Object.<anonymous> (/home/ubuntu/www/node_modules/jade/lib/jade.js:166:12)
at ServerResponse._render (/home/ubuntu/www/node_modules/express/lib/view.js:422:21)
at ServerResponse.render (/home/ubuntu/www/node_modules/express/lib/view.js:315:17)
at callbacks (/home/ubuntu/www/node_modules/express/lib/router/index.js:272:11)
at Promise.<anonymous> (/home/ubuntu/www/helper/auth.js:118:11)
at Promise.<anonymous> (/home/ubuntu/www/node_modules/mongoose/lib/promise.js:120:8)

如何让错误日志显示更多信息,例如错误发生的日期时间?

最佳答案

像这样使用 'uncaughtException' 事件:

process.on('uncaughtException', function (err) {
console.log('Caught exception: ' + err);
});

setTimeout(function () {
console.log('This will still run.');
}, 500);

// Intentionally cause an exception, but don't catch it.
nonexistentFunc();
console.log('This will not run.');

您可以在回调中记录一个日期以及您想要注销的任何其他内容。

更多关于这里的过程: http://nodejs.org/docs/v0.4.12/api/process.html#event_uncaughtException_

关于javascript - node.js 错误日志包含更多信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7962941/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com