Results 1 to 7 of 7

Thread: How to use log4j

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Location
    Québec, Canada
    Posts
    6

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    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
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3

    Default 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.

  4. #4
    Join Date
    Aug 2004
    Location
    Québec, Canada
    Posts
    6

    Default 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

  5. #5
    Join Date
    Aug 2004
    Location
    Atlanta, GA
    Posts
    129

    Default

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

  6. #6
    Join Date
    Aug 2004
    Posts
    1

    Default

    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.

  7. #7
    Join Date
    Aug 2004
    Location
    Québec, Canada
    Posts
    6

    Default 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.

Similar Threads

  1. Tomcat 5.5, Log4J, Spring
    By KnisterPeter in forum Web
    Replies: 2
    Last Post: Jul 9th, 2006, 01:17 PM
  2. Log4j, Commons Logging in JRun 4 problem
    By virgo_ct in forum Container
    Replies: 4
    Last Post: Jul 13th, 2005, 04:17 AM
  3. Replies: 4
    Last Post: Apr 6th, 2005, 12:07 PM
  4. Replies: 1
    Last Post: Dec 24th, 2004, 06:42 PM
  5. Stop Spring Logging
    By jgchristopher in forum Container
    Replies: 6
    Last Post: Dec 8th, 2004, 10:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •