log4j 2 인쇄 로그 (지정 한 logger 특수 인쇄 포함)

log4j2.xml


    
        
            
        
        
            
                [%d{MM-dd HH:mm:ss SSS} %-5level] [%t] %c{3} - %m%n%ex
            
            
                
            
        


        
            
                %m%n
            

            
                
            
        
    
    


        
            
            
        

        
        
            
        
        
        
        
    




자바 류 SPLogUtils
package com.daojia.data.query.util;

import com.alibaba.fastjson.JSON;

import com.daojia.data.query.vo.SPLog;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Created by liquanyu on 2018-05-28
 */
public class SPLogUtils {
    //           logger  ,      eg:

    private static final Logger spLogger = LoggerFactory.getLogger("spLogger");
//    private static final Logger spLogger = LoggerFactory.getLogger(SPLogUtils.class);

    public static void log(String sql, Integer dsId) {

        spLogger.info(JSON.toJSONString(new SPLog(sql, dsId)));
    }
}


클래스 SPLog
package com.daojia.data.query.vo;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * Created with IDEA
 * description:
 * author:liquanyu
 * Date:2018/5/28
 * Time:10:48
 */
public class SPLog {
    private String logTime;
    private String sql;
    private Integer dsId;

    public SPLog(String sql, Integer dsId) {
        this.logTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.dsId = dsId;
        this.sql = sql;
    }

    public String getLogTime() {
        return logTime;
    }

    public void setLogTime(String logTime) {
        this.logTime = logTime;
    }

    public String getSql() {
        return sql;
    }

    public void setSql(String sql) {
        this.sql = sql;
    }

    public Integer getDsId() {
        return dsId;
    }

    public void setDsId(Integer dsId) {
        this.dsId = dsId;
    }
}

좋은 웹페이지 즐겨찾기