
package com.capgemini.boot.trace;

import com.capgemini.boot.trace.settings.TraceLoggerSettings;
import org.springframework.aop.interceptor.AbstractTraceInterceptor;
import org.springframework.aop.interceptor.CustomizableTraceInterceptor;

/**
 * Utility methods for trace logger configuration.
 *
 */
public final class TraceLoggerConfigurationUtils {

    /**
     * Private constructor as this class provides static methods only
     */
    private TraceLoggerConfigurationUtils() { }

    /**
     * Creates a trace interceptor for logging entry into and exit from methods.
     * @param settings the settings
     * @return The created trace interceptor
     */
    public static AbstractTraceInterceptor createTraceInterceptor(TraceLoggerSettings settings) {
        CustomizableTraceInterceptor customizableTraceInterceptor = new CustomizableTraceInterceptor();
        customizableTraceInterceptor.setUseDynamicLogger(true);
        customizableTraceInterceptor.setEnterMessage(settings.getMessage().getEnter());
        customizableTraceInterceptor.setExitMessage(settings.getMessage().getExit());
        customizableTraceInterceptor.setExceptionMessage(settings.getMessage().getException());
        return customizableTraceInterceptor;
    }
}
