SLF4J의 가변 인자는 플레이에 2.1 프레임 워크/스칼라을이 간단한 예제를 수행하려고 내 자바 작업Play2.1 프레임 워크에서 SLF4J varargs를 어떻게 활용합니까? 로깅 호출에
Logger log = LoggerFactory.getLogger(getClass());
log.debug("Hello, {}. The current time is {}", "robert", new Date());
에 매우 유용하며 나는 나를 거부하는 컴파일러로 실행합니다.
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
오류 란 무엇이며 어떻게 SLF4J API를 호출 할 수 있습니까? 내가 할 수 없다면, 어떻게 로깅 호출에서 varargs를 얻기 위해 Play 2.1 로깅 프레임 워크를 사용할 수 있습니까? 스칼라 랜드에서 뭔가 이상한 것이 있습니다.
위 답변입니다. 롤백은 나를위한 옵션이 아닙니다. 록 : 하드 플레이스. SLF4J의 API를 포기하고 Scala의 String.format에서 내 가변성을 가져야하는 것처럼 보입니다. 나는 SLF4J의 "{}"과 Java의 String.format의 벤치 마크를 수행했으며 SL4J가 위에 나왔습니다. 너무 나쁜 나는 가장 낮은 성능의 경로에 붙어있는 것 같습니다. 어쩌면 벤치 마크를 다시 실행하여 실제로 그렇게 나쁠 지 지켜 볼 시간입니다. –