com.hihsoft.sso.sysmonitor.syslogs.aop.LogServiceCallAdvice.java Source code

Java tutorial

Introduction

Here is the source code for com.hihsoft.sso.sysmonitor.syslogs.aop.LogServiceCallAdvice.java

Source

/**
 * Copyright (c) 2013-2015 www.javahih.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.hihsoft.sso.sysmonitor.syslogs.aop;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.StopWatch;
import org.apache.log4j.Logger;

/**
 * <p> Title:?
 * ???</p>
 * <p> Description:</p>
 * <p> Copyright: Copyright (c) 2013 </p>
 * <p> Company:hihsoft.co.,ltd </p>
 *  @author hihsoft.co.,ltd
 * @version 1.0
 */
public class LogServiceCallAdvice implements MethodInterceptor {

    /** The Constant log. */
    private static final Logger log = Logger.getLogger(LogServiceCallAdvice.class);

    /*
     * ?
     * 
     * @see
     * org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept
     * .MethodInvocation)
     */
    @Override
    public Object invoke(final MethodInvocation invocation) throws Throwable {
        final String clazzString = invocation.getThis().getClass().getName();// ??
        final String methodName = invocation.getMethod().getName();// ??
        final String fullPath = clazzString + "." + methodName;
        final StopWatch clock = new StopWatch();
        clock.start(); // 
        final Object result = invocation.proceed();
        clock.stop(); // ? //????

        final Class<?>[] params = invocation.getMethod().getParameterTypes();
        final String[] simpleParams = new String[params.length];
        for (int i = 0; i < params.length; i++) {
            simpleParams[i] = params[i].getSimpleName();
        }
        //log4j.xml???
        log.info(
                "-----------------------------------------------------------------------------");
        log.info("[" + methodName + "(" + StringUtils.join(simpleParams, ",") + ")];:"
                + clock.getTime() + ";[" + fullPath + "]");
        return result;
    }
}