我正在尝试在scala中使用log4j。我将log4j文件正确放置在资源目录中。
我遵循java
中遵循的相同log4j方法我的Java代码:这很好用。完全没问题
package pack1;
import org.apache.log4j.Logger;
public class SampleMain {
final static Logger logger = Logger.getLogger(SampleMain.class);
public static void main(String[] args) {
SampleMain lld = new SampleMain();
lld.log();
}
public void log() {
logger.fatal("This is fatal.");
logger.error("This is error.");
logger.warn("This is warn.");
logger.info("This is info.");
logger.debug("This is debug.");
logger.trace("This is trace.");
}
}
我的Scala代码:
import org.apache.log4j.Logger;
class SampleScala {
val logger = Logger.getLogger(SampleScala.class)//getting compile time error at this line .
def method1():Unit = {
}
}
object ScalaLogging {
def main(args: Array[String]): Unit = {
val obj = new SampleScala();
obj.method1()
}
}
编译时上述scala代码中的错误:
identifier expected but 'class' found.
所以我想知道下面java代码的等效scala语句是什么
final static Logger logger = Logger.getLogger(SampleMain.class);
答案 0 :(得分:0)
是
val logger = Logger getLogger classOf[SampleMain]