Java Error Handling – Best Practices for Monitoring Unhandled Application Errors

error handlingexception handlingexceptionsjava

I'm working with multiple software with varying ways of monitoring for errors. When I make software, I usually send email with the stack trace to admins(usually me). Some customer software is monitored by a team who check that a particular batch run was successfull. Other software might not have any monitoring at all(someone will call when things go wrong horribly).

Sending emails is good, except when things start going wrong, my mail gets filled fast. Also I don't want to solve the same problem in code for every software. Is there some relatively cheap and low maintenance software or practice to handle this. I want it to be cheap/low maintenance because usually I work alone or in teams of 5 or smaller. For example it would be great if errors would be aggregated so I don't get 10 000 emails when something unexpected happens…

For clarification: By unhandled errors I mean Exceptions that were unhandled by application code that were propagated to Tomcat or Jboss. I don't need help with how to catch those errors. I need help with what to do with them.

Is there any cloud application that I could send my errors to? Or some simple server to install? Or some library that can handle errors using configuration files. I use Java if that is any help.

Best Answer

You have options...


  • Implement you own log4j/logback appender (WriteYourOwnAppender) that "does what you want"

  • Use an SMTPAppender that accumulates logging events in one or more fixed-size buffers and sends the contents of the appropriate buffer in an email after a user-specified event occurs

  • Use a DBAppender that inserts logging events into three database tables in a format independent of the Java programming language

  • Use a SocketAppender that is designed to log to a remote entity by transmitting serialized ILoggingEvent instances over the wire. You would have to take care of the receiving side of course.

  • Use a SyslogAppender a that sends a small message to a syslog receiver. The receiver is commonly called syslog daemon or syslog server. Logback can send messages to a remote syslog daemon. In short, it will send all your exceptions (errors, warnings, depending how you configure it in logback.properties/xml) to an OS syslog.

  • Or, there is Bug4J, that you can either use via Bug4jAppender or through the Bug4J agent. Both will write into a Bug4J server which has a web gui that looks a bit nicer than ChainSaw (which, btw, is another way..):

enter image description here