I'm having a very strange problem. When I log stacktraces, they seem to be originating at the line where I call the logger, rather than the line where the error occurs. This causes some serious wastes of time in terms of tracking down errors.
Using tomcat6, openjdk 6, and log4j.
Any thoughts? Thank you in advance for any help you can give.
Here are examples. Code, lines 137-142:
try {
req.getContentType().trim();
} catch (Exception e) {
log.error("DEBUG: " + e.getLocalizedMessage(), e.fillInStackTrace());
e.printStackTrace();
}
Logs:
2012-01-19 10:13:25,393 [http-8080-1] ERROR com.myservlet.servlet.Servlet2 - DEBUG: null
java.lang.NullPointerException
at com.myservlet.servlet.Servlet2.doPost(Servlet2.java:140)
at com.myservlet.servlet.Servlet2.doGet(Servlet2.java:292)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) ...
Don't do the fill in stack trace stuff, your exception should turn up fully populated.
Simply do
log.error("My message", e);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.