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
7d22178f
Commit
7d22178f
authored
Dec 14, 2019
by
Elune
Browse files
代码优化
parent
ebdf7799
Changes
2
Hide whitespace changes
Inline
Side-by-side
eladmin-logging/src/main/java/me/zhengjie/aspect/LogAspect.java
View file @
7d22178f
...
@@ -28,7 +28,7 @@ public class LogAspect {
...
@@ -28,7 +28,7 @@ public class LogAspect {
private
final
LogService
logService
;
private
final
LogService
logService
;
private
l
ong
currentTime
=
0L
;
ThreadLocal
<
L
ong
>
currentTime
=
new
ThreadLocal
<>()
;
public
LogAspect
(
LogService
logService
)
{
public
LogAspect
(
LogService
logService
)
{
this
.
logService
=
logService
;
this
.
logService
=
logService
;
...
@@ -50,9 +50,10 @@ public class LogAspect {
...
@@ -50,9 +50,10 @@ public class LogAspect {
@Around
(
"logPointcut()"
)
@Around
(
"logPointcut()"
)
public
Object
logAround
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
public
Object
logAround
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
Object
result
;
Object
result
;
currentTime
=
System
.
currentTimeMillis
();
currentTime
.
set
(
System
.
currentTimeMillis
()
)
;
result
=
joinPoint
.
proceed
();
result
=
joinPoint
.
proceed
();
Log
log
=
new
Log
(
"INFO"
,
System
.
currentTimeMillis
()
-
currentTime
);
Log
log
=
new
Log
(
"INFO"
,
System
.
currentTimeMillis
()
-
currentTime
.
get
());
currentTime
.
remove
();
HttpServletRequest
request
=
RequestHolder
.
getHttpServletRequest
();
HttpServletRequest
request
=
RequestHolder
.
getHttpServletRequest
();
logService
.
save
(
getUsername
(),
StringUtils
.
getBrowser
(
request
),
StringUtils
.
getIp
(
request
),
joinPoint
,
log
);
logService
.
save
(
getUsername
(),
StringUtils
.
getBrowser
(
request
),
StringUtils
.
getIp
(
request
),
joinPoint
,
log
);
return
result
;
return
result
;
...
@@ -66,7 +67,8 @@ public class LogAspect {
...
@@ -66,7 +67,8 @@ public class LogAspect {
*/
*/
@AfterThrowing
(
pointcut
=
"logPointcut()"
,
throwing
=
"e"
)
@AfterThrowing
(
pointcut
=
"logPointcut()"
,
throwing
=
"e"
)
public
void
logAfterThrowing
(
JoinPoint
joinPoint
,
Throwable
e
)
{
public
void
logAfterThrowing
(
JoinPoint
joinPoint
,
Throwable
e
)
{
Log
log
=
new
Log
(
"ERROR"
,
System
.
currentTimeMillis
()
-
currentTime
);
Log
log
=
new
Log
(
"ERROR"
,
System
.
currentTimeMillis
()
-
currentTime
.
get
());
currentTime
.
remove
();
log
.
setExceptionDetail
(
ThrowableUtil
.
getStackTrace
(
e
).
getBytes
());
log
.
setExceptionDetail
(
ThrowableUtil
.
getStackTrace
(
e
).
getBytes
());
HttpServletRequest
request
=
RequestHolder
.
getHttpServletRequest
();
HttpServletRequest
request
=
RequestHolder
.
getHttpServletRequest
();
logService
.
save
(
getUsername
(),
StringUtils
.
getBrowser
(
request
),
StringUtils
.
getIp
(
request
),
(
ProceedingJoinPoint
)
joinPoint
,
log
);
logService
.
save
(
getUsername
(),
StringUtils
.
getBrowser
(
request
),
StringUtils
.
getIp
(
request
),
(
ProceedingJoinPoint
)
joinPoint
,
log
);
...
...
eladmin-system/src/test/java/me/zhengjie/EladminSystemApplicationTests.java
View file @
7d22178f
...
@@ -5,9 +5,6 @@ import org.junit.runner.RunWith;
...
@@ -5,9 +5,6 @@ import org.junit.runner.RunWith;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
java.util.ArrayList
;
import
java.util.List
;
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
@SpringBootTest
public
class
EladminSystemApplicationTests
{
public
class
EladminSystemApplicationTests
{
...
...
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