To use Log4j2, we need to use the starter spring-boot-starter-log4j2. When we use starters such as spring-boot-starter-web, we need to ensure that we exclude the dependency in spring-boot-starter-logging. The following snippet shows the details:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency>
The following snippet shows the dependencies used in the spring-boot-starter-log4j2 starter:
<dependency> ...