Do I read you conf file to be a relative path , how about setting as fully
defined from the root  eg /var/fred/log.txt

----- Original Message -----
From: "James Adams" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, March 19, 2002 5:59 PM
Subject: Log4j initialization problem


> Hello,
>
> I am having the problem of Tomcat initializing/creating my Log4j log
> files in whatever directory that Tomcat is started from.  In other words
> if I am currently at directory /kung/foo when I issue the command
> /etc/init.d/tomcat start, then my log files will be created under
> /kung/foo instead of under the /path/to/webapp directory, which is where
> I thought that they should be created.
>
> I have the following WEB-INF/classes/log4j.properties file:
>
> --------------------
> # Set root category priority to DEBUG and its only appender to A1.
> log4j.rootCategory=DEBUG, A1
>
> # A1 is set to be a RollingFileAppender.
> log4j.appender.A1=org.apache.log4j.RollingFileAppender
>
> log4j.appender.A1.File=LogMessages-trajview.txt
> log4j.appender.A1.MaxFileSize=500KB
>
> # Keep one backup file
> log4j.appender.A1.MaxBackupIndex=2
>
> # A1 uses PatternLayout.
> log4j.appender.A1.layout=org.apache.log4j.PatternLayout
> log4j.appender.A1.layout.ConversionPattern=%5p %d (%F:%L) - %m%n
> ---------------------
>
>
> The log4j stuff is being initialized/configured by a servlet which has
> the following init() method:
>
> -------------------
>     public void init()
>     {
>         // gets the base directory to use, from the web application's
> "context"
>         String prefix = getServletContext().getRealPath("/");
>
>         // this looks in the web.xml for the initialization file
> parameter
>         // which points to log4j.properties
>         String file = getInitParameter("log4j-init-file");
>
>         // if the log4j-init-file is not set, then no point in trying
>         if (file != null)
>         {
>             // apply the configuration specified in the initialization
> file
>             PropertyConfigurator.configure(prefix + file);
>         }
>     }
> ------------------
>
>
> The above mentioned Log4j initialization servlet is being called at
> loadup time by virtue of the following entry in my web.xml:
>
> -----------------
>     <servlet>
>         <servlet-name>log4j-init</servlet-name>
>         <servlet-class>myapp.servlet.Log4jInit</servlet-class>
>         <init-param>
>             <param-name>log4j-init-file</param-name>
>             <param-value>WEB-INF/classes/log4j.properties</param-value>
>         </init-param>
>         <load-on-startup>1</load-on-startup>
>     </servlet>
> -----------------
>
>
> Because I have three separate webapps which should all have their own
> log files I would like to have the log files created in the separate
> webapp directories, or perhaps better yet in a logs subdirectory under
> each webapp directory.  For example if a webapp is under
> /var/tomcat/webappps/myapp then I would like for the log file to be
> created as /var/tomcat/webapps/myapp/LogMessages.txt or as
> /var/tomcat/webapps/myapp/logs/LogMessages.txt.  How can I get this to
> happen ?  Should I make a change to a log4j.properties entry, or perhaps
> I'm making an error in my log4j initialization servlet's init() method
> by referencing the wrong path in the getRealPath() call ?
>
> Any suggestions will be appreciated.  Thanks in advance.
>
>
> -James
>
>
> --
> To unsubscribe:   <mailto:[EMAIL PROTECTED]>
> For additional commands: <mailto:[EMAIL PROTECTED]>
> Troubles with the list: <mailto:[EMAIL PROTECTED]>
>


--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to