Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
first-boot
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
train
first-boot
Commits
d894eda3
Commit
d894eda3
authored
Nov 08, 2018
by
徐奇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
INIT
parent
c67c41d5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
0 deletions
+61
-0
pom.xml
+7
-0
src/main/java/cn/freemud/firstboot/aspect/HttpAspect.java
+54
-0
No files found.
pom.xml
View file @
d894eda3
...
@@ -59,6 +59,13 @@
...
@@ -59,6 +59,13 @@
<artifactId>
spring-boot-starter-thymeleaf
</artifactId>
<artifactId>
spring-boot-starter-thymeleaf
</artifactId>
</dependency>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
1.2.51
</version>
</dependency>
<!-- Swagger -->
<!-- Swagger -->
<dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<groupId>
io.springfox
</groupId>
...
...
src/main/java/cn/freemud/firstboot/aspect/HttpAspect.java
0 → 100644
View file @
d894eda3
/*
* Copyright (c) 2018 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package
cn
.
freemud
.
firstboot
.
aspect
;
import
com.alibaba.fastjson.JSON
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.annotation.AfterReturning
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Before
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.HttpServletRequest
;
@Aspect
@Component
public
class
HttpAspect
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
this
.
getClass
());
@Pointcut
(
"execution(public * cn.freemud.firstboot.web.*.*(..))"
)
public
void
log
()
{
}
/**
* @Before 在方法执行之前执行
*/
@Before
(
"log()"
)
public
void
doBefore
(
JoinPoint
joinPoint
)
{
//记录http请求
ServletRequestAttributes
attributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
HttpServletRequest
request
=
attributes
.
getRequest
();
//从request中获取http请求的url/请求的方法类型/响应该http请求的类方法/IP地址/请求中的参数
logger
.
info
(
"url={} method={} ip={} class_method={} args_json={}"
,
request
.
getRequestURI
(),
request
.
getMethod
(),
request
.
getRemoteAddr
(),
joinPoint
.
getSignature
().
getDeclaringTypeName
()
+
"."
+
joinPoint
.
getSignature
().
getName
(),
JSON
.
toJSONString
(
joinPoint
.
getArgs
()));
}
/**
* @After 在方法执行之后执行
*/
@AfterReturning
(
returning
=
"object"
,
pointcut
=
"log()"
)
public
void
doAfterReturning
(
Object
object
)
{
logger
.
info
(
"response={}"
,
JSON
.
toJSONString
(
object
));
}
}
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