Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
喜欢杯子
microservices-platform
提交
09476d98
microservices-platform
项目概览
喜欢杯子
/
microservices-platform
与 Fork 源项目一致
Fork自
whatyn / microservices-platform
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
microservices-platform
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
09476d98
编写于
8月 14, 2019
作者:
zlt2000
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加分布式日志链路追踪
上级
2cd4cce9
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
166 addition
and
6 deletion
+166
-6
zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/config/DefaultWebMvcConfig.java
...n/java/com/central/common/config/DefaultWebMvcConfig.java
+6
-0
zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/constant/CommonConstant.java
...main/java/com/central/common/constant/CommonConstant.java
+10
-0
zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/interceptor/TraceInterceptor.java
...java/com/central/common/interceptor/TraceInterceptor.java
+26
-0
zlt-commons/zlt-log-spring-boot-starter/pom.xml
zlt-commons/zlt-log-spring-boot-starter/pom.xml
+9
-0
zlt-commons/zlt-log-spring-boot-starter/src/main/java/com/central/log/config/LogAutoConfigure.java
...rc/main/java/com/central/log/config/LogAutoConfigure.java
+15
-0
zlt-commons/zlt-log-spring-boot-starter/src/main/java/com/central/log/properties/TraceProperties.java
...main/java/com/central/log/properties/TraceProperties.java
+23
-0
zlt-commons/zlt-log-spring-boot-starter/src/main/resources/META-INF/spring.factories
...boot-starter/src/main/resources/META-INF/spring.factories
+2
-0
zlt-commons/zlt-log-spring-boot-starter/src/main/resources/logback-spring.xml
...spring-boot-starter/src/main/resources/logback-spring.xml
+2
-2
zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/config/FeignInterceptorConfig.java
.../central/common/ribbon/config/FeignInterceptorConfig.java
+7
-0
zlt-config/src/main/resources/application-dev.properties
zlt-config/src/main/resources/application-dev.properties
+4
-1
zlt-config/src/main/resources/application-prod.properties
zlt-config/src/main/resources/application-prod.properties
+4
-1
zlt-config/src/main/resources/application-test.properties
zlt-config/src/main/resources/application-test.properties
+4
-1
zlt-gateway/zuul-gateway/src/main/java/com/central/gateway/filter/pre/TraceFilter.java
...main/java/com/central/gateway/filter/pre/TraceFilter.java
+51
-0
zlt-web/back-web/src/main/resources/static/pages/log/sysLog.html
.../back-web/src/main/resources/static/pages/log/sysLog.html
+3
-1
未找到文件。
zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/config/DefaultWebMvcConfig.java
浏览文件 @
09476d98
...
...
@@ -2,6 +2,7 @@ package com.central.common.config;
import
com.central.common.feign.UserService
;
import
com.central.common.interceptor.TenantInterceptor
;
import
com.central.common.interceptor.TraceInterceptor
;
import
com.central.common.resolver.ClientArgumentResolver
;
import
com.central.common.resolver.TokenArgumentResolver
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -26,7 +27,12 @@ public class DefaultWebMvcConfig extends WebMvcConfigurationSupport {
*/
@Override
protected
void
addInterceptors
(
InterceptorRegistry
registry
)
{
//租户拦截器
registry
.
addInterceptor
(
new
TenantInterceptor
()).
addPathPatterns
(
"/**"
);
//日志链路追踪拦截器
registry
.
addInterceptor
(
new
TraceInterceptor
()).
addPathPatterns
(
"/**"
);
super
.
addInterceptors
(
registry
);
}
...
...
zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/constant/CommonConstant.java
浏览文件 @
09476d98
...
...
@@ -102,4 +102,14 @@ public interface CommonConstant {
* 租户id参数
*/
String
TENANT_ID_PARAM
=
"tenantId"
;
/**
* 日志链路追踪id信息头
*/
String
TRACE_ID_HEADER
=
"x-traceId-header"
;
/**
* 日志链路追踪id日志标志
*/
String
LOG_TRACE_ID
=
"traceId"
;
}
zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/interceptor/TraceInterceptor.java
0 → 100644
浏览文件 @
09476d98
package
com.central.common.interceptor
;
import
cn.hutool.core.util.StrUtil
;
import
com.central.common.constant.CommonConstant
;
import
org.slf4j.MDC
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
/**
* 日志链路追踪拦截器
*
* @author zlt
* @date 2019/8/13
*/
public
class
TraceInterceptor
implements
HandlerInterceptor
{
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
{
String
traceId
=
request
.
getHeader
(
CommonConstant
.
TRACE_ID_HEADER
);
if
(
StrUtil
.
isNotEmpty
(
traceId
))
{
MDC
.
put
(
CommonConstant
.
LOG_TRACE_ID
,
traceId
);
}
return
true
;
}
}
zlt-commons/zlt-log-spring-boot-starter/pom.xml
浏览文件 @
09476d98
...
...
@@ -17,5 +17,14 @@
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-context
</artifactId>
</dependency>
</dependencies>
</project>
zlt-commons/zlt-log-spring-boot-starter/src/main/java/com/central/log/config/LogAutoConfigure.java
0 → 100644
浏览文件 @
09476d98
package
com.central.log.config
;
import
com.central.log.properties.TraceProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
/**
* 日志自动配置
*
* @author zlt
* @date 2019/8/13
*/
@EnableConfigurationProperties
(
TraceProperties
.
class
)
public
class
LogAutoConfigure
{
}
zlt-commons/zlt-log-spring-boot-starter/src/main/java/com/central/log/properties/TraceProperties.java
0 → 100644
浏览文件 @
09476d98
package
com.central.log.properties
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.cloud.context.config.annotation.RefreshScope
;
/**
* 日志链路追踪配置
*
* @author zlt
* @date 2019/8/13
*/
@Setter
@Getter
@ConfigurationProperties
(
prefix
=
"zlt.trace"
)
@RefreshScope
public
class
TraceProperties
{
/**
* 是否开启日志链路追踪
*/
private
Boolean
enable
=
false
;
}
zlt-commons/zlt-log-spring-boot-starter/src/main/resources/META-INF/spring.factories
0 → 100644
浏览文件 @
09476d98
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.central.log.config.LogAutoConfigure
zlt-commons/zlt-log-spring-boot-starter/src/main/resources/logback-spring.xml
浏览文件 @
09476d98
...
...
@@ -17,8 +17,8 @@
<!-- 彩色日志格式 -->
<property
name=
"CONSOLE_LOG_PATTERN"
value=
"[${APP_NAME}:${ServerIP}:${ServerPort}] %clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%level){blue} %clr(${PID}){magenta} %clr([%thread]){orange} %clr(%logger){cyan} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"
/>
<property
name=
"CONSOLE_LOG_PATTERN_NO_COLOR"
value=
"[${APP_NAME}:${ServerIP}:${ServerPort}] %d{yyyy-MM-dd HH:mm:ss.SSS} %level ${PID} [%thread] %logger %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"
/>
value=
"[${APP_NAME}:${ServerIP}:${ServerPort}] %clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%level){blue} %clr(${PID}){magenta} %clr([%
X{traceId}]){yellow} %clr([%
thread]){orange} %clr(%logger){cyan} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"
/>
<property
name=
"CONSOLE_LOG_PATTERN_NO_COLOR"
value=
"[${APP_NAME}:${ServerIP}:${ServerPort}] %d{yyyy-MM-dd HH:mm:ss.SSS} %level ${PID} [%
X{traceId}] [%
thread] %logger %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"
/>
<!-- 控制台日志 -->
<appender
name=
"StdoutAppender"
class=
"ch.qos.logback.core.ConsoleAppender"
>
...
...
zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/config/FeignInterceptorConfig.java
浏览文件 @
09476d98
...
...
@@ -5,6 +5,7 @@ import com.central.common.constant.CommonConstant;
import
com.central.common.constant.SecurityConstants
;
import
com.central.common.utils.TenantContextHolder
;
import
feign.RequestInterceptor
;
import
org.slf4j.MDC
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
...
...
@@ -63,6 +64,12 @@ public class FeignInterceptorConfig {
if
(
StrUtil
.
isNotEmpty
(
tenant
))
{
template
.
header
(
SecurityConstants
.
TENANT_HEADER
,
tenant
);
}
//传递日志traceId
String
traceId
=
MDC
.
get
(
CommonConstant
.
LOG_TRACE_ID
);
if
(
StrUtil
.
isNotEmpty
(
traceId
))
{
template
.
header
(
CommonConstant
.
TRACE_ID_HEADER
,
traceId
);
}
};
return
requestInterceptor
;
}
...
...
zlt-config/src/main/resources/application-dev.properties
浏览文件 @
09476d98
...
...
@@ -18,4 +18,7 @@ zlt.sentinel.dashboard=192.168.28.130:6999
##### fastDFS配置
zlt.fdfs.web-url
=
192.168.28.130
zlt.fdfs.trackerList
=
${zlt.fdfs.web-url}:22122
\ No newline at end of file
zlt.fdfs.trackerList
=
${zlt.fdfs.web-url}:22122
##### 日志链路追踪
zlt.trace.enable
=
true
\ No newline at end of file
zlt-config/src/main/resources/application-prod.properties
浏览文件 @
09476d98
...
...
@@ -18,4 +18,7 @@ zlt.sentinel.dashboard=192.168.28.130:6999
##### fastDFS配置
zlt.fdfs.web-url
=
192.168.28.130
zlt.fdfs.trackerList
=
${zlt.fdfs.web-url}:22122
\ No newline at end of file
zlt.fdfs.trackerList
=
${zlt.fdfs.web-url}:22122
##### 日志链路追踪
zlt.trace.enable
=
true
\ No newline at end of file
zlt-config/src/main/resources/application-test.properties
浏览文件 @
09476d98
...
...
@@ -18,4 +18,7 @@ zlt.sentinel.dashboard=192.168.28.130:6999
##### fastDFS配置
zlt.fdfs.web-url
=
192.168.28.130
zlt.fdfs.trackerList
=
${zlt.fdfs.web-url}:22122
\ No newline at end of file
zlt.fdfs.trackerList
=
${zlt.fdfs.web-url}:22122
##### 日志链路追踪
zlt.trace.enable
=
true
\ No newline at end of file
zlt-gateway/zuul-gateway/src/main/java/com/central/gateway/filter/pre/TraceFilter.java
0 → 100644
浏览文件 @
09476d98
package
com.central.gateway.filter.pre
;
import
cn.hutool.core.util.IdUtil
;
import
com.central.common.constant.CommonConstant
;
import
com.central.log.properties.TraceProperties
;
import
com.netflix.zuul.ZuulFilter
;
import
com.netflix.zuul.context.RequestContext
;
import
org.slf4j.MDC
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cloud.netflix.zuul.filters.support.FilterConstants
;
import
org.springframework.stereotype.Component
;
import
static
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
support
.
FilterConstants
.
FORM_BODY_WRAPPER_FILTER_ORDER
;
/**
* 生成日志链路追踪id,并传入header中
*
* @author zlt
* @date 2019/8/13
*/
@Component
public
class
TraceFilter
extends
ZuulFilter
{
@Autowired
private
TraceProperties
traceProperties
;
@Override
public
String
filterType
()
{
return
FilterConstants
.
PRE_TYPE
;
}
@Override
public
int
filterOrder
()
{
return
FORM_BODY_WRAPPER_FILTER_ORDER
-
1
;
}
@Override
public
boolean
shouldFilter
()
{
//根据配置控制是否开启过滤器
return
traceProperties
.
getEnable
();
}
@Override
public
Object
run
()
{
//链路追踪id
String
traceId
=
IdUtil
.
fastSimpleUUID
();
MDC
.
put
(
CommonConstant
.
LOG_TRACE_ID
,
traceId
);
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
ctx
.
addZuulRequestHeader
(
CommonConstant
.
TRACE_ID_HEADER
,
traceId
);
return
null
;
}
}
zlt-web/back-web/src/main/resources/static/pages/log/sysLog.html
浏览文件 @
09476d98
...
...
@@ -15,6 +15,7 @@
<option
value=
"logLevel"
>
日志级别
</option>
<option
value=
"appName"
>
应用名
</option>
<option
value=
"classname"
>
类名
</option>
<option
value=
"traceId"
>
链路追踪id
</option>
</select>
 
<input
id=
"sysLog-search-value"
class=
"layui-input search-input"
style=
"width: 300px"
type=
"text"
placeholder=
"输入关键字"
/>
 
<button
id=
"sysLog-btn-search"
class=
"layui-btn icon-btn"
><i
class=
"layui-icon"
>

</i>
搜索
</button>
...
...
@@ -50,7 +51,8 @@
{
field
:
'
serverIp
'
,
sort
:
true
,
title
:
'
服务ip
'
,
width
:
130
},
{
field
:
'
serverPort
'
,
sort
:
true
,
title
:
'
服务端口
'
,
width
:
100
},
{
field
:
'
threadName
'
,
sort
:
true
,
title
:
'
线程名
'
,
width
:
150
},
{
field
:
'
classname
'
,
sort
:
true
,
title
:
'
类名
'
,
width
:
250
}
{
field
:
'
classname
'
,
sort
:
true
,
title
:
'
类名
'
,
width
:
250
},
{
field
:
'
traceId
'
,
sort
:
true
,
title
:
'
链路追踪id
'
,
width
:
200
}
]]
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录