Custom Tomcat logging class needs ServletContext

2019-09-09 17:01发布

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?

1条回答
可以哭但决不认输i
2楼-- · 2019-09-09 17:30

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.

查看更多
登录 后发表回答