[英]How to change velocity template in Intellij for catch statement
I want to print in catch block directly with logger like:我想直接使用记录器在 catch 块中打印,例如:
Logger.getLogger(Example.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(Example.class.getName()).log(Level.SEVERE, null, ex);
I checked Velocity template in Settings - File and Code Templates for Catch Statement body我在 Settings - File and Code Templates for Catch Statement body 中检查了 Velocity 模板
By Default it is given with默认情况下,它与
${EXCEPTION}.printStackTrace()
Tried changing with:尝试更改:
Logger.getLogger(${NAME}.class.getName()).log(LEVEL.INFO,${EXCEPTION}.printStackTrace(),${EXCEPTION});
but the Logger statement is getting wrong while, NAME is not picking class Name as provided in guidelines: https://www.jetbrains.com/help/idea/file-template-variables.html但是 Logger 语句出错了,NAME 没有选择 class 指南中提供的名称: https://www.jetbrains.com/help/idea/file-template-variables.ZFC35FDC70D5FC69D269883A8
Want to automatically put logger statement in catch block whenever I am using try-catch block or try with resources block to catch such that it has like:每当我使用 try-catch 块或尝试使用资源块捕获时,想要自动将 logger 语句放入 catch 块中,这样它就有:
Logger.getLogger(Example.class.getName()).log(Level.SEVERE, null, ex);
It is not possible to use ${NAME} variable in Code Templates
yet.目前还不能在
Code Templates
中使用${NAME}变量。 You may try to use the following construction to get the class name:您可以尝试使用以下构造来获取 class 名称:
Logger.getLogger(this.getClass().getName()).log(LEVEL.INFO,${EXCEPTION}.printStackTrace(),${EXCEPTION});
There is a similar request on JetBrains issues tracker: IDEA-55300在 JetBrains 问题跟踪器上有一个类似的请求: IDEA-55300
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.