Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Tomcat Users »

How to pass context FileLogger to another class?

Donaldson, John

2003-10-07


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
J1DE@(protected)

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)


©2008 junlu.com - Jax Systems, LLC, U.S.A.