package com.longcoding.undefined.interceptors;

import com.longcoding.undefined.exceptions.ExceptionMessage;
import com.longcoding.undefined.exceptions.GeneralException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.DispatcherType;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by longcoding on 16. 4. 7..
 */
@Slf4j
public abstract class AbstractBaseInterceptor<T> extends HandlerInterceptorAdapter {

    private int errorCode;
    private String errorMessage;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        if (DispatcherType.ASYNC.equals(request.getDispatcherType())) {
            return true;
        }

        long startTime = System.currentTimeMillis();

        boolean result = preHandler(request, response, handler);

        log.debug("Time : {}", (System.currentTimeMillis() - startTime));

        if (!result) {
            throw new GeneralException(new ExceptionMessage(errorCode, errorMessage));
        }

        return result;
    }

    public void generateException(int errorCode, String errorMessage) {
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }


    public abstract boolean preHandler(HttpServletRequest request,
                                                  HttpServletResponse response, Object handler) throws Exception;


}

@@ -174,33 +174,83 @@
 ort 
-lombok.extern.slf4j.Slf4j
+org.apache.logging.log4j.LogManager;%0Aimport org.apache.logging.log4j.Logger
 ;%0Aim
@@ -504,15 +504,8 @@
  */%0A
-@Slf4j%0A
 publ
@@ -582,24 +582,95 @@
 rAdapter %7B%0A%0A
+    protected final Logger logger = LogManager.getLogger(getClass());%0A%0A
     private 
@@ -1091,19 +1091,67 @@
         
-log
+if ( logger.isDebugEnabled() ) %7B%0A            logger
 .debug(%22
@@ -1161,12 +1161,11 @@
 e : 
-%7B%7D%22,
+%22 +
  (Sy
@@ -1203,16 +1203,26 @@
 tTime));
+%0A        %7D
 %0A%0A      
@@ -1225,17 +1225,16 @@
       if
- 
 (!result
@@ -1234,17 +1234,16 @@
 !result)
- 
 %7B%0A      

rollback slf4 -> log4j in abstract class