Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log stack traces in node.js

Tags:

Looking for a node.js package that handles stack tracing similar to how this is done in RoR:

Rails: Logging the entire stack trace of an exception

like image 618
Chris Abrams Avatar asked Mar 04 '12 01:03

Chris Abrams


2 Answers

You can get this text off of the .stack property from any Error. For instance:

try {     throw new Error(); } catch (e) {     console.log(e.stack); } 

or just new up an error for the purposes of getting the stack trace

console.log(new Error().stack) 
like image 97
kelloti Avatar answered Sep 17 '22 16:09

kelloti


there's a function for that: console.trace()

In case you don't want to log to console you can get the stack trace string value using new Error().stack

like image 36
Benja Avatar answered Sep 20 '22 16:09

Benja