Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
2d19ad49
Commit
2d19ad49
authored
Jun 03, 2019
by
zhengjie
Browse files
异步日志
parent
ec716f99
Changes
3
Show whitespace changes
Inline
Side-by-side
eladmin-logging/src/main/java/me/zhengjie/aspect/LogAspect.java
View file @
2d19ad49
...
...
@@ -6,6 +6,7 @@ import me.zhengjie.exception.BadRequestException;
import
me.zhengjie.service.LogService
;
import
me.zhengjie.utils.RequestHolder
;
import
me.zhengjie.utils.SecurityUtils
;
import
me.zhengjie.utils.StringUtils
;
import
me.zhengjie.utils.ThrowableUtil
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.ProceedingJoinPoint
;
...
...
@@ -51,7 +52,7 @@ public class LogAspect {
currentTime
=
System
.
currentTimeMillis
();
result
=
joinPoint
.
proceed
();
Log
log
=
new
Log
(
"INFO"
,
System
.
currentTimeMillis
()
-
currentTime
);
logService
.
save
(
getUsername
(),
RequestHolder
.
getHttpServletRequest
(),
joinPoint
,
log
);
logService
.
save
(
getUsername
(),
StringUtils
.
getIP
(
RequestHolder
.
getHttpServletRequest
()
)
,
joinPoint
,
log
);
return
result
;
}
...
...
@@ -65,7 +66,7 @@ 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
(
getUsername
(),
RequestHolder
.
getHttpServletRequest
(),
(
ProceedingJoinPoint
)
joinPoint
,
log
);
logService
.
save
(
getUsername
(),
StringUtils
.
getIP
(
RequestHolder
.
getHttpServletRequest
()
)
,
(
ProceedingJoinPoint
)
joinPoint
,
log
);
}
public
String
getUsername
()
{
...
...
eladmin-logging/src/main/java/me/zhengjie/service/LogService.java
View file @
2d19ad49
...
...
@@ -18,7 +18,7 @@ public interface LogService {
* @param log
*/
@Async
void
save
(
String
username
,
HttpServletRequest
request
,
ProceedingJoinPoint
joinPoint
,
Log
log
);
void
save
(
String
username
,
String
ip
,
ProceedingJoinPoint
joinPoint
,
Log
log
);
/**
* 查询异常详情
...
...
eladmin-logging/src/main/java/me/zhengjie/service/impl/LogServiceImpl.java
View file @
2d19ad49
...
...
@@ -5,15 +5,12 @@ import cn.hutool.json.JSONObject;
import
me.zhengjie.domain.Log
;
import
me.zhengjie.repository.LogRepository
;
import
me.zhengjie.service.LogService
;
import
me.zhengjie.utils.SecurityUtils
;
import
me.zhengjie.utils.StringUtils
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.servlet.http.HttpServletRequest
;
import
java.lang.reflect.Method
;
/**
...
...
@@ -31,7 +28,7 @@ public class LogServiceImpl implements LogService {
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
save
(
String
username
,
HttpServletRequest
request
,
ProceedingJoinPoint
joinPoint
,
Log
log
){
public
void
save
(
String
username
,
String
ip
,
ProceedingJoinPoint
joinPoint
,
Log
log
){
MethodSignature
signature
=
(
MethodSignature
)
joinPoint
.
getSignature
();
Method
method
=
signature
.
getMethod
();
...
...
@@ -57,7 +54,7 @@ public class LogServiceImpl implements LogService {
}
// 获取IP地址
log
.
setRequestIp
(
StringUtils
.
getIP
(
request
)
);
log
.
setRequestIp
(
ip
);
if
(
LOGINPATH
.
equals
(
signature
.
getName
())){
try
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment