package com.schisandra.system.infra.config;

import com.mybatisflex.core.audit.AuditManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;

/**
 * @Classname MyBatisFlexConfiguration
 * @BelongsProject: schisandra-cloud-storage
 * @BelongsPackage: com.schisandra.oss.infra.config
 * @Author: landaiqing
 * @CreateTime: 2024-05-31  16:14
 * @Description: Mybatis flex 配置类
 * @Version: 1.0
 */
@Configuration
public class MyBatisFlexConfiguration {
    private static final Logger logger = LoggerFactory
            .getLogger("mybatis-flex-sql");


    public MyBatisFlexConfiguration() {
        //开启审计功能
        AuditManager.setAuditEnable(true);

        //设置 SQL 审计收集器
        AuditManager.setMessageCollector(auditMessage ->
                logger.info("{},{}ms", auditMessage.getFullSql()
                        , auditMessage.getElapsedTime())
        );
    }
}
