Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------PROBLEM--------------
- No matter what I do log4j2 wont find the configuration file in the class path. gives this error:
- ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
- --------------PROJECT STRUCTURE--------------
- Testing
- src
- main
- java
- testing
- App
- resources
- log4j2.yml
- pom.xml
- --------------pom.xml--------------
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>testing</groupId>
- <artifactId>testingid</artifactId>
- <version>1.0-SNAPSHOT</version>
- <packaging>jar</packaging>
- <name>testingid</name>
- <url>http://maven.apache.org</url>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-api</artifactId>
- <version>2.6.2</version>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- <version>2.6.2</version>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>exec-maven-plugin</artifactId>
- <version>1.5.0</version>
- <configuration>
- <mainClass>testing.App</mainClass>
- </configuration>
- </plugin>
- </plugins>
- </build>
- </project>
- --------------App.java--------------
- package testing;
- import org.apache.logging.log4j.LogManager;
- import org.apache.logging.log4j.Logger;
- public class App
- {
- private final static Logger logger = LogManager.getLogger();
- public static void main( String[] args )
- {
- System.out.println( "Hello World!" );
- }
- }
- --------------log4j2.yml--------------(copied from some tutorial, i have also tried an xml file instead same result)
- configuration:
- name: Default
- properties:
- property:
- - name: log-path
- value: logs
- - name: archive
- value: ${log-path}/archive
- appenders:
- Console:
- PatternLayout:
- pattern: '[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n'
- name: Console-Appender
- target: SYSTEM_OUT
- File:
- PatternLayout:
- pattern: '[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n'
- fileName: ${log-path}/logfile.log
- name: File-Appender
- RollingFile:
- DefaultRolloverStrategy:
- max: '30'
- PatternLayout:
- pattern: '[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n'
- Policies:
- SizeBasedTriggeringPolicy:
- size: 1 KB
- fileName: ${log-path}/rollingfile.log
- filePattern: ${archive}/rollingfile.log.%d{yyyy-MM-dd-hh-mm}.gz
- name: RollingFile-Appender
- loggers:
- logger:
- additivity: 'false'
- appender-ref:
- - level: info
- ref: Console-Appender
- - level: error
- ref: File-Appender
- - level: debug
- ref: RollingFile-Appender
- level: debug
- name: guru.springframework.blog.log4j2json
- root:
- appender-ref:
- ref: Console-Appender
- level: debug
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement