我正在尝试使用自定义布局类进行播放框架 2.0 logback 日志记录。
首先,我在 utils 包中定义了一个自定义布局类:
package utils;
public class MonitorLayoutForLogback extends LayoutBase<ILoggingEvent> {
...
}
在我的 conf/logging.xml 文件中,我输入:
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="utils.MonitorLayoutForLogback">
<param name="programName" value="uowVisualizer" />
<param name="serviceGroup" value="shared" />
<param name="serviceIdentifier" value="uowVisualizer" />
</layout>
</encoder>
</appender>
但是当我在游戏中奔跑时,例如,
play run
我懂了:
14:20:18,387 |-ERROR in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Could not create component [layout] of type [utils.MonitorLayoutForLogback] java.lang.ClassNotFoundException: utils.M
onitorLayoutForLogback
at java.lang.ClassNotFoundException: utils.MonitorLayoutForLogback
at at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at at java.security.AccessController.doPrivileged(Native Method)
at at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at at sbt.PlayCommands$$anonfun$53$$anonfun$55$$anon$2.loadClass(PlayCommands.scala:535)
at at ch.qos.logback.core.util.Loader.loadClass(Loader.java:124)
at at ch.qos.logback.core.joran.action.NestedComplexPropertyIA.begin(NestedComplexPropertyIA.java:100)
at at ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:276)
at at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:148)
at at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:130)
at at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:50)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:157)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:143)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:106)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:56)
at at play.api.Logger$$anonfun$configure$8.apply(Logger.scala:248)
at at play.api.Logger$$anonfun$configure$8.apply(Logger.scala:247)
at at scala.Option.map(Option.scala:145)
at at play.api.Logger$.configure(Logger.scala:247)
at at play.api.Application$class.$init$(Application.scala:266)
所以,play找不到我创建的布局类。如何将布局类放在类路径上?
请注意,我还尝试通过以下方式暂存项目,
play clean compile stage
然后通过
target/start
从打包版本启动项目,我没有看到上面的缺少类错误。但是,我也从来没有看到任何输出,我什至没有看到构建的类。我向此类的每个构造函数添加了 System.out.println 语句,如下所示,以验证是否正在构造该类:
public MonitorLayoutForLogback() {
System.out.println("MonitorLayoutForLogback Constructor without arguments");
}
public MonitorLayoutForLogback(String program) {
System.out.println("MonitorLayoutForLogback Constructor with program "+program);
_program = program;
}
public MonitorLayoutForLogback(String program, String sGroup, String sid) {
System.out.println("MonitorLayoutForLogback Constructor with program "+program+" sGroup "+sGroup+" sid "+sid);
_program = program;
MonitoringInfo.setServiceGroup(sGroup);
MonitoringInfo.setServiceIdentifier(sid);
}
我是 logback 配置的新手,所以我确定我遗漏了一些明显的东西。谢谢您的帮助。