Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7049103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:58:20+00:00 2026-05-28T02:58:20+00:00

I am trying to put log4j in a web application in Tomcat 7. I

  • 0

I am trying to put log4j in a web application in Tomcat 7.
I have the log4j library in the WEB-INF\lib of my web application.
I have the following log4j.xml under WEB-INF\classes

<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

      <!-- Log output to Console -->
      <appender name="console" class="org.apache.log4j.ConsoleAppender"> 
        <param name="Target" value="System.out"/> 
        <layout class="org.apache.log4j.PatternLayout"> 
          <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/> 
        </layout> 
      </appender>  

      <appender name="rolling" class="org.apache.log4j.RollingFileAppender"> 
        <param name="file" value="myLogfile.log"/>    
        <param name="append" value="true" />
        <param name="encoding" value="UTF-8" />  
        <layout class="org.apache.log4j.PatternLayout"> 
          <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/> 
        </layout> 
      </appender> 

      <!-- Log to both Console and File -->
      <root> 
        <priority value ="debug" /> 
        <appender-ref ref="console" /> 
        <appender-ref ref="rolling" />
      </root>  
</log4j:configuration>

I log e.g. in a servlet or filter that I know are loading but I can not see the output log anywhere.

E.g.

Logger log = Logger.getLogger(MyFilter.class);

and in doFilter I log i.e. log.debug("logging information); log.error("logging information);

I can not see the output in the Tomcat console as a result of the console appender and I don’t see the myLogfile.log created either.

I am not sure where is this file supposed to be created.

I see only System.out statements from servlets and filters.

What am I doing wrong here?

UPDATE:
I have in the classpath xercesImpl.jar and jaxb-impl.jar. Could this cause an issue?

I noticed the following exception I missed earlier in Tomcat console:

log4j:WARN Error during default initialization
java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2823)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1160)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1655)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1533)
at org.apache.xerces.parsers.AbstractDOMParser.startDocument(Unknown
Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startDocument(Unknown
Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl.startEntity(Unknown
Source)
at org.apache.xerces.impl.XMLVersionDetector.startDocumentParsing(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at org.apache.log4j.xml.DOMConfigurator$2.parse(DOMConfigurator.java:767)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:866)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:773)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:483)
at org.apache.log4j.LogManager.(LogManager.java:127)
at org.apache.log4j.Logger.getLogger(Logger.java:117)
at com.test.MyFilter.(MyFilter.java:26)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:125)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:256)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:382)
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:103)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4624)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5281)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:866)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:842)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1095)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1617)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662) Caused by: java.lang.ClassNotFoundException: org.w3c.dom.ElementTraversal
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1688)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1533)
… 48 more

log4j:WARN No appenders could be found for logger (com.test.MyFilter).
log4j:WARN Please initialize the log4j system properly. log4j:WARN See
http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:58:20+00:00Added an answer on May 28, 2026 at 2:58 am

    Probably is only here, but you are missing the closing </log4j:configuration>

    And for the file you can write this:

    <param name="file" value="/usr/logs/myLogfile.log"/>
    

    or

    <param name="file" value="c:/logs/myLogfile.log"/>
    

    How are you logging in your servlet classes? Put an example of the import and the sentences

    I guess you are doing something like this, isnt?:

    import org.apache.log4j.Logger;
    
    private Logger log = Logger.getLogger(name);
    log.debug("Mensaje de debug");
    

    UPDATE:

    The problem is a missing dependency in the class loader when trying to parse the Log4j XML, not a problem in the Log4j configuration.
    The log shows that org/w3c/dom/ElementTraversal is missing. Having xercesImpl.jar already, the xml-apis.jar is needed

    As stated here http://xerces.apache.org/xerces2-j/install.html the old xerces.jar contained all classes in one jar, but new distribution of xerces divides it in xercesImpl.jar and xml-apis.jar

    Quoted:

    xerces.jar is no longer available in the main distribution. You can still download this jar from deprecated distribution. xerces.jar is a Jar file that contains all the parser class files (i.e., it contains the intersection of the contents of xercesImpl.jar and xml-apis.jar).

    To use another XML parser just remove xercesImpl.jar and add another implementation library. The problem was only the use of xercesimpl.jar without xml-apis.jar

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to put my log4j.xml file in WEB-INF/conf directory where I have many
I'm trying to write a web application using Spring MVC. I have a configuration
I'm trying to get log4j application (webapp) logging working in a Tomcat 6 app.
I'm trying to put in an exception in my web.config so that one page
I'm trying to put into XML-file some data. Here is the code: @Test public
I am trying to put form into help mode in Delphi 2010. I have
I am trying to put an offline Openstreetmap map into my Java Application. I
I trying to put my Mac's data in order. I have many rc-files at
I trying to put the text of a JLabel under its icon (centered) at
I'm trying to put some plain text in the iPhone Pasteboard. The following code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.