logaspect.java
来自「spring2.0技术手册随书事例,结合例子学习起来更轻松」· Java 代码 · 共 31 行
JAVA
31 行
package onlyfun.caterpillar;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.aspectj.lang.JoinPoint;
public class LogAspect {
private Logger logger =
Logger.getLogger(this.getClass().getName());
public void before(JoinPoint jointPoint) {
logger.log(Level.INFO, "method starts..." +
jointPoint.getSignature().getDeclaringTypeName() +
"." + jointPoint.getSignature().getName());
}
public void afterReturning(JoinPoint jointPoint) {
logger.log(Level.INFO, "method ends..." +
jointPoint.getSignature().getDeclaringTypeName() +
"." + jointPoint.getSignature().getName());
}
public void afterThrowing(JoinPoint jointPoint,
Throwable throwable) {
logger.log(Level.INFO, "Logging that a " + throwable +
"\nException was thrown in..." +
jointPoint.getSignature().getDeclaringTypeName() +
"." + jointPoint.getSignature().getName());
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?