I have a spring boot project, this is how I use the logger:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
class MyController{
private static final Logger log = LogManager.getLogger(MyController.class);
public void do(){
log.error("test");
}
}
and src/main/resources/log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="-- %msg%n --" />
</Console>
</Appenders>
<Loggers>
<Root level="debug" additivity="false">
<AppenderRef ref="console" />
</Root>
</Loggers>
</Configuration>
this is how I see it in the console:
2019-09-10 11:04:08.818 ERROR 21680 --- [nio-8081-exec-2] com.ey.web.MyController : testtestBLI
How do I force log4j2 to use my xml file?
GRADLE FILE:
// hot deploy config https://stackoverflow.com/a/52070831/982234
plugins {
id 'org.springframework.boot' version '2.1.5.RELEASE'
id 'java'
id 'io.spring.dependency-management' version '1.0.1.RELEASE'
}
apply plugin: 'io.spring.dependency-management'
apply plugin: 'idea'
group = 'com.tt'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
sourceSets.main.java.srcDirs += "${buildDir}/generated"
compileJava {
options.annotationProcessorGeneratedSourcesDirectory = file("${buildDir}/generated")
}
dependencyManagement {
imports {
mavenBom 'org.apache.logging.log4j:log4j-bom:2.12.1'
}
}
configurations.all {
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
compile group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: '2.3.6.RELEASE'
compile 'io.jsonwebtoken:jjwt-api:0.10.5'
runtime 'io.jsonwebtoken:jjwt-impl:0.10.5'
runtime 'io.jsonwebtoken:jjwt-jackson:0.10.5'
compile group: 'com.pipl.api', name: 'piplapis', version: '5.0.11'
compile project('system')
compile 'org.apache.httpcomponents:httpclient:4.5'
compile("org.springframework.boot:spring-boot-devtools")
compile "org.springframework.boot:spring-boot-starter-data-jpa:2.0.5.RELEASE"
compile "mysql:mysql-connector-java:5.1.47"
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.4.4.Final'
annotationProcessor("javax.xml.bind:jaxb-api")
annotationProcessor("org.hibernate:hibernate-jpamodelgen")
compile group: 'org.jboss.logging', name: 'jboss-logging', version: '3.4.1.Final'
compile 'com.google.cloud:google-cloud-storage:1.89.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.12.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.12.1'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
}