0

I am having the below simple code. I am trying to use apache-commons+log4j since spring WS expects the apache commons to be used.

But I am not getting any thing printed. Please let me know what am i missing here.

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
//Import log4j classes.

public class MyApp {

 // Define a static logger variable so that it references the
 // Logger instance named "MyApp".
 private static final Log logger = LogFactory.getLog(MyApp.class);

 public static void main(final String... args) {

     // Set up a simple configuration that logs on the console.

     logger.info("Entering application.");
     //some stuff here
     logger.trace("Exiting application.");
 }
}

commons-logging.properties:

org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4jLogger
log4j.configuration=log4j.properties

log4j.properties:

log4j.rootCategory=INFO, stdout, TRACE
log4j.logger.org.springframework.ws.client.MessageTracing.sent=TRACE
log4j.logger.org.springframework.ws.client.MessageTracing.received=TRACE
log4j.logger.org.springframework.ws.server.MessageTracing=DEBUG
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%p [%c{3}] %m%n

Additionally I am getting below error message in console. I am wondering as I have not configured anything with slf4j

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
TheCodeGladiator
  • 173
  • 3
  • 12

1 Answers1

0

Must be sure that your log4j version is compatible with the rootCategory key word beacause as i've found here it still exists just to ensure compatibility with the older versions so try to use rootLogger instead like this: log4j.rootLogger = DEBUG, stdout Other hand, you have a misplaced argument to your rootCategory log4j.rootCategory=INFO, stdout, TRACE

  • Must provide only the least severe level and all the most severe one will be printed
  • the seconde argument is the appender: you can provide more then one

see this post:StackOverFlow

Hope it helps

Community
  • 1
  • 1
jMounir
  • 495
  • 2
  • 11
  • I didn't pay attention to the error message when i wrote my answer, must add the jar slf4j-log4j12.jar to your classpath cause maybe you have slf4j api in your classpath and it contains the same package as common logging, see: http://www.slf4j.org/api/org/apache/commons/logging/package-summary.html – jMounir Mar 31 '15 at 11:30