Howdy, You can't, by design of the servlet specification (separation of concerns).
You can achieve this in a round-about way by using system.out from your class and adding swallowOutput=true to your context definition in server.xml. Or you can use a real logging framework. Yoav Shapira Millennium ChemInformatics >-----Original Message----- >From: Donaldson, John [mailto:[EMAIL PROTECTED] >Sent: Tuesday, October 07, 2003 6:24 PM >To: Tomcat Users List >Subject: How to pass context FileLogger to another class? > >Hi Jakartites and Jakartettes, > >I would like Myclass to be able to log to the same file as MyServlet.Log(); > >My Servlet instantiates a class called Myclass. I want to pass to Myclass >the Filelogger that is defined in the <context /> section of >$CATALINA_HOME/conf/server.xml > >(eg. w/in MyServlet > > Me = new Myclass(); > Me.setFileLogger( unknown beasty from MyServlet should go here ); > >How do I get a reference to the same FileLogger that >MyServlet.Log("logstring", verbositylevel) uses? > >Here is my current <context /> section: > > <Context path="" docBase="PVCalc" swallowOutput="true"> > <Logger className="org.apache.catalina.logger.FileLogger" >prefix="PVCalc." suffix=".log" timestamp="true" > directory="logs" verbosity="3"/> > </Context> > > >The best I can figure out so far is to modify the server.xml to read: > > <Context path="" docBase="PVCalc" swallowOutput="false"> > <Logger className="org.apache.catalina.logger.FileLogger" >prefix="PVCalc." suffix=".log" timestamp="true" > directory="logs" verbosity="3"/> > <Parameter name="MyLoggerprefix" value="PVCalc." /> > <Parameter name="MyLoggersuffix" value=".log" /> > </Context> > >And then declare a FileLogger w/in MyServlet that (I hope) will actually >match the one that MyServlet.Log() uses w/ the above context params. This >is a little sloppy I think since the context params have to match the ><Logger /> param. It would be easier if I could just get the reference >from MyServlet w/out declaring > "org.apache.catalina.logger.FileLogger MyLogger = new >org.apache.catalina.logger.FileLogger(); " > >Also I'm not sure this will actually work. Doesn't the logfile that >MyServlet.Log("logstring") uses change w/ time? I think I've read that the >file name changes w/ each new day?? If so I'm not even sure declaring a >FileLogger that matches w/ the standard log will even work. > >So does anyone know how to get a reference to the standard logger that >MyServlet.Log() uses so that I can pass it to other classes? > >Thanks in advance, > >-John Donaldson >[EMAIL PROTECTED] > >--------------------------------------------------------------------- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
