package com.dd.admin.common.logs;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.p6spy.engine.spy.appender.MessageFormattingStrategy;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class P6SpyLogger implements MessageFormattingStrategy {

    @Override
    public String formatMessage(int connectionId, String now, long elapsed, String category,
                                String prepared, String sql, String url) {
        return StringUtils.isNotBlank(sql) ? now +" Execute Times："+ elapsed + " ms " +
                "Execute SQL：\n"+ sql.replaceAll("[\\s]+", " ") + "\n" : "";
    }
}
