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

@@ -1,3 +1,2 @@
### Relevant Articles:
- [Logging in Spring Boot](http://www.baeldung.com/spring-boot-logging)
- [How to Disable Console Logging in Spring Boot](https://www.baeldung.com/spring-boot-disable-console-logging)

View File

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

View File

@@ -1,11 +0,0 @@
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

@@ -1,19 +0,0 @@
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

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

View File

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

View File

@@ -1,11 +0,0 @@
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

@@ -1,20 +0,0 @@
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

@@ -1,13 +0,0 @@
<?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

@@ -1,9 +0,0 @@
<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

@@ -1,11 +0,0 @@
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

@@ -1,20 +0,0 @@
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

@@ -1,7 +0,0 @@
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

@@ -1,8 +0,0 @@
<?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

@@ -1,19 +0,0 @@
<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>
<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

@@ -4,41 +4,58 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot-logging-log4j2</artifactId>
<packaging>pom</packaging>
<description>Projects for Spring Boot Logging tutorials</description>
<packaging>jar</packaging>
<description>Demo project for Spring Boot Logging with Log4J2</description>
<!-- this needs to use the boot parent directly in order to not inherit logback dependencies -->
<parent>
<artifactId>parent-boot-2</artifactId>
<groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2</relativePath>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.0.5.RELEASE</version>
</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-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
</dependencies>
<modules>
<module>spring-boot-logging-log4j2-app</module>
<module>disabling-console-logging</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*IntTest.java</exclude>
<exclude>**/*ManualTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<properties>
</properties>
</project>

View File

@@ -1,33 +0,0 @@
<?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>
<artifactId>spring-boot-logging-log4j2-app</artifactId>
<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>

View File

@@ -32,6 +32,6 @@ public class LoggingController {
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...";
return "Howdy! Check out the Logs to see the output printed directly through Log4j2...";
}
}