forked from longfeizheng/logback
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01f7991
commit 1968501
Showing
2 changed files
with
62 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cn.merryyou.logback.aspect; | ||
|
||
import org.aspectj.lang.JoinPoint; | ||
import org.aspectj.lang.annotation.*; | ||
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; | ||
|
||
/** | ||
* Created by zlf | ||
* 2017-03-18 12:31 | ||
*/ | ||
@Aspect | ||
@Component | ||
public class HttpAspect { | ||
|
||
private final static Logger logger = LoggerFactory.getLogger(HttpAspect.class); | ||
|
||
|
||
@Pointcut("execution(public * cn.merryyou.logback.controller.*.*(..))") | ||
public void log() { | ||
} | ||
|
||
@Before("log()") | ||
public void doBefore(JoinPoint joinPoint) { | ||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); | ||
HttpServletRequest request = attributes.getRequest(); | ||
|
||
//url method ip | ||
logger.info("利用AOP记录每次请求的有关信息,url={},method={},ip={}", request.getRequestURL(), request.getMethod(), request.getRemoteAddr()); | ||
|
||
//类方法 参数 | ||
logger.info("class_method={}, args={}", joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName(), joinPoint.getArgs()); | ||
} | ||
|
||
@After("log()") | ||
public void doAfter() { | ||
logger.info("利用AOP记录每次请求完成后的信息"); | ||
} | ||
|
||
@AfterReturning(returning = "object", pointcut = "log()") | ||
public void doAfterReturning(Object object) { | ||
logger.info("response={}", object.toString()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters