使用Built-in formatting來創建log字符串


在一次哦測試中,sonar-qube總是報Use the built-in formatting to contruct this argument,

在網上查了一下,原來它是推薦這樣做:

log.info("#{} {} is completed.",index,task);

下面是全部代碼,供你參考:

package logbackCfg;

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

public class BuildinTester {
    private final static Logger log = LoggerFactory.getLogger(BuildinTester.class);
    
    public static void main(String[] args) {
        int index=3;
        String task="cleanExpiredData";
        
        // Traditional way to contruct a log msg
        log.info("#"+index+" "+task+" is completed.");
        
        // Built-in formatting to contruct a log msg
        log.info("#{} {} is completed.",index,task);
    }
}

--2020-02-28--


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM