In my log4j properties, I've defined a rootLogger to log everything starting with WARN to a file, so I don't have to put logger.error(...) in every catch statement (the rootLogger catches the errors itself when they are thrown). But the problem is, that errors get logged multiple times. For example, when I throw an IOException, i get these two lines:
1:
ERROR (ApplicationDispatcher.java:687) - Servlet.service() for
servlet action threw exception
java.io.IOException: dddd
(...stack trace)
2:
ERROR (StandardWrapperValve.java:253) - Servlet.service() for servlet
jsp threw exception
javax.servlet.jsp.JspException: Exception forwarding for name index: java.io.IOException: dddd
(...stack trace)
And when I use a wrong key for bean:message tag (I use
struts) the error is logged even 6 times. In short it looks like this:
ApplicationDispatcher.java:704) - Servlet.service() for servlet jsp threw exception
(InsertTag.java:922) - ServletException in '/tiles/body_search.jsp': Missing message for key "search..title"
(InsertTag.java:922) - ServletException in '/tiles/body_search.jsp': Missing message for key "search..title"
(ApplicationDispatcher.java:704) - Servlet.service() for servlet jsp threw exception
(ApplicationDispatcher.java:704) - Servlet.service() for servlet action threw exception
(StandardWrapperValve.java:253) - Servlet.service() for servlet jsp threw exception
The question is how can I assure that each error (incl. JspExceptions) will get logged only one time (with full trace)? Thanks for advice.