Configure Log4J2 for Spring Boot
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package com.javadevjournal;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class Log4J2Controller {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(Log4J2Controller.class);
|
||||
|
||||
@GetMapping(value = "/greeting")
|
||||
public String greeting() {
|
||||
|
||||
LOG.debug("Debugging log in our greeting method");
|
||||
LOG.info("Info log in our greeting method");
|
||||
LOG.warn("Warning log in our greeting method");
|
||||
LOG.error("Error in our greeting method");
|
||||
return "Hello!!!";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.javadevjournal;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringBootLog4J2ExampleApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringBootLog4J2ExampleApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
# This is another way to configure Log4J2 for your Spring Boot application. #
|
||||
#status = error
|
||||
#name = Log4j2Sample
|
||||
|
||||
#appenders = console
|
||||
|
||||
#appender.console.type = Console
|
||||
#appender.console.name = STDOUT
|
||||
#appender.console.layout.type = PatternLayout
|
||||
#appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} - %msg%n
|
||||
|
||||
#rootLogger.level = warn
|
||||
#rootLogger.appenderRefs = stdout
|
||||
#rootLogger.appenderRef.stdout.ref = STDOUT
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN" monitorInterval="30">
|
||||
<Properties>
|
||||
<Property name="PID">????</Property>
|
||||
<Property name="LOG_PATTERN">%clr{%d{yyyy-MM-dd HH:mm:ss.SSS}}{faint} %clr{%5p} %clr{${sys:PID}}{magenta} %clr{---}{faint} %clr{[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n%xwEx</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT" follow="true">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Logger name="com.javadevjournal" level="debug" additivity="false">
|
||||
<AppenderRef ref="Console" />
|
||||
</Logger>
|
||||
<Root level="info">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.javadevjournal;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class SpringBootLog4J2ExampleApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user