maven
A quick guide to configuring many log4j2 configurations with different profiles (QA, Prod…). First, you need to add the log4j2 spring starter, and to exclude the logback starter (here the version is inherited from your Spring Boot BOM). <dependency> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <!-- Exclude logback (default implementation) --> <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-validation</artifactId> </dependency> You can put your log4j2-local.xml and the log4j2-prod.xml in the resource directory of your choice, in this example it will be src/main/resources/log/.
In my current project, we needed to identify each build with a version number. We decided to inject this number at compile-time, so it would be generated at each Jenkins Build with a unique build-number, allowing us to always be in a “production-ready” state. Setting up the POM You can set a default value in the properties, here I’ve added metadata information “-dev”, that is useful to distinguish different build profiles (local, Jenkins CI, etc…).