Results 1 to 7 of 7

Thread: log4j and CommandLineJobRunner

  1. #1
    Join Date
    Dec 2007
    Posts
    5

    Default log4j and CommandLineJobRunner

    Are there any instructions on how to configure log4j in a batch job being run using CommandLineJobRunner from a maven generated jar file?

    I wish to log to a file and to set the log level.

    I have seen an example or two spring batch applications that suggest that the log4j.properties should be placed in the resources directory together with the batch context files, but this isn't working for me.

    Cheers

  2. #2

    Default

    It does work, but you need a log4j.jar e.g. log4j-1.2.16.jar in your CLASSPATH

  3. #3
    Join Date
    Dec 2007
    Posts
    5

    Default

    log4j is included in the jar and is logging to the console, but I can't configure log4j with a properties file.

    thanks

  4. #4

    Default

    can you give some more details of your configuration ?

    • how do you generate the jar with maven ?
    • is it an all-in-one.jar ?
    • how does your log4j.property file look like?
    Last edited by michael.lange; Nov 16th, 2011 at 04:12 AM.

  5. #5
    Join Date
    Dec 2007
    Posts
    5

    Default case closed

    I should have been using org.slf4j.Logger and org.slf4j.LoggerFactory
    not
    org.apache.commons.logging.Log and org.apache.commons.logging.LogFactory

  6. #6
    Join Date
    Dec 2007
    Posts
    5

    Default

    Yesterday I found that if I logged using org.slf4j.Logger and org.slf4j.LoggerFactory, my log4j properties are used used in my application, so stuff is logged to file. That is good enough for me although spring is still logging to the console.

    I have just tracked down this article http://blog.springsource.com/2009/12...ies-in-spring/ which it referenced in spring batch in action: it explains how to setup logging with spring. I quickly tried out excluding commons-logging but got same results. I will try out Logback at some point.

    To answer your questions

    1) I use maven-jar-plugin to generate a jar with CommandLineJobRunner as the entry point. Dependencies are installed in a separate directory.
    2) log4j.properties:

    log4j.rootLogger=INFO, file
    log4j.appender.file=org.apache.log4j.RollingFileAp pender
    log4j.appender.file.MaximumFileSize=1000000
    log4j.appender.file.MaxBackupIndex=7
    log4j.appender.file.layout=org.apache.log4j.Patter nLayout
    log4j.appender.file.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} (%C{1}:%L) [%p] %m%n
    log4j.appender.file.File=logs/batch-jobs.log

  7. #7

    Default

    although spring is still logging to the console
    take a look at SLF4: Bridging Legacy, to get it working with Spring Batch, you need to make sure that commons-logging is not on the classpath

Tags for this Thread

Posting Permissions

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