Issue
I have a Java project in Eclipse Kepler and I'm trying to set up log4j. I've added it to the project using the following in pom.xml:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.1</version>
</dependency>
I have the following in my log4j config file which is named log4j2.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
log4j2.xml is located in src/main/resources which I've added to the Java Build Path Source tab in Eclipse. When I launch the project, I'm able to use the logger. But, if I rename the config file to loggerconfig-dev.xml and add this to the VM arugments in Eclipse:
-Dlog4j.configuration=loggerconfig-dev.xml
I get an error saying "No log4j2 configuration file found...". How do I get it to see the configuration file with the new name?
Solution
According to Configuring Log4j 2 - Apache Log4j 2
Log4j will inspect the "
log4j.configurationFile" system property
So, you need to change to:
-Dlog4j.configurationFile=loggerconfig-dev.xml
See also:
Answered By - Paul Vargas
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.