How to apply System.out.printf(...) inspection hint to a custom function
Answered
Hi,
IntelliJ will offer fantastic inspection hints for the following:
System.out.printf("%.2f - %s", 10f, 5);
Which will indicate that the format string does not match the type of its arguments. I love this.
I have a BaseLogger class that I use throughout many applications which takes a log4j logger and decorates it with functions like the following:
protected void info(String format, Object... args) {
log.info(String.format(format, args));
}
protected void debug(String format, Object... args) {
log.debug(String.format(format, args));
}
These functions allow me to log via string format with varargs.
The only problem is, I have no way of visually knowing when I have not fulfilled the format contract like I do with System.out.printf(...).
How can I get IntelliJ to use the same validation on my custom BaseLogger methods?
Thanks!
Please sign in to leave a comment.
This is not really an answer but I think I obtained the same effect with minimal change.
Here is what I did:
That's it. Now I get what I wanted: Highlighting missing arguments when logging with parameters!
It seems that ReSharper supports defining custom string formatting methods: http://https://www.jetbrains.com/resharper/help/Code_Analysis__String_Formatting_Methods.html
But I can't find similar support in Intellij IDEA.
I am still very interested in this
Have you checked Lombok plugin? It should be helpful for logging: https://plugins.jetbrains.com/plugin/6317-lombok . Laos please check this thread: https://github.com/mplushnikov/lombok-intellij-plugin/issues/154 .