⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logaspect.java

📁 达内Java培训实训项目ECPORT原码。 包括逐步优化的四个版本: 简单工厂模式实现 简单Spring-IoC实现 Spring声明式事务实现 Spring-AOP集成
💻 JAVA
字号:
package com.royee.ecport.aop;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;

import com.royee.ecport.annotation.Description;
import com.royee.ecport.exception.ApplicationNotRunningException;
import com.royee.ecport.pojo.User;
import com.royee.ecport.web.actions.LoginAction;

/**
 * 日志记录模块,记录Web层动作日志
 * @author cfgxy
 *
 */
public class LogAspect extends AspectFilter {

	public void doFilter(JoinPoint jp) {
		User u = null;
		try {
			Description description= getAnnotation(jp,Description.class);
			if(description==null)
				return;
			u = (User) session().getAttribute(LoginAction.SESSION_KEY);
			String username = (u == null ? "[guest]" : u.toString());
			Logger.getLogger(jp.getTarget().getClass()).info(
					description.value() + "(" + username + ")");
		} catch (ApplicationNotRunningException e) {
			Logger.getLogger(jp.getTarget().getClass()).debug(
					"denified method used by spring.");
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -