Skip to content

Commit 2449866

Browse files
rozagerardoKevinGilmore
authored andcommitted
BAEL-2131 disable logging in console (eugenp#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
1 parent a42dfbc commit 2449866

21 files changed

Lines changed: 299 additions & 12 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.baeldung</groupId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<artifactId>disabling-console-jul</artifactId>
7+
8+
<parent>
9+
<groupId>org.springframework.boot</groupId>
10+
<artifactId>spring-boot-starter-parent</artifactId>
11+
<version>2.0.4.RELEASE</version>
12+
</parent>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.springframework.boot</groupId>
17+
<artifactId>spring-boot-starter-web</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-starter</artifactId>
22+
<exclusions>
23+
<exclusion>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-logging</artifactId>
26+
</exclusion>
27+
</exclusions>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.slf4j</groupId>
31+
<artifactId>jul-to-slf4j</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.slf4j</groupId>
35+
<artifactId>slf4j-simple</artifactId>
36+
</dependency>
37+
</dependencies>
38+
39+
<build>
40+
<plugins>
41+
<plugin>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-maven-plugin</artifactId>
44+
</plugin>
45+
</plugins>
46+
</build>
47+
48+
<properties>
49+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
50+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
51+
<java.version>1.8</java.version>
52+
</properties>
53+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.springbootlogging.disablingconsole.jul.properties;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class DisablingConsoleJulApp {
8+
public static void main(String[] args) {
9+
SpringApplication.run(DisablingConsoleJulApp.class, args);
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.springbootlogging.disablingconsole.jul.properties.controllers;
2+
3+
import java.time.LocalTime;
4+
import java.util.logging.Logger;
5+
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
@RestController
10+
public class DisabledConsoleRestController {
11+
12+
private static final Logger LOG = Logger.getLogger(DisabledConsoleRestController.class.getName());
13+
14+
@GetMapping("/disabled-console-jul-properties")
15+
public String logTime() {
16+
LOG.info("Current time: " + LocalTime.now());
17+
return "finished!";
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
logging.file=true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
handlers= java.util.logging.FileHandler
2+
3+
java.util.logging.FileHandler.pattern=baeldung.log
4+
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.baeldung</groupId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<artifactId>disabling-console-log4j2</artifactId>
7+
<parent>
8+
<groupId>org.springframework.boot</groupId>
9+
<artifactId>spring-boot-starter-parent</artifactId>
10+
<version>2.0.4.RELEASE</version>
11+
</parent>
12+
13+
<dependencies>
14+
<dependency>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-web</artifactId>
17+
</dependency>
18+
<dependency>
19+
<groupId>org.springframework.boot</groupId>
20+
<artifactId>spring-boot-starter</artifactId>
21+
<exclusions>
22+
<exclusion>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-logging</artifactId>
25+
</exclusion>
26+
</exclusions>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-log4j2</artifactId>
31+
</dependency>
32+
</dependencies>
33+
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-maven-plugin</artifactId>
39+
</plugin>
40+
</plugins>
41+
</build>
42+
43+
<properties>
44+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
45+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
46+
<java.version>1.8</java.version>
47+
</properties>
48+
49+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.springbootlogging.disablingconsole.log4j2.xml;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class DisablingConsoleLog4j2App {
8+
public static void main(String[] args) {
9+
SpringApplication.run(DisablingConsoleLog4j2App.class, args);
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.springbootlogging.disablingconsole.log4j2.xml.controllers;
2+
3+
import java.time.LocalTime;
4+
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
@RestController
11+
public class DisabledConsoleRestController {
12+
13+
private static final Logger LOG = LoggerFactory.getLogger(DisabledConsoleRestController.class);
14+
15+
@GetMapping("/disabled-console-log4j2-xml")
16+
public String logTime() {
17+
LOG.info("Current time: {}", LocalTime.now());
18+
return "finished!";
19+
}
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="INFO">
3+
<Appenders>
4+
<File name="MyFile" fileName="all.log" immediateFlush="true" append="false">
5+
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
6+
</File>
7+
</Appenders>
8+
<Loggers>
9+
<Root level="info">
10+
<AppenderRef ref="MyFile"/>
11+
</Root>
12+
</Loggers>
13+
</Configuration>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<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">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>com.baeldung</groupId>
5+
<artifactId>disabling-console-logging</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
</parent>
8+
<artifactId>disabling-console-logback</artifactId>
9+
</project>

0 commit comments

Comments
 (0)