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

  • 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
    It does work, but you need a log4j.jar e.g. log4j-1.2.16.jar in your CLASSPATH

    Comment


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

      thanks

      Comment


      • #4
        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, 04:12 AM.

        Comment


        • #5
          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

          Comment


          • #6
            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

            Comment


            • #7
              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

              Comment

              Working...
              X