Announcement Announcement Module
Collapse
No announcement yet.
How to use log4j Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use log4j

    I want to configure spring logging using log4j.

    I want to send all Spring logging to a file and we already use log4j in our application.

    How do you do such a thing?



    thank you.

  • #2
    petclinic sample from Spring Distribution uses Log4jConfigListener to configure logging.

    you may review the following files
    - web.xml: for Log4jConfigListener configuration (it is however disable in the sample)
    - log4j.properties: shows an example of logging to a file

    Comment


    • #3
      Sample of a log4J file

      Or put a log4j.xml like this to your classpath :

      Code:
      <?xml version="1.0" encoding="UTF-8" ?>
      <!DOCTYPE log4j&#58;configuration SYSTEM "log4j.dtd">
      
      <log4j&#58;configuration xmlns&#58;log4j="http&#58;//jakarta.apache.org/log4j/">
          <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
              <layout class="org.apache.log4j.PatternLayout">
                  <param name="ConversionPattern"
                      value="%p - %C&#123;1&#125;.%M&#40;%L&#41; | %m%n"/>
              </layout>
          </appender>
      
          <logger name="org.apache">
              <level value="WARN"/>
          </logger>
      
          <logger name="servletunit.struts">
              <level value="INFO"/>
          </logger>
          
          <logger name="net.sf.hibernate">
              <level value="WARN"/>
          </logger>
      
          <logger name="com.opensymphony.oscache">
              <level value="WARN"/>
          </logger>
      
          <logger name="org.springframework">
              <level value="INFO"/>
          </logger>
          
          <root>
              <level value="ERROR"/>
              <appender-ref ref="CONSOLE"/>
          </root>
      </log4j&#58;configuration>
      In this example, u trace all the "info" trace of springframework

      Hope it will help u,

      Fabien.

      Comment


      • #4
        Solution to integration between Websphere and JCL

        I found a solution to my problem.

        The problem is cause by to use of commons-logging and Websphere. Websphere use JCL internally and an application have to override websphere's configuration.

        Here a link to a complete solution to the problem.


        http://www-1.ibm.com/support/docview...id=swg27004610

        Comment


        • #5
          Excellent timing. I am having a similar problem and was going to post it on Monday. Thanks!

          Comment


          • #6
            Thanks for the link to the IBM site. I have tried both methods but neither worked for me.

            Which method worked for you?
            Option 2 adding org.apache.commons.logging.LogFactory in the META-INF/services directory or
            Option 3 commons-logging.properties with classloader set to PARENT_LAST.

            Comment


            • #7
              Option 2 worked for me

              > Which method worked for you?
              > Option 2 adding org.apache.commons.logging.LogFactory in the META-INF/services directory or
              > Option 3 commons-logging.properties with classloader set to PARENT_LAST.

              I tried both of these solution and only Option 2 works for me. And you have to put the file org.apache.commons.logging.LogFactory and the services directory in a WEB application.

              At first I tried to use an ejb application with no success. In your web application it works like a charm and your application (EAR) will use the JCL setting. Not only the web module as documented in the ibm paper.

              Comment

              Working...
              X