java - SLF4J parameterized logging using varargs method -


i must stupid or something, seem not able use varargs-utilizing parameterized logging methods of slf4j. example:

import org.slf4j.logger; import org.slf4j.loggerfactory;  public class loggingtest {      @test     public void loggingtest() {         logger logger = loggerfactory.getlogger(this.getclass());         int x = 0xdeadbeef;         long y = 0xdeadbeef;          try {             throw new exception("this mighty exception!");         } catch(exception e) {             logger.error("i wanna log {} , {} , {} backtrace", x, y, 3, e);         }     } } 

on logging method, eclipse produces such warning:

the method error(string, object, object) in type logger not applicable arguments (string, int, long, int, exception) 

and fails compile.

however, if change logging call to:

logger.error("i wanna log {} , {} , {} backtrace", new object[]{x, y, 3, e}); 

it compiles , runs expected (logging 3 "variables" , exception stack trace).

the library versions are: slf4j-api-1.7.5.jar, slf4j-log4j12-1.7.5.jar , log4j-1.2.14.jar, if makes difference.

if point out shortcomings of thinking abilities, it'd appreciated!

i did additional investigation, , way compile error

logger.error("i wanna log {} , {} , {} backtrace", x, y, 3, e); 

and not

logger.error("i wanna log {} , {} , {} backtrace", new object[]{x, y, 3, e}); 

is use version of slf4j api prior 1.7 (in support varargs introduced). need dig classpath (or server runtime?) find following statement fails true:

the library versions are: slf4j-api-1.7.5.jar, slf4j-log4j12-1.7.5.jar , log4j-1.2.14.jar, if makes difference.

(because makes precisely difference have observed)


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -