使用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