?
Solved

location for log4j.xml

Posted on 2006-05-16
1
Medium Priority
?
745 Views
Last Modified: 2012-05-05
I am getting filenotfoundexception: log4j.xml. where do i put the log4j.xml I don't want to put it in the classpath. is there any other way. Also currently I have to put DOMConfigurator.configure("log4j.xml"); inside each method. is there a central place that I can put it in and the application will be able to access it there after.

this is how i am using log4j.xml

import org.apache.log4j.*;
import org.apache.log4j.xml.DOMConfigurator;

public class CustomerFormAction extends LookupDispatchAction{
  static Logger myLogger = Logger.getLogger(CustomerFormAction.class.getName());
  .....

public ActionForward search(ActionMapping mapping,
                               ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response)
      throws Exception {
   
    DOMConfigurator.configure("log4j.xml");
    ......

Thanks
0
Comment
Question by:muthiahmerchant
1 Comment
 
LVL 11

Accepted Solution

by:
fargo earned 750 total points
ID: 16697122
better is to use the InitServlet which initialises the log4j at the application start. Then u need not to call it anywhere else.

The location of the log4j.xml is not required to be in classpath, but then u have to keep the location configured in the application. The log4j initializer will then take the location path from the configuration and initialise it.

InitServlet is just a servlet which will have load-on-startup at application start (so we keep it to 0)

  <servlet>
  <servlet-name>InitServlet</servlet-name>
    <servlet-class>com.xx.xxx.InitServlet</servlet-class>
    <!-- Load this servlet at server startup time -->
    <load-on-startup>0</load-on-startup>
  </servlet>

  <servlet-mapping>
        <servlet-name>InitServlet</servlet-name>
        <url-pattern>/InitServlet</url-pattern>
  </servlet-mapping>


call  DOMConfigurator.configure("complete/path/to/log4j.xml"); in initservlet.

public class InitServlet extends HttpServlet
{

    /**
     * Main method which call all the init steps
     * @throws ServletException
     */
    public void init() throws ServletException
    {
      DOMConfigurator.configure("complete/path/to/log4j.xml");
    }

} // end of InitServlet

Do the error handling in the above code.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question