logaspect.java

来自「达内Java培训实训项目ECPORT原码。 包括逐步优化的四个版本: 简单工」· Java 代码 · 共 34 行

JAVA
34
字号
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 + =
减小字号Ctrl + -
显示快捷键?