Last active
August 29, 2015 14:05
-
-
Save JulienSansot/9fcdbd9aa2dc049fb310 to your computer and use it in GitHub Desktop.
node.js global error handling + logging in LogEntries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var util = require('util'); | |
var logentries = require('node-logentries'); | |
var log = logentries.logger({ | |
token:'11111111-2222-3333-4444-555555555555' | |
}); | |
var d = require('domain').create(); | |
d.on('error', function(err){ | |
try { | |
// make sure we close down within 10 seconds | |
var killtimer = setTimeout(function() { | |
process.exit(1); | |
}, 10000); | |
// But don't keep the process open just for that! | |
killtimer.unref(); | |
console.log('crit ' + util.inspect(err, { showHidden: true})); | |
log.log("crit", util.inspect(err, { showHidden: true})); | |
} catch (er2) { | |
// oh well, not much we can do at this point. | |
console.error('Error ', er2); | |
} | |
}); | |
d.run(function(){ | |
/* | |
* | |
* DO YOUR STUFF HERE | |
* | |
* | |
*/ | |
var date = new Da_ERROR_te(); //dummy error | |
}); | |
log.on('error', function(err){ | |
console.log('log error '+err ); | |
}); | |
log.on('log',function(logline){ | |
console.log(logline) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment