/*
 * Copyright 2016-2018 shardingsphere.io.
 * <p>
 * Licensed 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.
 * </p>
 */

package io.shardingsphere.core.util;

import io.shardingsphere.core.parsing.parser.sql.SQLStatement;
import io.shardingsphere.core.routing.SQLExecutionUnit;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.Collection;

/**
 * SQL logger.
 * 
 * @author zhangliang
 * @author maxiaoguang
 */
@Slf4j(topic = "Sharding-Sphere-SQL")
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class SQLLogger {
    
    /**
     * Print SQL log.
     * 
     * @param logicSQL logic SQL
     * @param sqlStatement SQL statement
     * @param sqlExecutionUnits SQL execution units
     */
    public static void logSQL(final String logicSQL, final SQLStatement sqlStatement, final Collection<SQLExecutionUnit> sqlExecutionUnits) {
        log("Logic SQL: {}", logicSQL);
        log("SQLStatement: {}", sqlStatement);
        for (SQLExecutionUnit each : sqlExecutionUnits) {
            if (each.getSqlUnit().getParameterSets().get(0).isEmpty()) {
                log("Actual SQL: {} ::: {}", each.getDataSource(), each.getSqlUnit().getSql());
            } else {
                log("Actual SQL: {} ::: {} ::: {}", each.getDataSource(), each.getSqlUnit().getSql(), each.getSqlUnit().getParameterSets());
            }
        }
    }
    
    private static void log(final String pattern, final Object... arguments) {
        log.info(pattern, arguments);
    }
}

@@ -651,16 +651,65 @@
 .util;%0A%0A
+import io.shardingsphere.core.constant.RuleType;%0A
 import i
@@ -763,16 +763,16 @@
 tement;%0A
-
 import i
@@ -1167,16 +1167,34 @@
  SQL log
+ for sharding rule
 .%0A     *
@@ -1463,32 +1463,81 @@
 ecutionUnits) %7B%0A
+        log(%22Rule Type: %7B%7D%22, RuleType.Sharding);%0A
         log(%22Log
@@ -1992,24 +1992,24 @@
 terSets());%0A
-
             
@@ -2027,24 +2027,486 @@
 %0A    %7D%0A    %0A
+    /**%0A     * Print SQL log for master slave rule.%0A     *%0A     * @param logicSQL logic SQL%0A     * @param dataSourceNames data source names%0A     */%0A    public static void logSQL(final String logicSQL, final Collection%3CString%3E dataSourceNames) %7B%0A        log(%22Rule Type: %7B%7D%22, RuleType.MasterSlave);%0A        log(%22Logic SQL: %7B%7D%22, logicSQL);%0A        for (String each : dataSourceNames) %7B%0A            log(%22Actual SQL: %7B%7D ::: %7B%7D%22, each, logicSQL);%0A        %7D%0A    %7D%0A    %0A
     private 

add logSQL for master slave.