在linux 环境下,nodejs崩溃时,怎么获取到log信息?
发布于 2年前 作者 catyuki 1600 次浏览

在windows下可以看到类似的记录

D:\DevSpace\StateMachine\app.js:9 [2013-01-09 13:02:24.853] [INFO] console - 2013/0/9 13:2 init config and network stateMachline.start2(); ^ TypeError: Object #<Object> has no method ‘start2’ at Object.<anonymous> (D:\DevSpace\StateMachine\app.js:9:15) at Module._compile (module.js:449:26) at Object.Module._extensions…js (module.js:467:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.runMain (module.js:492:10) at process.startup.processNextTick.process._tickCallback (node.js:244:9) linux下怎么用log记录这种崩溃信息

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

刚接触NODE 比较白 能否在多问一下 我是以node app.js的形式启动的 是不是只需要在app.js里面写 就行了?

我加上了 但是貌似还是没被捕获到 var stateMachline = require(‘./StateMachine’); var app = stateMachline.createApp(); stateMachline.init(); stateMachline.start();

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

依然有报错,崩溃,但是没能打印出ERR消息 2013/0/9 13:30 创建并初始化状态机 [2013-01-09 13:30:46.268] [INFO] console - 2013/0/9 13:30 init config and networ k D:\DevSpace\StateMachine\StateMachine.js:47 cNetwork.conect(); ^ TypeError: Cannot call method ‘conect’ of null at Object.StateMachine.start (D:\DevSpace\StateMachine\StateMachine.js:47:11 ) at Object.<anonymous> (D:\DevSpace\StateMachine\app.js:9:15) at Module._compile (module.js:449:26) at Object.Module._extensions…js (module.js:467:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.runMain (module.js:492:10) at process.startup.processNextTick.process._tickCallback (node.js:244:9)

已经捕获到了.非常感谢

有一个新问题 Err能否看到详细信息呢 而不是一句话:Cannot call method ‘conect’ of null

@Catyuki Error对象有name, message, stack等属性

@Catyuki 可以把这些错误信息也捕获到吗??? 我搞了下- -怎么没好用呢…

TypeError: Cannot call method 'conect' of null
    at Object.StateMachine.start (D:\DevSpace\StateMachine\StateMachine.js:47:11
)
at Object.<anonymous> (D:\DevSpace\StateMachine\app.js:9:15)
at Module.compile (module.js:449:26)
at Object.Module.extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module.load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process.tickCallback (node.js:244:9)

可以的,用这段代码

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

@Catyuki 搞出来了, 多谢~~ process.on貌似要放在代码执行之前来做??

回到顶部