Nitesh Nitesh - 1 month ago 12
Java Question

my Issue with log4j java.lang.ClassNotFoundException: =org.apache.log4j.RollingFileAppender

I'm trying to write a sample application using log4j and slf4j. The code is very simple in my application, I have the following code in my main class in main method

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Logger logger = LoggerFactory.getLogger("com.company.cdrs");
logger.info("testing it in the application");


I'm using the following command to run the test application

java -cp /home/nbansal/workspace_eclipse_luna/event-utils-test/target/classes:event-utils-1.1~vox~trunk.jar:json-simple-1.1.jar:slf4j-api-1.7.7.jar:slf4j-log4j12-1.7.7.jar:log4j-1.2.17.jar:log4j-1.2.13.jar -Dlog4j.configuration=file:///home/nbansal/workspace_eclipse_luna/event-utils-test/target/classes/resources/log4j.properties com.company.eventtest.EventUtilsTest


When I run the application, I keep getting the following error:

Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
log4j:ERROR Could not instantiate class [=org.apache.log4j.RollingFileAppender].
java.lang.ClassNotFoundException: =org.apache.log4j.RollingFileAppender
at java.net.URLClassLoader$1.run(URLClassLoader.java:372


I can't understand why I'm getting this error, I'm providing log4j jar file correctly on the classpath.
Here is the how my log4j.properties looks like

log4j.rootLogger=DEBUG
log4j.logger.com.company.cdrs=DEBUG, hadoop_cdr
log4j.additivity.com.company.cdrs=false
log4j.appender.hadoop_cdr==org.apache.log4j.RollingFileAppender
log4j.appender.hadoop_cdr.File=/home/nbansal/workspace_eclipse_luna/event-utils-test/cdr_events.out
log4j.appender.hadoop_cdr.ImmediateFlush=true
log4j.appender.hadoop_cdr.Threshold=debug
log4j.appender.hadoop_cdr.Append=true
log4j.appender.hadoop_cdr.layout=org.apache.log4j.PatternLayout
log4j.appender.hadoop_cdr.layout.conversionPattern=%u %m%n
log4j.appender.hadoop_cdr.DatePattern='.'yyyy-MM-dd-HH

Vel Vel
Answer

You have two equals to operator in your log4j.properties file.

log4j.appender.hadoop_cdr=org.apache.log4j.RollingFileAppender
Comments