简体   繁体   English

IntelliJ IDEA 中的自动“log.info”完成?

[英]Automatic `log.info` completion in IntelliJ IDEA?

I am using Java and I log things like:我正在使用 Java 并记录以下内容:

log.info("createArticle userId={} articleId={} title={} content={}", userId, articleId, title, content);

As you can see, when inputting this line into my IDE, I have to manually write down those characters like "userId={} " .如您所见,当将此行输入我的 IDE 时,我必须手动写下这些字符,例如"userId={} " Ideally, I hope I can simply type the userId , and Intellij IDEA will automatically help me fill out both "userId={} " (in the format string) and , userId (in the arguments list).理想情况下,我希望我可以简单地输入userId ,Intellij IDEA 会自动帮我填写"userId={} " (格式字符串)和, userId (arguments 列表)。

Question: How can I do that in IntelliJ IDEA?问题:如何在 IntelliJ IDEA 中做到这一点? Or, is there any other ways to type such logging lines faster ?或者,是否有任何其他方法可以更快地键入此类日志记录行?

Thanks for any suggestions!感谢您的任何建议!

It is possible to implement it with Live Templates and groovyScript for one of the variables: take the second segment, split it by comma, concat in something like part=${part} :可以使用Live TemplatesgroovyScript为其中一个变量实现它:取第二段,用逗号分隔,连接为part=${part}之类的东西:

groovyScript("_1.split(',').collect { it.trim() + '={}' }.join(' ')", B)

在此处输入图像描述

See video视频

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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