You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Donaldson, John" <J1...@pge.com> on 2003/10/08 00:24:11 UTC

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
J1DE@pge.com

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org