Reputation: 47
I have included all the necessary log4j jar files and I don't understand why I'm still getting this error.
package in.gstzen.einvoice;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
public class Log4jExample {
private static Logger logger = LogManager.getLogger(Log4jExample.class);
public static void main(String[] args) throws Exception {
System.out.println("Hello World!\n");
logger.debug("Log4jExample: A Sample Debug Message");
logger.info("Log4jExample: A Sample Info Message");
logger.warn("Log4jExample: A Sample Warn Message");
logger.error("Log4jExample: A Sample Error Message");
logger.fatal("Log4jExample: A Sample Fatal Message");
System.out.println("Completed...");
}
}
Upvotes: 1
Views: 14431
Reputation: 1149
This looks like a conflict between log4j versions 1 and 2. Your class is importing version 1 classes, but the error message is in response to the spring framework not finding the jar files for version 2 classes. You want to use one version or the other.
Version 1 is going to have classes with packages org.apache.log4j.x
.
The jar will be called log4j-1.x.x
Version 2 is going to have classes with packages like org.apache.logging.log4j.x
.
The jars will be named log4j-core-2.x.x
and an the implementation like log4j-slf4j18-impl-2.x.x
.
See this migration helper: https://logging.apache.org/log4j/2.x/manual/migration.html
Note: If your classpath includes both the version 1 and version 2 jars resolution of the actual classes used can be somewhat random (and problematic).
Upvotes: 2