fix boot logging modules

This commit is contained in:
Loredana Crusoveanu
2018-10-14 23:40:39 +03:00
parent e51b8261c7
commit c882fa6e54
25 changed files with 65 additions and 64 deletions

View File

@@ -0,0 +1,37 @@
package com.baeldung.springbootlogging;
import org.apache.logging.log4j.LogManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class LoggingController {
private final static Logger logger = LoggerFactory.getLogger(LoggingController.class);
@GetMapping("/")
public String index() {
logger.trace("A TRACE Message");
logger.debug("A DEBUG Message");
logger.info("An INFO Message");
logger.warn("A WARN Message");
logger.error("An ERROR Message");
return "Howdy! Check out the Logs to see the output...";
}
private static final org.apache.logging.log4j.Logger loggerNative = LogManager.getLogger(LoggingController.class);
@GetMapping("/native")
public String nativeLogging() {
loggerNative.trace("This TRACE message has been printed by Log4j2 without passing through SLF4J");
loggerNative.debug("This DEBUG message has been printed by Log4j2 without passing through SLF4J");
loggerNative.info("This INFO message has been printed by Log4j2 without passing through SLF4J");
loggerNative.warn("This WARN message been printed by Log4j2 without passing through SLF4J");
loggerNative.error("This ERROR message been printed by Log4j2 without passing through SLF4J");
loggerNative.fatal("This FATAL message been printed by Log4j2 without passing through SLF4J");
return "Howdy! Check out the Logs to see the output printed directly through Log4j2...";
}
}

View File

@@ -0,0 +1,12 @@
package com.baeldung.springbootlogging;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringBootLoggingApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootLoggingApplication.class, args);
}
}

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout
pattern="%style{%d{ISO8601}}{black} %highlight{%-5level }[%style{%t}{bright,blue}] %style{%C{1.}}{bright,yellow}: %msg%n%throwable" />
</Console>
<RollingFile name="RollingFile"
fileName="./logs/spring-boot-logger-log4j2.log"
filePattern="./logs/$${date:yyyy-MM}/spring-boot-logger-log4j2-%d{-dd-MMMM-yyyy}-%i.log.gz">
<PatternLayout>
<pattern>%d %p %C{1.} [%t] %m%n</pattern>
</PatternLayout>
<Policies>
<!-- rollover on startup, daily and when the file reaches
10 MegaBytes -->
<OnStartupTriggeringPolicy />
<SizeBasedTriggeringPolicy
size="10 MB" />
<TimeBasedTriggeringPolicy />
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<!-- LOG everything at INFO level -->
<Root level="info">
<AppenderRef ref="Console" />
<AppenderRef ref="RollingFile" />
</Root>
<!-- LOG "com.baeldung*" at TRACE level -->
<Logger name="com.baeldung" level="trace"></Logger>
</Loggers>
</Configuration>

View File

@@ -0,0 +1,17 @@
package org.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.springbootlogging.SpringBootLoggingApplication;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SpringBootLoggingApplication.class)
public class SpringContextIntegrationTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}