$ java -Dlog4j.configuration=file:///path/to/your/log4j2.xml -jar /path/to/your/jar_file.jar
Written to the console, you get
ERROR
Just try below steps, it will work,
src/main/java
pom.xml
file in case any changes made..I have solve this problem by configuring the build path. Here are the steps that I followed: In eclipse.
Now you should be able to run
Make sure that you have put a log4j2.*
file instead of a log4j.*
file under .../src/main/resources
folder.
The issue solved after renaming the xml file name to log4j2.xml
I am working on TestNG Maven project, This worked for me by adding <resources>
tag in pom.xml
, this happens to be the path of my custom configuration file log4j2.xml
.
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<resources>
<resource>
<directory>src/main/java/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
I use hive jdbc in a java maven project and have the same issues.
My method is to add a log4j2.xml file under src/main/java/resources
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyClassName {
private static final Logger LOG = LoggerFactory.getLogger(MyClassName.class);
}
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>
<Logger name="<your_package_name>.<your_class_name>" level="debug">
<AppenderRef ref="Console"/>
</Logger>
<Root level="WARN">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>