神器雖好,logger的插件卻比較難找,網上找了個替代方案是通過live template,快速插入日志打印語句。
目前能做到的是:
1,聲明logger變量;
2,在方法入口處打印方法名和變量。
實現1:
在live template中新增名為logs的template group,然后新增live template,abbreviation填入自己喜歡的縮寫,我這里是logf。Applicable context選擇statement&expression&declaration,Template text輸入
private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger($CLASS_NAME$.class);

實現2:
新增一個live template,縮寫隨意,我稀飯logp。Template text:
LOG.debug("$METHOD_NAME$::$PLACE_HOLDERS$",$ARGUMENTS$);
點擊編輯變量,幾個變量的定義如下:
PLACE_HOLDERS = groovyScript("_1.collect { it + ' = [{}]'}.join(', ') ", methodParameters())
ARGUMENTS = groovyScript("_1.collect { it }.join(', ') ", methodParameters())
METHOD_NAME = methodName()

applicable context 選擇(Java-> Statment )
搞定,收工。
原文鏈接:http://artfulonline.blogspot.tw/2014/03/quick-logging-with-intellij-live.html
