scala – 如何利用Play2.1框架中的SLF4J varargs登录?
发布时间:2020-12-16 08:54:52 所属栏目:安全 来源:网络整理
导读:SLF4J关于日志调用的变量在我的 Java工作中非常有用 Logger log = LoggerFactory.getLogger( getClass() );log.debug( "Hello,{}. The current time is {}","robert",new Date() ); 试图在Play 2.1 Framework / Scala中做这个简单的例子,我遇到编译器拒绝我.
|
SLF4J关于日志调用的变量在我的
Java工作中非常有用
Logger log = LoggerFactory.getLogger( getClass() );
log.debug( "Hello,{}. The current time is {}","robert",new Date() );
试图在Play 2.1 Framework / Scala中做这个简单的例子,我遇到编译器拒绝我. 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 {}",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 {}",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?如果我不能这样做,我如何使用Play 2.1 Logging Framework来获取日志记录调用的变量? Scala-land中有些东西不对. 解决方法
您使用的是什么版本的SLF4J?如果您可以返回1.6.6或更高版本,则可以避免出现这种问题.不幸的是,这两个签名看起来与scala完全相同,编译器似乎无法区分你的意思.常见的建议是回滚到SLF4J的一个版本(如果可能的话),这个重载的方法歧义将不存在.更多信息可以在以下链接中找到:
https://groups.google.com/forum/?fromgroups#!topic/scala-language/ms4IVIu-xGw https://github.com/typesafehub/scalalogging/issues/16 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
