简体   繁体   中英

IntelliJ IDEA Live Template to generate log statement

@Slf4j    
public class LogGenerator {
        public void testLog() {
            String customVariable1 = "Hello";
            String customVariable2 = "World";
    
            log.info("LogGenerator::testLog, customVariable1 : {}, customVariable2 : {}", customVariable1, customVariable2);
        }
    }

Is there any way to generate the log statement using a Live Template hotkey?

step1:add template text enter image description here

step2:Edit variables, METHOD_NAME are defined by IDEA, you just need to change the default value of ARGUMENTS. enter image description here

step3: add groovy script to default value

groovyScript(" def result=''; def result1=''; def params="${_1}".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList(); for(i = 0; i < params.size(); i++) { result1 += ', ' + params[i]; if (i==0) { result+='+" ' + params[i] + ': {}, '; } else { result+= params[i] + ': {}, '; } }; return result + '" ' + result1; ", methodParameters());}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM