Skip to content

Commit b30af8d

Browse files
author
YunaiV
committed
增加 log 相关的目录。还未完成
1 parent 7cd44ab commit b30af8d

File tree

5 files changed

+64
-66
lines changed

5 files changed

+64
-66
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
package cn.iocoder.springboot.lab37.loggingdemo;
22

3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
35
import org.springframework.boot.SpringApplication;
46
import org.springframework.boot.autoconfigure.SpringBootApplication;
57

68
@SpringBootApplication
79
public class Application {
810

11+
private static Logger logger = LoggerFactory.getLogger(Application.class);
12+
913
public static void main(String[] args) {
1014
SpringApplication.run(Application.class, args);
15+
16+
// 打印日志
17+
logger.debug("just do it");
1118
}
1219

1320
}

lab-37/lab-37-logging-log4j2/src/main/java/cn/iocoder/springboot/lab37/loggingdemo/controller/DemoController.java

-30
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
11
spring:
22
application:
33
name: demo-application # 应用名
4-
5-
logging:
6-
# 日志文件配置
7-
file:
8-
# path: /Users/yunai/logs/ # 日志文件路径。
9-
name: /Users/yunai/logs/${spring.application.name}.log # 日志文件名。
10-
max-history: 7 # 日志文件要保留的归档的最大天数。默认为 7 天。
11-
max-size: 10MB # 日志文件的最大大小。默认为 10MB 。
12-
13-
# 日志级别
14-
level:
15-
cn:
16-
iocoder:
17-
springboot:
18-
lab37:
19-
loggingdemo:
20-
controller: DEBUG
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="WARN">
3+
<Properties>
4+
<Property name="PID">????</Property>
5+
<Property name="LOG_EXCEPTION_CONVERSION_WORD">%xwEx</Property>
6+
<Property name="LOG_LEVEL_PATTERN">%5p</Property>
7+
<Property name="LOG_DATEFORMAT_PATTERN">yyyy-MM-dd HH:mm:ss.SSS</Property>
8+
<Property name="FILE_LOG_BASE_PATH">/Users/yunai/logs</Property>
9+
<Property name="APPLICATION_NAME">demo-application</Property>
10+
11+
<!-- 控制台的日志格式 -->
12+
<Property name="CONSOLE_LOG_PATTERN">%clr{%d{${LOG_DATEFORMAT_PATTERN}}}{faint} %clr{${LOG_LEVEL_PATTERN}} %clr{${sys:PID}}{magenta} %clr{---}{faint} %clr{[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}</Property>
13+
<!-- 日志文件的日志格式 -->
14+
<Property name="FILE_LOG_PATTERN">%d{${LOG_DATEFORMAT_PATTERN}} ${LOG_LEVEL_PATTERN} ${sys:PID} --- [%t] %-40.40c{1.} : %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}</Property>
15+
</Properties>
16+
17+
<Appenders>
18+
<!-- 控制台的 Appender -->
19+
<Console name="Console" target="SYSTEM_OUT" follow="true">
20+
<PatternLayout pattern="${sys:CONSOLE_LOG_PATTERN}" />
21+
</Console>
22+
23+
<!-- 日志文件的 Appender -->
24+
<RollingFile name="File" fileName="${FILE_LOG_BASE_PATH}/${sys:APPLICATION_NAME}"
25+
filePattern="${FILE_LOG_BASE_PATH}/${sys:APPLICATION_NAME}-%d{yyyy-MM-dd-HH}-%i.log.gz">
26+
<!-- 日志的格式化 -->
27+
<PatternLayout>
28+
<Pattern>${sys:FILE_LOG_PATTERN}</Pattern>
29+
</PatternLayout>
30+
<!--滚动策略,基于时间 + 大小的分包策略 -->
31+
<Policies>
32+
<SizeBasedTriggeringPolicy size="10 MB" />
33+
</Policies>
34+
</RollingFile>
35+
</Appenders>
36+
37+
<Loggers>
38+
<!-- 常用组件的 Logger 的日志级别 -->
39+
<Logger name="org.apache.catalina.startup.DigesterFactory" level="error" />
40+
<Logger name="org.apache.catalina.util.LifecycleBase" level="error" />
41+
<Logger name="org.apache.coyote.http11.Http11NioProtocol" level="warn" />
42+
<logger name="org.apache.sshd.common.util.SecurityUtils" level="warn"/>
43+
<Logger name="org.apache.tomcat.util.net.NioSelectorPool" level="warn" />
44+
<Logger name="org.eclipse.jetty.util.component.AbstractLifeCycle" level="error" />
45+
<Logger name="org.hibernate.validator.internal.util.Version" level="warn" />
46+
<logger name="org.springframework.boot.actuate.endpoint.jmx" level="warn"/>
47+
48+
<!-- 自定义的 Logger 的日志级别 -->
49+
<logger name="cn.iocoder.springboot.lab37.loggingdemo" level="debug"/>
50+
51+
<!-- 设置 Appender ,同时 ROOT 的日志级别为 INFO -->
52+
<Root level="info">
53+
<AppenderRef ref="Console" />
54+
<AppenderRef ref="File" />
55+
</Root>
56+
</Loggers>
57+
</Configuration>
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
11
spring:
22
application:
33
name: demo-application # 应用名
4-
5-
logging:
6-
# 日志文件配置
7-
file:
8-
# path: /Users/yunai/logs/ # 日志文件路径。
9-
name: /Users/yunai/logs/${spring.application.name}.log # 日志文件名。
10-
max-history: 7 # 日志文件要保留的归档的最大天数。默认为 7 天。
11-
max-size: 10MB # 日志文件的最大大小。默认为 10MB 。
12-
13-
# 日志级别
14-
level:
15-
cn:
16-
iocoder:
17-
springboot:
18-
lab37:
19-
loggingdemo:
20-
controller: DEBUG
21-
22-

0 commit comments

Comments
 (0)