Commit 8c45b8f71bcc41512fe3fd9e7c2ebe5f5fec7f25
1 parent
442b579c
动态指定logs目录为项目启动路径下logs目录
Signed-off-by: TanYibin <5491541@qq.com>
Showing
2 changed files
with
85 additions
and
13 deletions
huaheng-wms-core/src/main/java/org/jeecg/utils/CustomLogContextListener.java
0 → 100644
1 | +package org.jeecg.utils; | |
2 | + | |
3 | +import ch.qos.logback.classic.Level; | |
4 | +import ch.qos.logback.classic.Logger; | |
5 | +import ch.qos.logback.classic.LoggerContext; | |
6 | +import ch.qos.logback.classic.spi.LoggerContextListener; | |
7 | +import ch.qos.logback.core.spi.ContextAwareBase; | |
8 | +import ch.qos.logback.core.spi.LifeCycle; | |
9 | +import ch.qos.logback.core.Context; | |
10 | + | |
11 | +/** | |
12 | + * @version 1.0 | |
13 | + * @class: CustomLogContextListener | |
14 | + * @author: carlo | |
15 | + * @mail: carlo_cwh@qq.com | |
16 | + * @date: 2021/8/25 10:01 | |
17 | + * @description: 定义logback 日志监听器,指定日志文件存放目录 | |
18 | + */ | |
19 | +public class CustomLogContextListener extends ContextAwareBase implements LoggerContextListener, LifeCycle { | |
20 | + | |
21 | + /** 存储日志路径标识 */ | |
22 | + public static final String LOG_PAHT_KEY = "LOG_PATH"; | |
23 | + | |
24 | + @Override | |
25 | + public boolean isResetResistant() { | |
26 | + return false; | |
27 | + } | |
28 | + | |
29 | + @Override | |
30 | + public void onStart(LoggerContext loggerContext) { | |
31 | + | |
32 | + } | |
33 | + | |
34 | + @Override | |
35 | + public void onReset(LoggerContext loggerContext) { | |
36 | + | |
37 | + } | |
38 | + | |
39 | + @Override | |
40 | + public void onStop(LoggerContext loggerContext) { | |
41 | + | |
42 | + } | |
43 | + | |
44 | + @Override | |
45 | + public void onLevelChange(Logger logger, Level level) { | |
46 | + | |
47 | + } | |
48 | + | |
49 | + @Override | |
50 | + public void start() { | |
51 | + // "user.dir"是指用户当前工作目录 | |
52 | + String s = System.getProperty("user.dir"); | |
53 | + System.setProperty(LOG_PAHT_KEY, s); | |
54 | + Context context = getContext(); | |
55 | + context.putProperty(LOG_PAHT_KEY, s); | |
56 | + } | |
57 | + | |
58 | + @Override | |
59 | + public void stop() { | |
60 | + | |
61 | + } | |
62 | + | |
63 | + @Override | |
64 | + public boolean isStarted() { | |
65 | + return false; | |
66 | + } | |
67 | +} | |
0 | 68 | \ No newline at end of file |
... | ... |
huaheng-wms-core/src/main/resources/logback-spring.xml
1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | 2 | <configuration debug="false"> |
3 | + | |
4 | + <!-- 监听器,指定日志文件存放目录 --> | |
5 | + <contextListener class="org.jeecg.utils.CustomLogContextListener" /> | |
6 | + | |
3 | 7 | <!--定义日志文件的存储地址 --> |
4 | - <property name="LOG_HOME" value="../logs"/> | |
8 | + <property name="LOG_HOME" value="${LOG_PATH}/logs" /> | |
5 | 9 | |
6 | - <!--<property name="COLOR_PATTERN" value="%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta( %replace(%caller{1}){'\t|Caller.{1}0|\r\n', ''})- %gray(%msg%xEx%n)" />--> | |
10 | + <!--<property name="COLOR_PATTERN" value="%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta( | |
11 | + %replace(%caller{1}){'\t|Caller.{1}0|\r\n', ''})- %gray(%msg%xEx%n)" /> --> | |
7 | 12 | <!-- 控制台输出 --> |
8 | 13 | <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
9 | 14 | <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> |
10 | - <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 | |
11 | - <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n</pattern>--> | |
15 | + <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L | |
16 | + - %msg%n</pattern> --> | |
12 | 17 | <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{50}:%L) - %msg%n</pattern> |
13 | 18 | </encoder> |
14 | 19 | </appender> |
... | ... | @@ -31,7 +36,7 @@ |
31 | 36 | <!-- 生成 error html格式日志开始 --> |
32 | 37 | <appender name="HTML" class="ch.qos.logback.core.FileAppender"> |
33 | 38 | <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> |
34 | - <!--设置日志级别,过滤掉info日志,只输入error日志--> | |
39 | + <!--设置日志级别,过滤掉info日志,只输入error日志 --> | |
35 | 40 | <level>ERROR</level> |
36 | 41 | </filter> |
37 | 42 | <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> |
... | ... | @@ -61,17 +66,17 @@ |
61 | 66 | <!-- 每天生成一个html格式的日志结束 --> |
62 | 67 | |
63 | 68 | <!--myibatis log configure --> |
64 | - <logger name="com.apache.ibatis" level="TRACE"/> | |
65 | - <logger name="java.sql.Connection" level="DEBUG"/> | |
66 | - <logger name="java.sql.Statement" level="DEBUG"/> | |
67 | - <logger name="java.sql.PreparedStatement" level="DEBUG"/> | |
69 | + <logger name="com.apache.ibatis" level="TRACE" /> | |
70 | + <logger name="java.sql.Connection" level="DEBUG" /> | |
71 | + <logger name="java.sql.Statement" level="DEBUG" /> | |
72 | + <logger name="java.sql.PreparedStatement" level="DEBUG" /> | |
68 | 73 | |
69 | 74 | <!-- 日志输出级别 --> |
70 | 75 | <root level="INFO"> |
71 | - <appender-ref ref="STDOUT"/> | |
72 | - <appender-ref ref="FILE"/> | |
73 | - <appender-ref ref="HTML"/> | |
74 | - <appender-ref ref="FILE_HTML"/> | |
76 | + <appender-ref ref="STDOUT" /> | |
77 | + <appender-ref ref="FILE" /> | |
78 | + <appender-ref ref="HTML" /> | |
79 | + <appender-ref ref="FILE_HTML" /> | |
75 | 80 | </root> |
76 | 81 | |
77 | 82 | </configuration> |
... | ... |