Custom Tomcat logging class needs ServletContext

不打扰是莪最后的温柔 提交于 2019-12-12 01:29:53

问题


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:


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.



来源:https://stackoverflow.com/questions/15235324/custom-tomcat-logging-class-needs-servletcontext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!