Skip to content

Commit 47d7124

Browse files
Merge pull request #18693 from programenth/swagger-tag
BAEL-6471 | adding custom log level code
2 parents 7014cb6 + f3117bf commit 47d7124

File tree

6 files changed

+82
-0
lines changed

6 files changed

+82
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>3.5.3</version>
9+
</parent>
10+
<artifactId>customloglevel</artifactId>
11+
<name>customloglevel</name>
12+
<description>Demo project for Different Log level</description>
13+
<dependencies>
14+
<dependency>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-web</artifactId>
17+
</dependency>
18+
</dependencies>
19+
</project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.customloglevel;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class CustomloglevelApplication {
8+
public static void main(String[] args) {
9+
SpringApplication.run(CustomloglevelApplication.class, args);
10+
}
11+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.baeldung.customloglevel;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
@RestController
9+
public class LogController {
10+
11+
private static final Logger logger = LoggerFactory.getLogger(LogController.class);
12+
13+
@GetMapping("/log")
14+
public String generateLogs() {
15+
logger.trace("This is a TRACE message from controller.");
16+
logger.debug("This is a DEBUG message from controller.");
17+
logger.info("This is an INFO message from controller.");
18+
logger.warn("This is a WARN message from controller.");
19+
logger.error("This is an ERROR message from controller.");
20+
return "Logs generated!";
21+
}
22+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spring.application.name=customloglevel
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<property name="LOGS_HOME" value="./logs"/>
4+
<property name="CONSOLE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"/>
5+
<property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"/>
6+
<property name="FILE_NAME" value="my-spring-app"/>
7+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
8+
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
9+
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
10+
</encoder>
11+
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
12+
<level>INFO</level>
13+
</filter>
14+
</appender>
15+
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
16+
<file>${LOGS_HOME}/${FILE_NAME}.log</file>
17+
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
18+
<Pattern>${FILE_LOG_PATTERN}</Pattern>
19+
</encoder>
20+
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
21+
<level>DEBUG</level>
22+
</filter>
23+
</appender>
24+
<root level="DEBUG">
25+
<appender-ref ref="CONSOLE"/>
26+
<appender-ref ref="FILE"/>
27+
</root>
28+
</configuration>

logging-modules/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
</parent>
1515

1616
<modules>
17+
<module>customloglevel</module>
1718
<module>flogger</module>
1819
<module>log4j</module>
1920
<module>log4j2</module>

0 commit comments

Comments
 (0)