收到信号时动态加载logback.xml文件

时间:2013-10-10 12:15:32

标签: java logback

在我的项目中,我使用logback进行日志管理。但是有一个问题让我困惑了两天,我已经尝试了很多方法来解决它,但没有结果。所以,我需要帮助:

项目启动时项目第一次加载“logback.xml”,没有错误。当项目在sun.misc.Signal方法中收到信号,然后重新加载“logback.xml”文件,这次发生错误。

“logback.xml”文件中控制台显示的错误是:

<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
    <evaluator>
        <expression>message.contains("imsi")</expression>
    </evaluator>
    <OnMismatch>DENY</OnMismatch>
    <OnMatch>ACCEPT</OnMatch>
</filter>

在Java中加载“logback.xml”的代码是:

LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator configurator = new JoranConfigurator();
lc.reset();
configurator.setContext(lc);
configurator.doConfigure("F:\\logback.xml");

控制台中的错误是:

02:12:21,859 |-ERROR in ch.qos.logback.classic.boolex.JaninoEventEvaluator@5d68fa45 -    Could not start evaluator with expression [message.contains("imsi")] org.codehaus.commons.compiler.CompileException: Line 1, Column 7: A class 'ch.qos.logback.classic.Level' could not be found
at org.codehaus.commons.compiler.CompileException: Line 1, Column 7: A class 'ch.qos.logback.classic.Level' could not be found
at org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:9779)
at org.codehaus.janino.UnitCompiler.getSingleTypeImport(UnitCompiler.java:8299)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:338)
at org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:320)
at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:1017)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:327)
at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:293)
at org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java:310)
at org.codehaus.janino.ClassBodyEvaluator.compileToClass(ClassBodyEvaluator.java:319)
at org.codehaus.janino.ScriptEvaluator.cook(ScriptEvaluator.java:563)
at org.codehaus.janino.ScriptEvaluator.cook(ScriptEvaluator.java:462)
at org.codehaus.janino.ScriptEvaluator.cook(ScriptEvaluator.java:374)
at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:178)
at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:80)
at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:73)
at org.codehaus.janino.ScriptEvaluator.<init>(ScriptEvaluator.java:147)
at ch.qos.logback.core.boolex.JaninoEventEvaluatorBase.start(JaninoEventEvaluatorBase.java:57)
at ch.qos.logback.core.joran.action.NestedComplexPropertyIA.end(NestedComplexPropertyIA.java:167)
at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:317)
at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:196)
at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:182)
at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:62)
at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:149)
at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:135)
at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:99)
at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:76)
at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:68)
at com.log.loader.LogbackConfigLoader.load(LogbackConfigLoader.java:43)
at com.log.servlet.OnloadStart.signalCallback(OnloadStart.java:51)
at com.log.servlet.OnloadStart.handle(OnloadStart.java:45)
at sun.misc.Signal$1.run(Signal.java:212)
at java.lang.Thread.run(Thread.java:724)

非常感谢~~

0 个答案:

没有答案