1

I want to print in catch block directly with logger like:

Logger.getLogger(Example.class.getName()).log(Level.SEVERE, null, ex);

I checked Velocity template in Settings - File and Code Templates for Catch Statement body

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

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:

Logger.getLogger(Example.class.getName()).log(Level.SEVERE, null, ex);
Ranjit M
  • 138
  • 4
  • 4
  • 17

1 Answers1

0

It is not possible to use ${NAME} variable in Code Templates yet. You may try to use the following construction to get the class name:

Logger.getLogger(this.getClass().getName()).log(LEVEL.INFO,${EXCEPTION}.printStackTrace(),${EXCEPTION});

There is a similar request on JetBrains issues tracker: IDEA-55300

Egor Klepikov
  • 3,386
  • 5
  • 19
  • 34