Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zlt2000
microservices-platform
提交
d79141c7
microservices-platform
项目概览
zlt2000
/
microservices-platform
9 个月 前同步成功
通知
16
Star
4
Fork
3
代码
文件
提交
分支
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 搜索 >>
提交
d79141c7
编写于
3月 30, 2021
作者:
zlt2000
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化日志埋点工具类
上级
5fe72576
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
92 addition
and
2 deletion
+92
-2
zlt-commons/zlt-log-spring-boot-starter/pom.xml
zlt-commons/zlt-log-spring-boot-starter/pom.xml
+5
-0
zlt-commons/zlt-log-spring-boot-starter/src/main/java/com/central/log/monitor/PointUtil.java
...rter/src/main/java/com/central/log/monitor/PointUtil.java
+86
-1
zlt-gateway/zuul-gateway/src/main/java/com/central/gateway/filter/pre/UserInfoHeaderFilter.java
.../com/central/gateway/filter/pre/UserInfoHeaderFilter.java
+1
-1
未找到文件。
zlt-commons/zlt-log-spring-boot-starter/pom.xml
浏览文件 @
d79141c7
...
...
@@ -42,6 +42,11 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-aop
</artifactId>
</dependency>
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-web
</artifactId>
...
...
zlt-commons/zlt-log-spring-boot-starter/src/main/java/com/central/log/monitor/PointUtil.java
浏览文件 @
d79141c7
package
com.central.log.monitor
;
import
cn.hutool.core.util.ReflectUtil
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.util.ObjectUtils
;
import
java.lang.reflect.Field
;
import
java.util.Iterator
;
import
java.util.Map
;
/**
* 日志埋点工具类
*
* @author zlt
* <p>
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
@Slf4j
public
class
PointUtil
{
private
static
final
String
MSG_PATTERN
=
"{}|{}|{}"
;
private
static
final
String
PROPERTIES_SPLIT
=
"&"
;
private
static
final
String
PROPERTIES_VALUE_SPLIT
=
"="
;
private
final
PointEntry
pointEntry
;
private
PointUtil
()
{
throw
new
IllegalStateException
(
"Utility class"
);
pointEntry
=
new
PointEntry
();
}
@Setter
@Getter
private
class
PointEntry
{
String
id
;
String
type
;
Object
properties
;
}
/**
...
...
@@ -31,4 +54,66 @@ public class PointUtil {
public
static
void
debug
(
String
id
,
String
type
,
String
message
)
{
log
.
debug
(
MSG_PATTERN
,
id
,
type
,
message
);
}
public
static
PointUtil
builder
()
{
return
new
PointUtil
();
}
/**
* @param businessId 业务id/对象id
*/
public
PointUtil
id
(
Object
businessId
)
{
this
.
pointEntry
.
setId
(
String
.
valueOf
(
businessId
));
return
this
;
}
/**
* @param type 类型
*/
public
PointUtil
type
(
String
type
)
{
this
.
pointEntry
.
setType
(
type
);
return
this
;
}
/**
* @param properties 对象属性
*/
public
PointUtil
properties
(
Object
properties
)
{
this
.
pointEntry
.
setProperties
(
properties
);
return
this
;
}
private
String
getPropertiesStr
()
{
Object
properties
=
this
.
pointEntry
.
getProperties
();
StringBuilder
result
=
new
StringBuilder
();
if
(!
ObjectUtils
.
isEmpty
(
properties
))
{
//解析map
if
(
properties
instanceof
Map
)
{
Map
proMap
=
(
Map
)
properties
;
Iterator
<
Map
.
Entry
>
ite
=
proMap
.
entrySet
().
iterator
();
while
(
ite
.
hasNext
())
{
Map
.
Entry
entry
=
ite
.
next
();
if
(
result
.
length
()
>
0
)
{
result
.
append
(
PROPERTIES_SPLIT
);
}
result
.
append
(
entry
.
getKey
()).
append
(
PROPERTIES_VALUE_SPLIT
).
append
(
entry
.
getValue
());
}
}
else
{
//解析对象
Field
[]
allFields
=
ReflectUtil
.
getFields
(
properties
.
getClass
());
for
(
Field
field
:
allFields
)
{
String
fieldName
=
field
.
getName
();
Object
fieldValue
=
ReflectUtil
.
getFieldValue
(
properties
,
field
);
if
(
result
.
length
()
>
0
)
{
result
.
append
(
PROPERTIES_SPLIT
);
}
result
.
append
(
fieldName
).
append
(
PROPERTIES_VALUE_SPLIT
).
append
(
fieldValue
);
}
}
}
return
result
.
toString
();
}
public
void
build
()
{
PointUtil
.
debug
(
this
.
pointEntry
.
getId
(),
this
.
pointEntry
.
getType
(),
this
.
getPropertiesStr
());
}
}
zlt-gateway/zuul-gateway/src/main/java/com/central/gateway/filter/pre/UserInfoHeaderFilter.java
浏览文件 @
d79141c7
...
...
@@ -45,7 +45,7 @@ public class UserInfoHeaderFilter extends ZuulFilter {
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
//客户端模式只返回一个clientId
if
(
principal
instanceof
SysUser
)
{
SysUser
user
=
(
SysUser
)
authentication
.
getPrincipal
()
;
SysUser
user
=
(
SysUser
)
principal
;
ctx
.
addZuulRequestHeader
(
SecurityConstants
.
USER_ID_HEADER
,
String
.
valueOf
(
user
.
getId
()));
ctx
.
addZuulRequestHeader
(
SecurityConstants
.
USER_HEADER
,
user
.
getUsername
());
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录