Let's say my node.js app is running. If there is an error (I mean ALL errors. Not just the web error. If it goes to Err out, it counts) , how can I call a function to send an email to me?
Basically, before I want it to write to err.out, I want an email sent to me.
I'm using node.js and express.
Edit: I know how to send an email. The question I want to know is how to intercept the error. You know how when there's an error, it logs to out.log? Well, right now, I'm tail -f out.log, monitoring for errors. I can't sit at home all day doing this. I want errors emailed to me anytime it pops up in out.log.
I want all errors emailed to me. (Not just Express errors). If it's logged, I want that error emailed.
Let's say my node.js app is running. If there is an error (I mean ALL errors. Not just the web error. If it goes to Err out, it counts) , how can I call a function to send an email to me?
Basically, before I want it to write to err.out, I want an email sent to me.
I'm using node.js and express.
Edit: I know how to send an email. The question I want to know is how to intercept the error. You know how when there's an error, it logs to out.log? Well, right now, I'm tail -f out.log, monitoring for errors. I can't sit at home all day doing this. I want errors emailed to me anytime it pops up in out.log.
I want all errors emailed to me. (Not just Express errors). If it's logged, I want that error emailed.
Share Improve this question edited Sep 8, 2011 at 8:40 TIMEX asked Aug 26, 2011 at 12:14 TIMEXTIMEX 272k367 gold badges801 silver badges1.1k bronze badges2 Answers
Reset to default 15 +500You could replace nodes global console.error() function with one implementation sending emails:
console.error = function(msg) {
// send email
// ...
// additionaly log
process.stderr.write(msg);
};
Then every call in every library made to console.error() would call your specific implementation send out mails ;)
Since all log entries are stored in a limited number of log files, in stead of trying to intercept all possible error events, why not just set up a file change monitor and have the new lines mailed to you? That way you can also schedule intervals with summary log entries of the last hour/day/... which will be a lot easier to go through, pared to opening separate mails.