How to apply System.out.printf(...) inspection hint to a custom function

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!

2 comments
Comment actions Permalink

This is not really an answer but I think I obtained the same effect with minimal change.

Here is what I did:

  1. Migrated from JCL -> slf4j
  2. Changed my parameterized logging from printf format (%s %d) to the slf4j format (using {} parameter markers)
    1. This was much easier than I had anticipated thanks to IntelliJ's awesome search/replace and structural search/replace
  3. Simplified my BaseLogger so that all it provided was a protected Logging object
  4. Installed the Log Support plugin by Juergen Kellerer: https://plugins.jetbrains.com/plugin/4953?pr=


That's it. Now I get what I wanted: Highlighting missing arguments when logging with parameters!

0
Comment actions Permalink

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.

0

Please sign in to leave a comment.