11

When using

log.trace("with name {}, duration {}, repetitions {}", name, duration, repetitions);

SLF4J complains as follows

[javac] sourcefile.java:105: error: incompatible types: String cannot be converted to Marker
[javac] log.trace("with name {}, duration {}, repetitions {}",
[javac] ^
[javac] Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
[javac] 1 error

Using

log.trace("with name {}, duration {}, repetitions {}",
      new Object[]{name, duration, repetitions});

solves the problem, yet seems kludgey. (Especially since the API allows varargs).

Going by this answer seems to say that upgrading to SLF4J 1.7 would solve the problem, yet the android-slf4j is at 1.6.1.

Is there a way to use the varargs constructor in SLF4J for Android? Is there an alternative?

Community
  • 1
  • 1
serv-inc
  • 35,772
  • 9
  • 166
  • 188

2 Answers2

2

Seems like a bug in the API.

Varargs are used, but for the Marker methods there are also defined methods with 1, 2 and 3 arguments.

log.trace(Marker, Object...)
log.trace(Marker, Object)
log.trace(Marker, Object, Object)
log.trace(Marker, **Object**, Object, Object)

However the String APIs, only have varargs and 1 and 2 arg methods.

log.trace(String, Object...)
log.trace(String, Object)
log.trace(String, Object, Object)

For me Varargs do work with 1, 2, or 4, arguments.

Its only a problem with 3 arguments.

Its fixed in 1.7 by changing the highlighted Object to a String.

teknopaul
  • 6,505
  • 2
  • 30
  • 24
1

Try solving your problem with following sample code:

log.trace("with name {0}, duration {1}, repetitions {2}", name, duration, repetitions);
avocato
  • 211
  • 3
  • 11