Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
browser-backend
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
browser-backend
Commits
015c9803
Commit
015c9803
authored
Oct 20, 2020
by
huangjiamin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
全局日志处理
parent
6e2265ea
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
7 deletions
+93
-7
pom.xml
pom.xml
+6
-0
IpController.java
...edgec/browserbackend/browser/controller/IpController.java
+7
-7
MvcMethodLogAdvice.java
...m/edgec/browserbackend/common/log/MvcMethodLogAdvice.java
+80
-0
No files found.
pom.xml
View file @
015c9803
...
@@ -183,6 +183,12 @@
...
@@ -183,6 +183,12 @@
<version>
4.6.0
</version>
<version>
4.6.0
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.aspectj
</groupId >
<artifactId>
aspectjweaver
</artifactId >
<version>
1.8.7
</version >
</dependency>
</dependencies>
</dependencies>
...
...
src/main/java/com/edgec/browserbackend/browser/controller/IpController.java
View file @
015c9803
...
@@ -35,7 +35,7 @@ public class IpController {
...
@@ -35,7 +35,7 @@ public class IpController {
* 购买IP资源
* 购买IP资源
*
*
* @param principal principal
* @param principal principal
* @param ipResourceRequestDto
tod
o
* @param ipResourceRequestDto
ipResourceRequestDt
o
* @return ResultDto
* @return ResultDto
*/
*/
@RequestMapping
(
value
=
"/buy"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/buy"
,
method
=
RequestMethod
.
POST
)
...
@@ -57,7 +57,7 @@ public class IpController {
...
@@ -57,7 +57,7 @@ public class IpController {
* 续费IP资源
* 续费IP资源
*
*
* @param principal principal
* @param principal principal
* @param ipResourceRequestDto
tod
o
* @param ipResourceRequestDto
ipResourceRequestDt
o
* @return ResultDto
* @return ResultDto
*/
*/
@RequestMapping
(
value
=
"/renew"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/renew"
,
method
=
RequestMethod
.
POST
)
...
@@ -79,7 +79,7 @@ public class IpController {
...
@@ -79,7 +79,7 @@ public class IpController {
* 删除指定IP资源
* 删除指定IP资源
*
*
* @param principal principal
* @param principal principal
* @param ipResourceRequestDto
todo--前端只传了 addr
* @param ipResourceRequestDto
ipResourceRequestDto
* @return ResultDto
* @return ResultDto
*/
*/
@RequestMapping
(
value
=
"/del"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/del"
,
method
=
RequestMethod
.
POST
)
...
@@ -101,7 +101,7 @@ public class IpController {
...
@@ -101,7 +101,7 @@ public class IpController {
* 获取IP列表
* 获取IP列表
*
*
* @param principal principal
* @param principal principal
* @param ipListRequestDto
tod
o
* @param ipListRequestDto
ipListRequestDt
o
* @return ResultDto
* @return ResultDto
*/
*/
@RequestMapping
(
value
=
"/list"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/list"
,
method
=
RequestMethod
.
POST
)
...
@@ -128,7 +128,7 @@ public class IpController {
...
@@ -128,7 +128,7 @@ public class IpController {
* (暂不知)
* (暂不知)
*
*
* @param principal principal
* @param principal principal
* @param ipResourceUpdateDto
tod
o
* @param ipResourceUpdateDto
ipResourceUpdateDt
o
* @return ResultDto
* @return ResultDto
*/
*/
@RequestMapping
(
value
=
"/update"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/update"
,
method
=
RequestMethod
.
POST
)
...
@@ -152,7 +152,7 @@ public class IpController {
...
@@ -152,7 +152,7 @@ public class IpController {
* 添加自有ip的检测
* 添加自有ip的检测
*
*
* @param principal principal
* @param principal principal
* @param ipResourceUpdateDto
tod
o
* @param ipResourceUpdateDto
ipResourceUpdateDt
o
* @return ResultDto
* @return ResultDto
*/
*/
@RequestMapping
(
value
=
"/query"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/query"
,
method
=
RequestMethod
.
POST
)
...
@@ -174,7 +174,7 @@ public class IpController {
...
@@ -174,7 +174,7 @@ public class IpController {
/**
/**
* @param principal principal
* @param principal principal
* @param ipResourceRequestDto
tod
o
* @param ipResourceRequestDto
ipResourceRequestDt
o
* @return ResultDto
* @return ResultDto
*/
*/
@RequestMapping
(
value
=
"/detail"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/detail"
,
method
=
RequestMethod
.
POST
)
...
...
src/main/java/com/edgec/browserbackend/common/log/MvcMethodLogAdvice.java
0 → 100644
View file @
015c9803
package
com
.
edgec
.
browserbackend
.
common
.
log
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.Signature
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.HttpServletRequest
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Parameter
;
import
java.util.*
;
/**
* @author JMW
*/
@Component
@Aspect
public
class
MvcMethodLogAdvice
{
private
static
Logger
LOG
=
LoggerFactory
.
getLogger
(
MvcMethodLogAdvice
.
class
);
@Around
(
"@annotation(org.springframework.web.bind.annotation.RequestMapping)"
)
public
Object
aroundAdvice
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
//获取当前请求对象
ServletRequestAttributes
attributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
HttpServletRequest
request
=
Objects
.
requireNonNull
(
attributes
).
getRequest
();
Signature
signature
=
joinPoint
.
getSignature
();
MethodSignature
methodSignature
=
(
MethodSignature
)
signature
;
Method
method
=
methodSignature
.
getMethod
();
String
sb
=
"url : "
+
request
.
getRequestURL
().
toString
()
+
" ; "
+
"Ip : "
+
request
.
getRemoteAddr
()
+
" ; "
+
"Method : "
+
request
.
getMethod
()
+
"; "
+
"Parameter : "
+
getParameter
(
method
,
joinPoint
.
getArgs
());
LOG
.
info
(
sb
);
return
joinPoint
.
proceed
();
}
/**
* 根据方法和传入的参数获取请求参数
*/
private
Object
getParameter
(
Method
method
,
Object
[]
args
)
{
List
<
Object
>
argList
=
new
ArrayList
<>();
Parameter
[]
parameters
=
method
.
getParameters
();
for
(
int
i
=
0
;
i
<
parameters
.
length
;
i
++)
{
//将RequestBody注解修饰的参数作为请求参数
RequestBody
requestBody
=
parameters
[
i
].
getAnnotation
(
RequestBody
.
class
);
if
(
requestBody
!=
null
)
{
argList
.
add
(
args
[
i
]);
}
//将RequestParam注解修饰的参数作为请求参数
RequestParam
requestParam
=
parameters
[
i
].
getAnnotation
(
RequestParam
.
class
);
if
(
requestParam
!=
null
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
String
key
=
parameters
[
i
].
getName
();
if
(!
org
.
springframework
.
util
.
StringUtils
.
isEmpty
(
requestParam
.
value
()))
{
key
=
requestParam
.
value
();
}
map
.
put
(
key
,
args
[
i
]);
argList
.
add
(
map
);
}
}
if
(
argList
.
size
()
==
0
)
{
return
null
;
}
else
if
(
argList
.
size
()
==
1
)
{
return
argList
.
get
(
0
);
}
else
{
return
argList
;
}
}
}
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