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
d378198a
Commit
d378198a
authored
Apr 24, 2017
by
lee_mingzhu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
删除日志切面
parent
017be902
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
96 deletions
+0
-96
ParamLogAdvice.java
...in/java/cn/quantgroup/xyqb/aspect/log/ParamLogAdvice.java
+0
-96
No files found.
src/main/java/cn/quantgroup/xyqb/aspect/log/ParamLogAdvice.java
deleted
100644 → 0
View file @
017be902
package
cn
.
quantgroup
.
xyqb
.
aspect
.
log
;
import
javassist.ClassClassPath
;
import
javassist.ClassPool
;
import
javassist.CtClass
;
import
javassist.CtMethod
;
import
javassist.Modifier
;
import
javassist.NotFoundException
;
import
javassist.bytecode.CodeAttribute
;
import
javassist.bytecode.LocalVariableAttribute
;
import
javassist.bytecode.MethodInfo
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.annotation.After
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.context.annotation.Configuration
;
/**
* Created by 11 on 2017/4/20.
*/
@Aspect
@Configuration
public
class
ParamLogAdvice
{
private
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ParamLogAdvice
.
class
);
/**
* 定义切面,拦截InnerController类中的所有方法
*/
@Pointcut
(
"execution(* cn.quantgroup.xyqb.controller.external.user.InnerController.*(..))"
)
public
void
logPointCut
(){}
/**
* 后置通知,方法执行后获取方法的入参信息并打印日志
* @param jp
*/
@After
(
"logPointCut()"
)
public
void
printMethodParam
(
JoinPoint
jp
)
{
Object
[]
params
=
jp
.
getArgs
();
String
methodName
=
jp
.
getSignature
().
getName
();
String
[]
paramNames
=
null
;
try
{
paramNames
=
getFieldsName
(
jp
.
getTarget
().
getClass
(),
jp
.
getTarget
().
getClass
().
getName
(),
methodName
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
StringBuffer
buffer
=
new
StringBuffer
();
int
index
=
0
;
if
(
null
!=
paramNames
)
{
for
(
int
i
=
0
;
i
<
paramNames
.
length
;
i
++)
{
if
(
paramNames
[
i
].
equals
(
"this"
)){
continue
;
}
buffer
.
append
(
paramNames
[
i
]).
append
(
":"
).
append
(
params
[
index
]).
append
(
" "
);
index
=
i
;
}
String
logInfo
=
buffer
.
toString
().
substring
(
0
,
buffer
.
toString
().
length
()
-
1
);
LOGGER
.
info
(
"调用方法,方法名:{} , 方法参数:{}"
,
methodName
,
logInfo
);
}
}
/**
* 利用javassist获取方法的参数名称
* @param cls
* @param clazzName
* @param methodName
* @return
* @throws NotFoundException
*/
private
static
String
[]
getFieldsName
(
Class
cls
,
String
clazzName
,
String
methodName
)
throws
NotFoundException
{
//获取class定义的容器
ClassPool
pool
=
ClassPool
.
getDefault
();
ClassClassPath
classPath
=
new
ClassClassPath
(
cls
);
pool
.
insertClassPath
(
classPath
);
//从容器中获取编译后的class
CtClass
cc
=
pool
.
get
(
clazzName
);
//反射获取指定方法
CtMethod
cm
=
cc
.
getDeclaredMethod
(
methodName
);
MethodInfo
methodInfo
=
cm
.
getMethodInfo
();
CodeAttribute
codeAttribute
=
methodInfo
.
getCodeAttribute
();
LocalVariableAttribute
attr
=
(
LocalVariableAttribute
)
codeAttribute
.
getAttribute
(
LocalVariableAttribute
.
tag
);
if
(
attr
==
null
)
{
return
null
;
}
String
[]
paramNames
=
new
String
[
cm
.
getParameterTypes
().
length
];
int
pos
=
Modifier
.
isStatic
(
cm
.
getModifiers
())
?
0
:
1
;
for
(
int
i
=
0
;
i
<
paramNames
.
length
;
i
++){
paramNames
[
i
]
=
attr
.
variableName
(
i
+
pos
);
}
return
paramNames
;
}
}
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