/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.shardingsphere.core.log;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.api.config.masterslave.MasterSlaveRuleConfiguration;
import org.apache.shardingsphere.api.config.sharding.ShardingRuleConfiguration;
import org.apache.shardingsphere.core.rule.Authentication;
import org.apache.shardingsphere.core.yaml.swapper.AuthenticationYamlSwapper;
import org.apache.shardingsphere.core.yaml.swapper.MasterSlaveRuleConfigurationYamlSwapper;
import org.apache.shardingsphere.core.yaml.swapper.ShardingRuleConfigurationYamlSwapper;
import org.apache.shardingsphere.encrypt.api.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.yaml.swapper.EncryptRuleConfigurationYamlSwapper;
import org.apache.shardingsphere.underlying.common.config.RuleConfiguration;
import org.apache.shardingsphere.underlying.common.yaml.engine.YamlEngine;

import java.util.Properties;

/**
 * Configuration logger.
 *
 * @author sunbufu
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Slf4j
public final class ConfigurationLogger {
    
    /**
     * Log rule configuration.
     *
     * @param ruleConfiguration rule configuration
     */
    public static void log(final RuleConfiguration ruleConfiguration) {
        if (null == ruleConfiguration) {
            return;
        }
        if (ruleConfiguration instanceof ShardingRuleConfiguration) {
            ConfigurationLogger.log((ShardingRuleConfiguration) ruleConfiguration);
        } else if (ruleConfiguration instanceof MasterSlaveRuleConfiguration) {
            ConfigurationLogger.log((MasterSlaveRuleConfiguration) ruleConfiguration);
        } else if (ruleConfiguration instanceof EncryptRuleConfiguration) {
            ConfigurationLogger.log((EncryptRuleConfiguration) ruleConfiguration);
        }
    }
    
    private static void log(final ShardingRuleConfiguration shardingRuleConfiguration) {
        if (null != shardingRuleConfiguration) {
            log(shardingRuleConfiguration.getClass().getSimpleName(), YamlEngine.marshal(new ShardingRuleConfigurationYamlSwapper().swap(shardingRuleConfiguration)));
        }
    }
    
    private static void log(final MasterSlaveRuleConfiguration masterSlaveRuleConfiguration) {
        if (null != masterSlaveRuleConfiguration) {
            log(masterSlaveRuleConfiguration.getClass().getSimpleName(), YamlEngine.marshal(new MasterSlaveRuleConfigurationYamlSwapper().swap(masterSlaveRuleConfiguration)));
        }
    }
    
    private static void log(final EncryptRuleConfiguration encryptRuleConfiguration) {
        if (null != encryptRuleConfiguration) {
            log(encryptRuleConfiguration.getClass().getSimpleName(), YamlEngine.marshal(new EncryptRuleConfigurationYamlSwapper().swap(encryptRuleConfiguration)));
        }
    }
    
    /**
     * Log authentication configuration.
     *
     * @param authenticationConfiguration authentication configuration
     */
    public static void log(final Authentication authenticationConfiguration) {
        if (null != authenticationConfiguration) {
            log(authenticationConfiguration.getClass().getSimpleName(), YamlEngine.marshal(new AuthenticationYamlSwapper().swap(authenticationConfiguration)));
        }
    }
    
    /**
     * Log properties.
     *
     * @param properties properties
     */
    public static void log(final Properties properties) {
        if (null != properties) {
            log(properties.getClass().getSimpleName(), YamlEngine.marshal(properties));
        }
    }
    
    private static void log(final String type, final String logContent) {
        log.info("{}\n{}", type, logContent);
    }
}

@@ -2251,36 +2251,16 @@
         
-ConfigurationLogger.
 log((Sha
@@ -2295,32 +2295,32 @@
 Configuration);%0A
+
         %7D else i
@@ -2395,36 +2395,16 @@
         
-ConfigurationLogger.
 log((Mas
@@ -2518,32 +2518,32 @@
 onfiguration) %7B%0A
+
             Conf
@@ -2542,28 +2542,8 @@
     
-ConfigurationLogger.
 log(
@@ -4423,16 +4423,17 @@
 info(%22%7B%7D
+:
 %5Cn%7B%7D%22, t

refactor ConfigurationLogger