Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
head_group
xyqb-user2
Commits
58a3be11
Commit
58a3be11
authored
Jan 29, 2021
by
于桐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
日志切面调整
parent
29842182
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
34 deletions
+42
-34
.gitignore
.gitignore
+1
-0
LogCallHttpAspect.java
...n/quantgroup/xyqb/aspect/logcaller/LogCallHttpAspect.java
+41
-34
No files found.
.gitignore
View file @
58a3be11
...
@@ -110,3 +110,4 @@ dump.rdb
...
@@ -110,3 +110,4 @@ dump.rdb
transaction-logs/
transaction-logs/
.settings/
.settings/
/bin/
src/main/java/cn/quantgroup/xyqb/aspect/logcaller/LogCallHttpAspect.java
View file @
58a3be11
package
cn
.
quantgroup
.
xyqb
.
aspect
.
logcaller
;
package
cn
.
quantgroup
.
xyqb
.
aspect
.
logcaller
;
import
cn.quantgroup.xyqb.util.IpUtil
;
import
java.util.concurrent.TimeUnit
;
import
com.google.common.base.Stopwatch
;
import
lombok.extern.slf4j.Slf4j
;
import
javax.servlet.http.HttpServletRequest
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.slf4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.HttpServletRequest
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
java.util.concurrent.TimeUnit
;
import
com.google.common.base.Stopwatch
;
import
cn.quantgroup.xyqb.util.IpUtil
;
import
lombok.extern.slf4j.Slf4j
;
/**
/**
* 调用者记录
* 调用者记录
...
@@ -28,31 +31,35 @@ import java.util.concurrent.TimeUnit;
...
@@ -28,31 +31,35 @@ import java.util.concurrent.TimeUnit;
@Order
(
value
=
Ordered
.
HIGHEST_PRECEDENCE
)
@Order
(
value
=
Ordered
.
HIGHEST_PRECEDENCE
)
public
class
LogCallHttpAspect
{
public
class
LogCallHttpAspect
{
@Pointcut
(
value
=
"execution(public * cn.quantgroup.xyqb.controller..*.*(..)) "
+
@Autowired
"&& !execution(* cn.quantgroup.xyqb.controller.ExceptionHandlingController.*(..))"
)
private
ObjectMapper
objectMapper
;
private
void
logHttpCaller
()
{
}
@Pointcut
(
value
=
"execution(public * cn.quantgroup.xyqb.controller..*.*(..)) "
+
"&& !execution(* cn.quantgroup.xyqb.controller.ExceptionHandlingController.*(..))"
)
@Around
(
"logHttpCaller()"
)
private
void
logHttpCaller
()
{
public
Object
record
(
ProceedingJoinPoint
pjp
)
throws
Throwable
{
}
Stopwatch
stopwatch
=
Stopwatch
.
createStarted
();
ServletRequestAttributes
attrs
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
@Around
(
"logHttpCaller()"
)
HttpServletRequest
request
=
attrs
.
getRequest
();
public
Object
record
(
ProceedingJoinPoint
pjp
)
throws
Throwable
{
String
remoteIP
=
IpUtil
.
getRemoteIP
(
request
);
Stopwatch
stopwatch
=
Stopwatch
.
createStarted
();
Object
[]
args
=
pjp
.
getArgs
();
ServletRequestAttributes
attrs
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
boolean
hasException
=
false
;
HttpServletRequest
request
=
attrs
.
getRequest
();
Object
result
;
String
remoteIP
=
IpUtil
.
getRemoteIP
(
request
);
try
{
Object
[]
args
=
pjp
.
getArgs
();
result
=
pjp
.
proceed
();
boolean
hasException
=
false
;
}
catch
(
Throwable
e
)
{
Object
result
=
null
;
hasException
=
true
;
try
{
throw
e
;
result
=
pjp
.
proceed
();
}
finally
{
}
catch
(
Throwable
e
)
{
Stopwatch
stop
=
stopwatch
.
stop
();
hasException
=
true
;
long
elapsed
=
stop
.
elapsed
(
TimeUnit
.
MILLISECONDS
);
throw
e
;
log
.
info
(
"[httpRequestLog],url:[{}],remoteIP:[{}],args:[{}],duration:[{}],exception:[{}]"
,
}
finally
{
request
.
getRequestURL
(),
remoteIP
,
args
,
elapsed
,
hasException
);
Stopwatch
stop
=
stopwatch
.
stop
();
}
long
elapsed
=
stop
.
elapsed
(
TimeUnit
.
MILLISECONDS
);
return
result
;
String
resultStr
=
result
==
null
?
""
:
objectMapper
.
writeValueAsString
(
result
).
substring
(
0
,
500
);
}
log
.
info
(
"[httpRequestLog],url:[{}],remoteIP:[{}],args:[{}],duration:[{}],exception:[{}],result:[{}]"
,
request
.
getRequestURL
(),
remoteIP
,
args
,
elapsed
,
hasException
,
resultStr
);
}
return
result
;
}
}
}
Write
Preview
Markdown
is supported
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