简体   繁体   中英

How to filter an exception out of tomcat 7 logging? (java util logging)

I have the following problem: Our webapp is running on tomcat 7 and I have an exception that I would like to filter from being written in the log files. The logger is defined in the logging.properties file,

handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler

followed by the directory, prefix and format.

Is there any possibility to stop tomcat from writing the exception in the file and onto the console? Because thats what happens right now. I know there are log filters for log4j, but I don't know anything for juli. The exception beeing thrown is:

org.apache.catalina.core.StandardWrapperValve invoke 
SEVERE: Servlet.service() for servlet [default] in context with path [] threw exception [javax.servlet.ServletException: 

I would be glad if anyone could point me in the direction how to get this exception out of the logs.

Ideas I had so far:

  • write a doFilter servlet, that filters the exception out before it arrives at the logger
  • modifiy the the java.util.logging library files to reject this certain exception
  • route all tomcat logs through log4j and filter there

JULI supports custom filters by extending java.util.logging.Filter .

  1. Write a custom filter to block the exception. Unit test it so you know it works.
  2. Place the filter code in the Tomcat classpath .
  3. Modify the logging.properties to install custom filter on the FileHandler and ConsoleHandler .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM