I must be stupid or something, but I seem not to be able to use the varargs-utilizing parameterized logging methods of SLF4J. An 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 is a mighty exception!");
} catch(Exception e) {
logger.error("I wanna log {} and {} and {} with backtrace", x, y, 3, e);
}
}
}
On the logging method, eclipse produces such a warning:
The method error(String, Object, Object) in the type Logger is not applicable for the arguments (String, int, long, int, Exception)
and fails to compile.
However, if I change the logging call to:
logger.error("I wanna log {} and {} and {} with backtrace", new Object[]{x, y, 3, e});
It compiles and runs as expected (logging 3 "variables" and the exception stack trace).
The library versions are: slf4j-api-1.7.5.jar, slf4j-log4j12-1.7.5.jar and log4j-1.2.14.jar, if it makes any difference.
If anybody would point out the shortcomings of my thinking abilities, it'd be very much appreciated!