I have to use a custom logger for Tomcat. Extending java.util.logging.Handler
I implemented a bridge to the custom logger. It gets instanciated via WEB-INF/classes/logging.properties
.
But it needs to beconfigured by a property file from the war. So I need the ServletContext to do servletContext.getResourceAsStream(iniFileName)
. Since the custom Logger is created by the java logging mechanism, I am not able to get the ServletContext from a Servlet constructor or via dependency injection.
How do I get a ServletContext before any Servlet was created?
Create a ServletContextListener and instantiate your handler programmatically. If you must instantiate it via loggin.property , you can still look for your handler instances via the logger API and configure it then.