Reputation: 36643
I'm trying to use log4j to print messages from a standalone Java app to the console in Eclipse, but it's not printing anything. Here's the code:
Declaration:
static Logger logger = LoggerFactory.getLogger(AnalyticsBackupUtil.class);
Print statements:
public static void main(String args[]) {
String log4jConfigFile = System.getProperty("user.dir") + File.separator + "log4j.properties";
PropertyConfigurator.configure(log4jConfigFile);
logger.debug("this is a debug log message");
logger.info("this is a information log message");
logger.warn("this is a warning log message");
logger.error("this is an error log message");
...
properties file:
log4j.rootLogger=DEBUG, Appender1,Appender2
log4j.appender.Appender1=org.apache.log4j.ConsoleAppender
log4j.appender.Appender1.layout=org.apache.log4j.PatternLayout
log4j.appender.Appender1.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n
log4j.appender.Appender2=org.apache.log4j.FileAppender
log4j.appender.Appender2.File=applog.txt
log4j.appender.Appender2.layout=org.apache.log4j.PatternLayout
log4j.appender.Appender2.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n
Maven:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
Any idea what the problem might be?
Upvotes: 0
Views: 35
Reputation: 16045
Log4j 1.x does not have a method LoggerFactory.getLogger
. You are probably using org.slf4j.Logger
and org.slf4j.LoggerFactory
.
If this is intentional (using a logging API like SLF4j allows to easily change the backend), you need to add the slf4j-log4j12
binding to the classpath.
Upvotes: 1