Skip to content

Instantly share code, notes, and snippets.

@wafe
Created March 8, 2012 10:16
Show Gist options
  • Save wafe/2000145 to your computer and use it in GitHub Desktop.
Save wafe/2000145 to your computer and use it in GitHub Desktop.
node.js uncaughtException logging using winston
var winston = require('winston'); // https://github.com/flatiron/winston
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)(),
new (winston.transports.File)({ filename : 'winston.log', timestamp: true, /*maxsize: 2000, maxFiles: 5*/ })
]
});
process.on('uncaughtException', function (err) {
logger.error('uncaughtException', { message : err.message, stack : err.stack }); // logging with MetaData
process.exit(1); // exit with failure
});
@wafe
Copy link
Author

wafe commented Mar 8, 2012

Log Result

{"message":"uncaughtException","stack":"ReferenceError: conole is not defined\n at Socket.< anonymous>(D:\nodeapps\sockettest_standalone\app.js:54:9)\n at Socket.$emit (events.js:67:17)\n at SocketNamespace.handlePacket (D:\nodeapps\sockettest_standalone\node_modules\socket.io\lib\namespace.js:335:22)\n at Manager.onClientMessage (D:\nodeapps\sockettest_standalone\node_modules\socket.io\lib\manager.js:462:38)\n at WebSocket.onMessage (D:\nodeapps\sockettest_standalone\node_modules\socket.io\lib\transport.js:387:20)\n at Parser. (D:\nodeapps\sockettest_standalone\node_modules\socket.io\lib\transports\websocket\hybi-16.js:40:10)\n at Parser.emit (events.js:67:17)\n at D:\nodeapps\sockettest_standalone\node_modules\socket.io\lib\transports\websocket\hybi-16.js:289:16\n at Parser.expectHandler (D:\nodeapps\sockettest_standalone\node_modules\socket.io\lib\transports\websocket\hybi-16.js:300:15)\n at Parser.add (D:\nodeapps\sockettest_standalone\node_modules\socket.io\lib\transports\websocket\hybi-16.js:467:24)","level":"error","timestamp":"8 Mar 19:12:19"}

@crobinson42
Copy link

Awesome gist! Thanks for posting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment