All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.lsn.java.common.middleware.businesslog.AbstractLoggingAspect Maven / Gradle / Ivy

package io.lsn.java.common.middleware.businesslog;

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

import java.time.Duration;
import java.time.LocalDateTime;

/**
 * @author Patryk Szlagowski 
 */
public class AbstractLoggingAspect {

    protected final static Logger logger = Logger.getLogger(AbstractLoggingAspect.class);

    /**
     * execute method and log execution time
     * @param point
     * @param signature
     * @return
     * @throws Throwable
     */
    public Object log(ProceedingJoinPoint point, String signature) throws Throwable {
        LocalDateTime start = LocalDateTime.now();
        Object toReturn = null;
        try {
            toReturn = point.proceed();
        } catch (Throwable e) {
            throw e;
        }

        Long milliseconds = Duration.between(start, LocalDateTime.now()).toMillis();
        logger.info(signature.concat(" execution time: ".concat(String.valueOf(milliseconds).concat("ms"))));

        return toReturn;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy