Results 1 to 7 of 7

Thread: Stop Spring Logging

  1. #1

    Default Stop Spring Logging

    I have a stand alone application using spring core. I am also using log4j. The structure of the application is a simple shell script, and lib dir with all of my required jar files and a jar of my application.

    When I start up my application, the logging for my application, does what I want it to do and uses my log4j properties file. The spring classes however, continue to log to stdout using a totally different pattern.

    I know I am missing something easy here but I just can't find it. My log4j configuration is below.

    log4j.rootLogger= INFO, A2
    log4j.debug=true

    # logs to a file
    log4j.appender.A2=org.apache.log4j.RollingFileAppe nder
    log4j.appender.A2.layout=org.apache.log4j.PatternL ayout
    log4j.appender.A2.layout.ConversionPattern=%d{MM/dd/yyyy HH:mm:ss} %-5p [Thread: %t] [Class: %c{2}] [Method: %M] [Line: %L]- "%m"%n
    log4j.appender.A2.append.log=false
    log4j.appender.A2.File=/home/ppl/logs/PPLdataprocessor.log


    log4j.logger.org.springframework=FATAL


    Debug output when application starts...

    log4j: Parsing for [root] with value=[INFO, A2].
    log4j: Level token is [INFO].
    log4j: Category root set to INFO
    log4j: Parsing appender named "A2".
    log4j: Parsing layout options for "A2".
    log4j: Setting property [conversionPattern] to [%d{MM/dd/yyyy HH:mm:ss} %-5p [Thread: %t] [Class: %c{2}] [Method: %M] [Line: %L]- "%m"%n].
    log4j: End of parsing for "A2".
    log4j: Setting property [file] to [/home/ppl/logs/PPLdataprocessor.log].
    log4j: setFile called: /home/ppl/logs/PPLdataprocessor.log, true
    log4j: setFile ended
    log4j: Parsed "A2" options.
    log4j: Parsing for [org.springframework] with value=[FATAL].
    log4j: Level token is [FATAL].
    log4j: Category org.springframework set to FATAL
    log4j: Handling log4j.additivity.org.springframework=[null]
    log4j: Finished configuring.


    Thanks,
    John C

  2. #2
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Spring does not use Log4J but Apache commons-logging. This is but a wrapper which can be instructed to log to console, Log4J, Java-Logging or whatever you want.
    So you need to configure commons-logging to use Log4J. Then your logging should work.

    See http://jakarta.apache.org/commons/lo...#Configuration for details.

    Regards,
    Andreas

  3. #3

    Default Using Commons Logging made things worse

    okay, I changed over my code to commons logging. Now, Springs code and my code are being logged to the Console, taking it over.

    The logging that I want to happen, log4j configured to go to a file is also working.

    I thought Commons logging was supposed to notice that I am using log4j and use that as the Logger?

    --John

  4. #4
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    John,

    You can find full details of the algorithm used by Commons Logging to resolve a logging implementation at http://jakarta.apache.org/commons/logging/guide.html.

    You are right is saying that without any configuration, CL will look for log4j first. You should have log4j classes available in the classpath in order for CL to use it. Plus you need to have a valid log4j.properties file in the root of the classpath otherwise log4j will dump an error to stdout.

    Rob

  5. #5

    Default Followed the CL guide.

    I followed that guide when I moved over to CL.

    I have log4j in my class path, it starts and logs just fine. I even have log4j debugging turned on to try and see what is going on. (see below for out put to console on application startup).

    This data is output to the console and then the spring logging begins.

    log4j: Level token is [INFO].
    log4j: Category root set to INFO
    log4j: Parsing appender named "A2".
    log4j: Parsing layout options for "A2".
    log4j: Setting property [conversionPattern] to [%d{MM/dd/yyyy HH:mm:ss} %-5p [Thread: %t] [Class: %c{2}] [Method: %M] [Line: %L]- "%m"%n].
    log4j: End of parsing for "A2".
    log4j: Setting property [file] to [/home/ppl/logs/PPLdataprocessor.log].
    log4j: setFile called: /home/ppl/logs/PPLdataprocessor.log, true
    log4j: setFile ended
    log4j: Parsed "A2" options.
    log4j: Parsing for [org.springframework] with value=[FATAL].
    log4j: Level token is [FATAL].
    log4j: Category org.springframework set to FATAL
    log4j: Handling log4j.additivity.org.springframework=[null]
    log4j: Finished configuring.
    Dec 6, 2004 10:38:17 PM org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [dps_beans.xml]
    Dec 6, 2004 10:38:17 PM org.springframework.beans.factory.config.PropertyR esourceConfigurer postProcessBeanFactory
    INFO: Loading properties from file [/gpfs3/home/ppl/dps/config/build.properties]
    Dec 6, 2004 10:38:18 PM org.springframework.beans.factory.support.Abstract BeanFactory getBean
    INFO: Creating shared instance of singleton bean 'pplingester'
    Dec 6, 2004 10:38:18 PM org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory autowireConstructor
    ....


    Notice that log4j loads and configures itself and then the Spring logging starts in the console. Not sure what this line is?
    log4j: Handling log4j.additivity.org.springframework=[null].
    I even tried to set that to false. but didn't change the debug output.


    --John

  6. #6
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    John,

    From the format of those messages, it looks like CL is using JDK 1.4 logging rather than log4j. Have you tried forcing CL to use the log4j logger by setting the following system property:

    org.apache.commons.logging.Log=org.apache.commons. logging.impl.Log4JLogger?

    Rob

  7. #7

    Default I feel like a dope :)

    I recently took over this project so that is my excuse

    After setting that property, my app wouldn't start, throwing a class not found exception. After looking more closely at what libs the app is using I noticed two things.
    1. The libraries are extremely outdated.
    2. commons-logging-api.jar was being used and not commons-logging.jar

    I downloaded the latest and put the commons-logging in place and everything works fine without the system property.

    Lesson learned - Always update your dependencies when taking over a project.

    Thanks again for you help and patience.

    --John

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. Replies: 14
    Last Post: Apr 25th, 2008, 05:01 AM
  3. changing spring logging level
    By mavisakal in forum Container
    Replies: 6
    Last Post: Apr 18th, 2006, 09:01 PM
  4. Replies: 29
    Last Post: Apr 12th, 2005, 05:24 PM
  5. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM

Posting Permissions

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