No log4j2 configuration file found. Using default configuration: logging only errors to the console

前端 未结 15 1102
情深已故
情深已故 2020-12-04 22:59
$ java -Dlog4j.configuration=file:///path/to/your/log4j2.xml -jar /path/to/your/jar_file.jar

Written to the console, you get

ERROR          


        
相关标签:
15条回答
  • 2020-12-04 23:40

    Just try below steps, it will work,

    1. Keep XML file directly under below folder structure. src/main/java
    2. Make sure to save the pom.xml file in case any changes made..
    0 讨论(0)
  • 2020-12-04 23:43

    I have solve this problem by configuring the build path. Here are the steps that I followed: In eclipse.

    1. create a folder and save the logj4 file in it.
    2. Write click in the folder created and go to Build path.
    3. Click on Add folder
    4. Choose the folder created.
    5. Click ok and Apply and close.

    Now you should be able to run

    0 讨论(0)
  • 2020-12-04 23:44

    Make sure that you have put a log4j2.* file instead of a log4j.* file under .../src/main/resources folder.

    0 讨论(0)
  • 2020-12-04 23:44

    The issue solved after renaming the xml file name to log4j2.xml

    0 讨论(0)
  • 2020-12-04 23:45

    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>
    
    0 讨论(0)
  • 2020-12-04 23:46

    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>
    
    0 讨论(0)
提交回复
热议问题