File tree Expand file tree Collapse file tree 6 files changed +82
-0
lines changed
java/com/baeldung/customloglevel Expand file tree Collapse file tree 6 files changed +82
-0
lines changed Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ spring.application.name =customloglevel
Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change 14
14
</parent >
15
15
16
16
<modules >
17
+ <module >customloglevel</module >
17
18
<module >flogger</module >
18
19
<module >log4j</module >
19
20
<module >log4j2</module >
You can’t perform that action at this time.
0 commit comments