在Play 2中,我使用此代码获取记录器:
public class LoggerHelper {
public static Logger getLogger() {
final Throwable t = new Throwable();
t.fillInStackTrace();
final String fullClassName = t.getStackTrace()[1].getClassName();
return Logger.getLogger(fullClassName);
}
}
public class MyController {
private final static Logger logger = LoggerHelper.getLogger();
}
在Play 2中,我发现的代码示例看起来像是为了让记录器看起来像这样:
class MyController {
private val log = Logger(classOf[MyController])
...
}
如何使其不包含类名?
答案 0 :(得分:4)
也许我误解了你的问题,但看起来你需要的只是
class MyController {
private val log = Logger(this.getClass)
...
}
还是我误解了你的需求?