questionersam
questionersam

Reputation: 1125

log4j:WARN No appenders could be found

I have this scala application which is very simple . All that it does is initializes a logger and does a logger.info("Hello"). I have a log4j.properties file in the class path that has the following settings

# Root logger option
log4j.rootLogger=INFO, stdout

# Direct log messages to stdout
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=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

However, when I try to run the application. I get the error log4j:WARN No appenders could be found for logger (app.TestApp$). log4j:WARN Please initialize the log4j system properly.

What am I missing ? However, I get the logs printed out if I have hadoop-core.jar in the classpath (yeah there is a log4j inside it as well)

Upvotes: 2

Views: 2784

Answers (2)

rxg
rxg

Reputation: 3982

Your log4J configuration file isn't in the classpath, even if you think it is. The easiest way to solve this problem is to add -Dlog4j.debug to the VM parameters, then Log4J will trace the algorithm it is using to find its configuration:

scala -cp {yourclasspath} -Dlog4j.debug {yourscalaentrypoint}

Unfortunately @Jens' answer won't help you when you're running a Scala program since Scala doesn't use the standard Java system property to store its classpath. When you need to print out the classpath used for the Scala program you should use something like this technique.

Upvotes: 7

Jens Schauder
Jens Schauder

Reputation: 81940

Sounds like your properties file isn't found on the classpath. Print out the classpath (System property java.class.path) to verify what is going on.

Upvotes: 1

Related Questions