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:
rozagerardo 2018-09-05 00:18:03 -03:00 committed by KevinGilmore
parent a42dfbcf12
commit 2449866727
21 changed files with 299 additions and 12 deletions

View File

@ -0,0 +1,53 @@
<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>
<version>0.0.1-SNAPSHOT</version>
<artifactId>disabling-console-jul</artifactId>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
</project>

View File

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

View File

@ -0,0 +1,19 @@
package com.baeldung.springbootlogging.disablingconsole.jul.properties.controllers;
import java.time.LocalTime;
import java.util.logging.Logger;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class DisabledConsoleRestController {
private static final Logger LOG = Logger.getLogger(DisabledConsoleRestController.class.getName());
@GetMapping("/disabled-console-jul-properties")
public String logTime() {
LOG.info("Current time: " + LocalTime.now());
return "finished!";
}
}

View File

@ -0,0 +1,4 @@
handlers= java.util.logging.FileHandler
java.util.logging.FileHandler.pattern=baeldung.log
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter

View File

@ -0,0 +1,49 @@
<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>
<version>0.0.1-SNAPSHOT</version>
<artifactId>disabling-console-log4j2</artifactId>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</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>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
</project>

View File

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

View File

@ -0,0 +1,20 @@
package com.baeldung.springbootlogging.disablingconsole.log4j2.xml.controllers;
import java.time.LocalTime;
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 DisabledConsoleRestController {
private static final Logger LOG = LoggerFactory.getLogger(DisabledConsoleRestController.class);
@GetMapping("/disabled-console-log4j2-xml")
public String logTime() {
LOG.info("Current time: {}", LocalTime.now());
return "finished!";
}
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<File name="MyFile" fileName="all.log" immediateFlush="true" append="false">
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="MyFile"/>
</Root>
</Loggers>
</Configuration>

View File

@ -0,0 +1,9 @@
<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>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>disabling-console-logging</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>disabling-console-logback</artifactId>
</project>

View File

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

View File

@ -0,0 +1,20 @@
package com.baeldung.springbootlogging.disablingconsole.logback.xml.controllers;
import java.time.LocalTime;
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 DisabledConsoleRestController {
private static final Logger LOG = LoggerFactory.getLogger(DisabledConsoleRestController.class);
@GetMapping("/disabled-console-logback-xml")
public String logTime() {
LOG.info("Current time: {}", LocalTime.now());
return "finished!";
}
}

View File

@ -0,0 +1,7 @@
logging.file=disabled-console.log
### we could potentially 'disable' console logging by setting a blank log pattern:
#logging.pattern.console=
### or disable the logs completely by setting the root logging level as 'OFF':
#logging.level.root=OFF

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
<root level="INFO">
<appender-ref ref="FILE" />
</root>
</configuration>

View File

@ -0,0 +1,21 @@
<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>
<version>0.0.1-SNAPSHOT</version>
<groupId>com.baeldung</groupId>
<artifactId>disabling-console-logging</artifactId>
<packaging>pom</packaging>
<description>Projects for Disabling Spring Boot Console Logging tutorials</description>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>spring-boot-logging-log4j2</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modules>
<module>disabling-console-logback</module>
<module>disabling-console-log4j2</module>
<module>disabling-console-jul</module>
</modules>
</project>

View File

@ -6,8 +6,8 @@
<groupId>com.baeldung</groupId>
<artifactId>spring-boot-logging-log4j2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<description>Demo project for Spring Boot Logging with Log4J2</description>
<packaging>pom</packaging>
<description>Projects for Spring Boot Logging tutorials</description>
<parent>
<artifactId>parent-boot-2</artifactId>
@ -20,16 +20,6 @@
<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>
<dependency>
@ -39,6 +29,11 @@
</dependency>
</dependencies>
<modules>
<module>spring-boot-logging-log4j2-app</module>
<module>disabling-console-logging</module>
</modules>
<build>
<plugins>
<plugin>

View File

@ -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>