Java – How much logging should I do at production for SQLExcpetions

exceptionsjavalogging

I'm writing a small database-centric application in Java Swing that will be used internally in a small company. I haven't much experience with developing production-level applications.

I don't use an ORM, just a few simple methods that run SQL queries with Java JDBC. On every method that access the database I use a try-catch statement for SQLException and IOException. Should I do any logging here? In case I should, how much should I log? Please give me examples of good practice in this case.

Best Answer

Two main things in production system are:

  1. Don't blow up the logs with information that is not interesting
  2. Allow raising the log level for troubleshooting purpose.

Use some kind of a logging infrastructure. If the exception can occur during the normal operation, report it in debug level. If it is a real problem, report it in error level. Either way you will have a way to troubleshoot the system by raising the log level.

Also - when you report an exception always make sure the the entire stack trace + inner exceptions are printed.