/**
 * ÀÌ ¼Ò½º´Â Spring ÇÁ·¹ÀÓ¿öÅ© ¿öÅ©ºÏ¿¡¼­ »ç¿ëÇÑ ¿¹Á¦ ¼Ò½ºÀÔ´Ï´Ù. 
 * ÀÌ ¼Ò½º´Â ¸ðµç °³¹ßÀÚµéÀÌ ÀÚÀ¯·Ó°Ô ¼öÁ¤ ¹× ¹èÆ÷ÇÒ ¼ö ÀÖ½À´Ï´Ù. 
 * ´Ü, ÀÌ ¼Ò½º¸¦ ±â¹ÝÀ¸·Î »õ·Î¿î ¾ÖÇÃ¸®ÄÉÀÌ¼ÇÀ» °³¹ßÇÒ °æ¿ì ÃâÃ³¸¦ ¸í½ÃÇØ ÁÖ½Ã¸é µË´Ï´Ù. 
 */
package net.javajigi.advice;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * ÁÖ¼®À» ³Ö¾î ÁÖ¼¼¿ä. ¹è°¡ °íÆÄ¿ä.
 * 
 * @author ¹ÚÀç¼º(ÀÚ¹ÙÁö±â, javajigi@gmail.com)
 */
public class LoggingAdvice implements MethodInterceptor {
	protected final Log logger = LogFactory.getLog(getClass());

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
	 */
	public Object invoke(MethodInvocation invocation) throws Throwable {
		String className = invocation.getThis().getClass().getName();

		if (logger.isDebugEnabled()) {
			logger.debug(className + "." + invocation.getMethod().getName()
					+ "() ½ÃÀÛ!!");
			Object[] args = invocation.getArguments();
			if ((args != null) && (args.length > 0)) {
				logger.debug("Argument Size : " + args.length);

				for (int i = 0; i < args.length; i++) {
					logger.debug("Argument[" + i + "] : " + args[i]);
				}
			}
		}

		Object retVal = invocation.proceed();

		if (logger.isDebugEnabled()) {
			logger.debug(className + " | " + invocation.getMethod().getName()
					+ " Á¾·á!!");
		}

		return retVal;
	}
}
