BAEL-2131 disable logging in console (#5103)
* * first approach dividing spring-boot-logging into modules * * first approach dividing spring-boot-logging into modules * * modularized spring-boot-logging-log4j2 module * existing example as module * created module for new examples of "disabling console output" article * * removed name from poms * removed logback-properties submodule * added comment about logback properties in logback module * fixed comment typo * removed one last name tag
This commit is contained in:
committed by
KevinGilmore
parent
a42dfbcf12
commit
2449866727
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>spring-boot-logging-log4j2-app</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<description>Demo project for Spring Boot Logging with Log4J2</description>
|
||||
|
||||
<parent>
|
||||
<artifactId>spring-boot-logging-log4j2</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</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>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -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 throguh Log4j2...";
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user