varargs del SLF4J sulle chiamate di registrazione sono molto utili nel mio lavoro JavaCome faccio a sfruttare le vararg SLF4J registrando nel framework Play2.1?
Logger log = LoggerFactory.getLogger(getClass());
log.debug("Hello, {}. The current time is {}", "robert", new Date());
Cercando di fare questo semplice esempio in Play 2.1 Framework/Scala e mi imbatto in compilatore mi rifiuto.
import play.api._
import play.api.mvc._
import org.slf4j.LoggerFactory
object Application extends Controller {
val log: org.slf4j.Logger = LoggerFactory.getLogger(getClass())
def hb = Action {
val message = makeMessage()
// COMPILER HATES THIS: ambiguous reference compiler error here
log.info("Hello {}. The current time is {}", "robert", new java.util.Date())
Ok(message)
}
def makeMessage(): String = { return "stuff" }
}
[dm2-server] $ compile
[info] Compiling 2 Scala sources to /Users/bobk/work/dm2-server/target/scala-2.10/classes...
[error] /Users/bobk/work/dm2-server/app/controllers/Application.scala:16: ambiguous reference to overloaded definition,
[error] both method info in trait Logger of type (x$1: String, x$2: <repeated...>[Object])Unit
[error] and method info in trait Logger of type (x$1: String, x$2: Any, x$3: Any)Unit
[error] match argument types (String,String,java.util.Date)
[error] log.info("Hello {}. The current time is {}", "robert", new java.util.Date())
[error] ^
[error] one error found
[error] (compile:compile) Compilation failed
[error] Total time: 1 s, completed Jun 6, 2013 10:54:41 AM
Qual è l'errore e come si supera per richiamare l'API SLF4J? Se non riesco a farlo, come posso utilizzare il framework di registrazione di Play 2.1 per ottenere vararg sulle mie chiamate di registrazione? Qualcosa non è giusto in Scala-land.
Ottima risposta. Il rollback non è un'opzione per me. Rock: Hard Place. Sembra che devo rinunciare all'API di SLF4J e ottenere la mia vararità dal String.format di Scala. Ho fatto benchmark in passato su "{}" di SLF4J rispetto a String.format di Java e SL4J ne è uscito in cima. Peccato, mi sembra di essere bloccato con il percorso delle prestazioni più basse. Forse è il momento di rieseguire i benchmark per vedere se è effettivamente così male. –