Posted By:
Christopher_Koenigsberg
Posted On:
Thursday, April 24, 2003 06:41 AM
My way may not be the best way, but it works so far. I have a separate Initializer servlet, in which I only have an "init()" static method, and nothing else. In that servlet's init(), I do the log4j BasicConfigurator. I have this servlet load-on-startup in the web.xml. I never use any URL's referring to this servlet; I just want its init() to run at startup of the web application in the servlet container engine (Tomcat, maybe migrating to JBoss and/or WebLogic).
So, once the init() has Basically Configurated the log4j stuff, then in my regular Struts Action classes and ActionForms (which of course run from the regular Struts ActionServlet as usual), I can just getLogger's and log to them.
One thing I still haven't gotten clear, which I may have to modify my Initializer to fix (probably using something beyond just the BasicConfigurator, I suspect, but have no time to work on it yet), is that if I turn on debugging for my own loggers, it also turns on the flood of internal debugging from Struts including all sorts of Common Digestifier etc. crap. But if I turn off the Struts/Commons debugging, it also turns off my own debugging!
I have a convention where I getLogger(myclassname) e.g. for each of my classes I get a logger under the fully qualified name of the class (including the package prefix). So I had thought I could control debug logging levels etc. by distinguishing the package prefixes (in log4j.properties) since mine all start with "com" and Apache Struts/Commons all start with "org", but it's not working, again maybe because I need something beyond the BasicConfigurator....