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
77e6b434
Commit
77e6b434
authored
Jul 20, 2023
by
王亮
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix an issue(log)
parent
67419058
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
38 deletions
+45
-38
LogCallHttpAspect.java
...n/quantgroup/xyqb/aspect/logcaller/LogCallHttpAspect.java
+45
-38
No files found.
src/main/java/cn/quantgroup/xyqb/aspect/logcaller/LogCallHttpAspect.java
View file @
77e6b434
package
cn
.
quantgroup
.
xyqb
.
aspect
.
logcaller
;
package
cn
.
quantgroup
.
xyqb
.
aspect
.
logcaller
;
import
cn.quantgroup.tech.util.TechEnvironment
;
import
cn.quantgroup.xyqb.util.IpUtil
;
import
cn.quantgroup.xyqb.util.IpUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.google.common.base.Stopwatch
;
import
com.google.common.base.Stopwatch
;
import
java.io.Serializable
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Around
;
...
@@ -19,7 +16,11 @@ import org.springframework.web.context.request.RequestContextHolder;
...
@@ -19,7 +16,11 @@ 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
javax.servlet.http.HttpServletRequest
;
import
java.io.Serializable
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
/**
/**
* 调用者记录
* 调用者记录
...
@@ -30,47 +31,53 @@ import java.util.concurrent.TimeUnit;
...
@@ -30,47 +31,53 @@ import java.util.concurrent.TimeUnit;
@Component
@Component
@Order
(
value
=
Ordered
.
HIGHEST_PRECEDENCE
)
@Order
(
value
=
Ordered
.
HIGHEST_PRECEDENCE
)
public
class
LogCallHttpAspect
{
public
class
LogCallHttpAspect
{
@Pointcut
(
value
=
"execution(public * cn.quantgroup.xyqb.controller..*.*(..)) "
@Pointcut
(
value
=
"execution(public * cn.quantgroup.xyqb.controller..*.*(..)) "
+
"&& !execution(* cn.quantgroup.xyqb.controller.ExceptionHandlingController.*(..))"
+
"&& !execution(* cn.quantgroup.xyqb.controller.ExceptionHandlingController.*(..))"
+
"&& !execution(* cn.quantgroup.xyqb.controller.middleoffice.login.ILoginModule.*(..))"
)
// 服务层包路径导致错误,暂时不动,在合适的时候应该挪走
+
"&& !execution(* cn.quantgroup.xyqb.controller.middleoffice.login.ILoginModule.*(..))"
)
private
void
logHttpCaller
()
{
// 服务层包路径导致错误,暂时不动,在合适的时候应该挪走
}
private
void
logHttpCaller
()
{
}
@Around
(
"logHttpCaller()"
)
@Around
(
"logHttpCaller()"
)
public
Object
record
(
ProceedingJoinPoint
pjp
)
throws
Throwable
{
public
Object
record
(
ProceedingJoinPoint
pjp
)
throws
Throwable
{
Stopwatch
stopwatch
=
Stopwatch
.
createStarted
();
Stopwatch
stopwatch
=
Stopwatch
.
createStarted
();
ServletRequestAttributes
attrs
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
ServletRequestAttributes
attrs
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
HttpServletRequest
request
=
attrs
.
getRequest
();
HttpServletRequest
request
=
attrs
.
getRequest
();
String
remoteIP
=
IpUtil
.
getRemoteIP
(
request
);
String
remoteIP
=
IpUtil
.
getRemoteIP
(
request
);
Object
[]
args
=
pjp
.
getArgs
();
Object
[]
args
=
pjp
.
getArgs
();
boolean
hasException
=
false
;
boolean
hasException
=
false
;
Object
result
=
null
;
Object
result
=
null
;
try
{
try
{
result
=
pjp
.
proceed
();
result
=
pjp
.
proceed
();
}
catch
(
Throwable
e
)
{
}
catch
(
Throwable
e
)
{
log
.
error
(
e
.
getMessage
());
log
.
error
(
e
.
getMessage
());
hasException
=
true
;
hasException
=
true
;
throw
e
;
throw
e
;
}
finally
{
}
finally
{
long
elapsed
=
stopwatch
.
stop
().
elapsed
(
TimeUnit
.
MILLISECONDS
);
long
elapsed
=
stopwatch
.
stop
().
elapsed
(
TimeUnit
.
MILLISECONDS
);
String
resultStr
=
result
==
null
?
""
:
JSON
.
toJSONString
(
result
);
String
resultStr
=
result
==
null
?
""
:
JSON
.
toJSONString
(
result
);
resultStr
=
resultStr
.
length
()
<
500
?
resultStr
:
resultStr
.
substring
(
0
,
500
);
resultStr
=
resultStr
.
length
()
<
500
?
resultStr
:
resultStr
.
substring
(
0
,
500
);
List
<
Object
>
argList
=
Arrays
.
stream
(
args
).
filter
(
arg
->
arg
instanceof
Serializable
)
List
<
Object
>
argList
=
Arrays
.
stream
(
args
).
filter
(
arg
->
arg
instanceof
Serializable
)
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
log
.
info
(
"[httpRequestLog],url:[{}],duration:[{}],[耗时区间]{},remoteIP:[{}],args:[{}],exception:[{}],result:[{}]"
,
request
.
getRequestURL
(),
elapsed
,
slowlyTag
(
elapsed
),
remoteIP
,
JSON
.
toJSONString
(
argList
),
hasException
,
resultStr
);
if
(
TechEnvironment
.
isPro
()
&&
request
.
getRequestURL
().
toString
().
contains
(
"/oauth/login"
))
{
}
log
.
info
(
"[httpRequestLog],url:[{}],duration:[{}],[耗时区间]{},remoteIP:[{}],exception:[{}],result:[{}]"
,
return
result
;
request
.
getRequestURL
(),
elapsed
,
slowlyTag
(
elapsed
),
remoteIP
,
hasException
,
resultStr
);
}
}
log
.
info
(
"[httpRequestLog],url:[{}],duration:[{}],[耗时区间]{},remoteIP:[{}],args:[{}],exception:[{}],result:[{}]"
,
request
.
getRequestURL
(),
elapsed
,
slowlyTag
(
elapsed
),
remoteIP
,
JSON
.
toJSONString
(
argList
),
hasException
,
resultStr
);
}
return
result
;
}
private
String
slowlyTag
(
long
elapsed
)
{
private
String
slowlyTag
(
long
elapsed
)
{
Long
second
=
elapsed
/
1000L
;
Long
second
=
elapsed
/
1000L
;
String
outTimeFormat
=
"[outTime_%s]"
;
String
outTimeFormat
=
"[outTime_%s]"
;
StringBuffer
sb
=
new
StringBuffer
();
StringBuffer
sb
=
new
StringBuffer
();
// 3秒步长
// 3秒步长
for
(
int
outTime
=
3
;
outTime
<=
second
;
outTime
++)
{
for
(
int
outTime
=
3
;
outTime
<=
second
;
outTime
++)
{
sb
.
append
(
String
.
format
(
outTimeFormat
,
outTime
));
sb
.
append
(
String
.
format
(
outTimeFormat
,
outTime
));
}
}
return
sb
.
toString
();
return
sb
.
toString
();
}
}
}
}
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