Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
JAVA小学生-王铁柱
eladmin
提交
ec716f99
E
eladmin
项目概览
JAVA小学生-王铁柱
/
eladmin
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
eladmin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ec716f99
编写于
6月 03, 2019
作者:
Z
zhengjie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化 druid配置,日志异步保存
上级
3696c2fb
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
22 addition
and
13 deletion
+22
-13
eladmin-logging/src/main/java/me/zhengjie/aspect/LogAspect.java
...n-logging/src/main/java/me/zhengjie/aspect/LogAspect.java
+14
-2
eladmin-logging/src/main/java/me/zhengjie/service/LogService.java
...logging/src/main/java/me/zhengjie/service/LogService.java
+3
-1
eladmin-logging/src/main/java/me/zhengjie/service/impl/LogServiceImpl.java
...rc/main/java/me/zhengjie/service/impl/LogServiceImpl.java
+2
-10
eladmin-system/src/main/resources/config/application-dev.yml
eladmin-system/src/main/resources/config/application-dev.yml
+2
-0
eladmin-system/src/main/resources/config/application-prod.yml
...min-system/src/main/resources/config/application-prod.yml
+1
-0
未找到文件。
eladmin-logging/src/main/java/me/zhengjie/aspect/LogAspect.java
浏览文件 @
ec716f99
...
...
@@ -4,6 +4,8 @@ import lombok.extern.slf4j.Slf4j;
import
me.zhengjie.domain.Log
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.service.LogService
;
import
me.zhengjie.utils.RequestHolder
;
import
me.zhengjie.utils.SecurityUtils
;
import
me.zhengjie.utils.ThrowableUtil
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.ProceedingJoinPoint
;
...
...
@@ -14,6 +16,8 @@ import org.aspectj.lang.annotation.Pointcut;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.http.HttpServletRequest
;
/**
* @author jie
* @date 2018-11-24
...
...
@@ -47,7 +51,7 @@ public class LogAspect {
currentTime
=
System
.
currentTimeMillis
();
result
=
joinPoint
.
proceed
();
Log
log
=
new
Log
(
"INFO"
,
System
.
currentTimeMillis
()
-
currentTime
);
logService
.
save
(
joinPoint
,
log
);
logService
.
save
(
getUsername
(),
RequestHolder
.
getHttpServletRequest
(),
joinPoint
,
log
);
return
result
;
}
...
...
@@ -61,6 +65,14 @@ public class LogAspect {
public
void
logAfterThrowing
(
JoinPoint
joinPoint
,
Throwable
e
)
{
Log
log
=
new
Log
(
"ERROR"
,
System
.
currentTimeMillis
()
-
currentTime
);
log
.
setExceptionDetail
(
ThrowableUtil
.
getStackTrace
(
e
));
logService
.
save
((
ProceedingJoinPoint
)
joinPoint
,
log
);
logService
.
save
(
getUsername
(),
RequestHolder
.
getHttpServletRequest
(),
(
ProceedingJoinPoint
)
joinPoint
,
log
);
}
public
String
getUsername
()
{
try
{
return
SecurityUtils
.
getUsername
();
}
catch
(
Exception
e
){
return
""
;
}
}
}
eladmin-logging/src/main/java/me/zhengjie/service/LogService.java
浏览文件 @
ec716f99
...
...
@@ -4,6 +4,8 @@ import me.zhengjie.domain.Log;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.springframework.scheduling.annotation.Async
;
import
javax.servlet.http.HttpServletRequest
;
/**
* @author jie
* @date 2018-11-24
...
...
@@ -16,7 +18,7 @@ public interface LogService {
* @param log
*/
@Async
void
save
(
ProceedingJoinPoint
joinPoint
,
Log
log
);
void
save
(
String
username
,
HttpServletRequest
request
,
ProceedingJoinPoint
joinPoint
,
Log
log
);
/**
* 查询异常详情
...
...
eladmin-logging/src/main/java/me/zhengjie/service/impl/LogServiceImpl.java
浏览文件 @
ec716f99
...
...
@@ -5,7 +5,6 @@ import cn.hutool.json.JSONObject;
import
me.zhengjie.domain.Log
;
import
me.zhengjie.repository.LogRepository
;
import
me.zhengjie.service.LogService
;
import
me.zhengjie.utils.RequestHolder
;
import
me.zhengjie.utils.SecurityUtils
;
import
me.zhengjie.utils.StringUtils
;
import
org.aspectj.lang.ProceedingJoinPoint
;
...
...
@@ -32,10 +31,8 @@ public class LogServiceImpl implements LogService {
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
save
(
ProceedingJoinPoint
joinPoint
,
Log
log
){
public
void
save
(
String
username
,
HttpServletRequest
request
,
ProceedingJoinPoint
joinPoint
,
Log
log
){
// 获取request
HttpServletRequest
request
=
RequestHolder
.
getHttpServletRequest
();
MethodSignature
signature
=
(
MethodSignature
)
joinPoint
.
getSignature
();
Method
method
=
signature
.
getMethod
();
me
.
zhengjie
.
aop
.
log
.
Log
aopLog
=
method
.
getAnnotation
(
me
.
zhengjie
.
aop
.
log
.
Log
.
class
);
...
...
@@ -53,9 +50,6 @@ public class LogServiceImpl implements LogService {
Object
[]
argValues
=
joinPoint
.
getArgs
();
//参数名称
String
[]
argNames
=
((
MethodSignature
)
joinPoint
.
getSignature
()).
getParameterNames
();
// 用户名
String
username
=
""
;
if
(
argValues
!=
null
){
for
(
int
i
=
0
;
i
<
argValues
.
length
;
i
++)
{
params
+=
" "
+
argNames
[
i
]
+
": "
+
argValues
[
i
];
...
...
@@ -65,9 +59,7 @@ public class LogServiceImpl implements LogService {
// 获取IP地址
log
.
setRequestIp
(
StringUtils
.
getIP
(
request
));
if
(!
LOGINPATH
.
equals
(
signature
.
getName
())){
username
=
SecurityUtils
.
getUsername
();
}
else
{
if
(
LOGINPATH
.
equals
(
signature
.
getName
())){
try
{
JSONObject
jsonObject
=
new
JSONObject
(
argValues
[
0
]);
username
=
jsonObject
.
get
(
"username"
).
toString
();
...
...
eladmin-system/src/main/resources/config/application-dev.yml
浏览文件 @
ec716f99
...
...
@@ -23,6 +23,8 @@ spring:
test-while-idle
:
true
test-on-borrow
:
false
test-on-return
:
false
validation-query
:
select
1
# 配置监控统计拦截的filters
filters
:
stat
stat-view-servlet
:
...
...
eladmin-system/src/main/resources/config/application-prod.yml
浏览文件 @
ec716f99
...
...
@@ -23,6 +23,7 @@ spring:
test-while-idle
:
true
test-on-borrow
:
false
test-on-return
:
false
validation-query
:
select
1
# 配置监控统计拦截的filters
filters
:
stat
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录