Logback 中的条件功能如何工作?

2023-11-23

我使用这个 logback 配置文件:

<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%-10.-10thread] %-5level %-30logger{1} - %msg%n</pattern>
    </encoder>
  </appender>

<if condition='isDefined("fileout-dir")'><then>
  <appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender">
     <discriminator  class="edu.kit.sdq.storagebenchmarkharness.logging.SBHThreadDiscriminator"/>
    <sift>
      <appender name="FILE-${thread}" class="ch.qos.logback.core.FileAppender">
        <file>${fileout-dir:-}${thread}.log</file>
        <append>true</append>
        <layout class="ch.qos.logback.classic.PatternLayout">
          <pattern>%d{HH:mm:ss.SSS} %-5level %-30logger{1} - %msg%n</pattern>
        </layout>
      </appender>
    </sift>
  </appender>
  <root>
    <appender-ref>SIFT</appender-ref>
  </root>
 </then> </if>

  <root level="debug">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

运行我的应用程序时,出现以下错误:

org.codehaus.commons.compiler.CompileException: Line 1, Column 45: A method named "isDefined" is not declared in any enclosing class nor any supertype, nor through a static import
    at org.codehaus.commons.compiler.CompileException: Line 1, Column 45: A method named "isDefined" is not declared in any enclosing class nor any supertype, nor through a static import
    at  at org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:9014)
    at  at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:6549)
    at  at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:3429)
    at  at org.codehaus.janino.UnitCompiler.access$6300(UnitCompiler.java:104)
    at  at org.codehaus.janino.UnitCompiler$11.visitMethodInvocation(UnitCompiler.java:2869)
    at  at org.codehaus.janino.Java$MethodInvocation.accept(Java.java:2831)
    at  at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:2890)
    at  at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:3897)
    at  at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:1637)
    at  at org.codehaus.janino.UnitCompiler.access$1700(UnitCompiler.java:104)
    at  at org.codehaus.janino.UnitCompiler$5.visitReturnStatement(UnitCompiler.java:877)
    at  at org.codehaus.janino.Java$ReturnStatement.accept(Java.java:1803)
    at  at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:888)
    at  at org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:914)
    at  at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1999)
    at  at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:789)
    at  at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:770)
    at  at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:464)
    at  at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:357)
    at  at org.codehaus.janino.UnitCompiler$3.visitPackageMemberClassDeclaration(UnitCompiler.java:312)
    at  at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:770)
    at  at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:319)
    at  at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:288)
    at  at org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java:393)
    at  at org.codehaus.janino.ClassBodyEvaluator.compileToClass(ClassBodyEvaluator.java:311)
    at  at org.codehaus.janino.ClassBodyEvaluator.cook(ClassBodyEvaluator.java:224)
    at  at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:194)
    at  at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:80)
    at  at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:72)
    at  at ch.qos.logback.core.joran.conditional.PropertyEvalScriptBuilder.build(PropertyEvalScriptBuilder.java:34)
    at  at ch.qos.logback.core.joran.conditional.IfAction.begin(IfAction.java:43)
    at  at ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:273)
    at  at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:145)
    at  at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:127)
    at  at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:40)
    at  at ch.qos.logback.core.joran.spi.Interpreter.play(Interpreter.java:332)
    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:126)
    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:93)
    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:52)
    at  at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:60)
    at  at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:121)
    at  at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)
    at  at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
    at  at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121)
    at  at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
    at  at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:268)
    at  at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:241)
    at  at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254)
    at  at edu.kit.sdq.storagebenchmarkharness.Logger.getLogger(Logger.java:44)
    at  at edu.kit.sdq.storagebenchmarkharness.BenchmarkController.<clinit>(BenchmarkController.java:66)

为什么是方法isDefined未知?这回溯文档声明它应该存在,并且至少一次堆栈溢出线程似乎使用它。

我在类路径中包含了最新版本的 janino,因为表达式的求值需要它。正如您在错误消息中看到的那样,janino 编译器已加载。


确保您使用的是最新版本的 logback。另外,在logback中使用条件语句需要 Janino 库.

将其添加到您的 pom.xml 文件中以获取依赖项:

    <!-- The org.codehaus.janino:commons-compiler:2.6.1 dependency -->
    <!-- will be automatically pulled in by Maven's transitivity rules -->
    <dependency>
        <groupId>org.codehaus.janino</groupId>
        <artifactId>janino</artifactId>
        <version>2.6.1</version>
    </dependency>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Logback 中的条件功能如何工作? 的相关文章

随机推荐

  • Outlook .MSG 和 .OFT 文件格式之间有区别吗?

    这个问题有点遥远 但我花了几个小时却无济于事 我有一些代码可以在网络服务器上生成电子邮件文件 并允许用户下载该电子邮件并在 Outlook 中打开它 从这里 他们可以在将电子邮件发送给一群人之前对电子邮件进行各种手动更改 现在 我生成一个
  • 当将对象作为参数传递时,它们是通过引用传递的吗?

    如果我执行以下任一操作 是否会对性能产生影响 def do something user article end versus def do something user id article id end 我更喜欢传递对象 因为我可能需要
  • D3.js 的最大数据文件大小

    D3js 数据文件大小的限制因素是什么 文件从服务器加载到客户端需要多长时间 我正在尝试创建芝加哥的路线图 您可以将鼠标悬停在道路上以获取其名称并突出显示它 来自城市的文件大小为 125 MB 我通过删除不必要的信息将其缩减至 30 MB
  • 升级到 EF 6 (RTM) - 获取 System.Data.Entity.Core.Objects.ObjectContext 不能用于返回类型 System.Data.Objects

    刚刚升级了 NET 4 5 WCF 服务 该服务还有一个使用 EF 6 的 OData 服务 OData 服务当然在升级之前可以正常工作 现在 当尝试查询 OData 服务或什至只是从 Visual Studio 2012 浏览到它时 我得
  • 如何从 Android 联系人列表中获取 Skype 信息?

    使用联系人合同内容提供程序的新手 我正在尝试从我的应用程序中进行 Skype 通话 但我不知道如何从 Android 联系人中获取 Skype 信息 我正在通过 ContentResolver 运行查询以获取联系人的所有数据 但我不知道如何
  • 为什么 printf 和 sprintf 在仅给定数组时表现不同?

    sub do printf printf sub do sprintf print sprintf do printf s n ok prints ok do sprintf s n ok prints 2 sprintf有原型 while
  • 使用 jQuery 获取元素类型

    是否可以使用 jQuery 找出元素的类型 例如 元素是 div span select 还是 input 例如 如果我尝试使用 jQuery 将值加载到下拉列表中 但相同的脚本可以将代码生成到一组单选按钮中 我可以创建类似以下内容的内容
  • 如何解决运算符“!=”不能应用于“T”和“T”类型的操作数[重复]

    这个问题在这里已经有答案了 此代码片段按预期工作int type public class Test public int Value get gt Value set if Value value Value value private
  • iOS:如何实现手写识别?

    开始iOS开发 我希望在我的应用程序中实现手写识别 我进行了谷歌搜索 但没有找到任何在 Objective C 中实现文本手势的教程 有没有可用的基本教程来实现文本手势 例如 当用户写入时A在屏幕上 屏幕应该显示A 这个项目有可用的演示教程
  • VBA数组排序功能?

    我正在寻找 VBA 中数组的合适排序实现 快速排序将是首选 或任何其他排序算法除了泡沫或合并就足够了 请注意 这是为了与 MS Project 2003 一起使用 因此应避免任何 Excel 本机函数和任何 net 相关的内容 Take a
  • 对 NSMutableDictionary 进行排序

    我有一个NSMutableDictionary那个映射NSString to NSString 尽管这些值是NSStrings 它们实际上只是整数 例如考虑以下映射 dog gt 4 cat gt 3 turtle gt 6 我希望最终得到
  • Android WebView SSL“安全警告”

    我正在为客户构建应用程序的测试版本 此应用程序的一部分使用调用基于 SSL 的站点的 WebView 反过来 客户端提供了一个测试域 其中证书名称与 FQDN 不匹配 唉 他们无法提供匹配的证书 我正在使用一行代码在配套的 iOS 特别应用
  • 远程访问 Team Foundation Server 2010

    我们是四个位于不同地点 彼此半径 100 公里 的开发人员 尝试在软件开发项目上进行合作 我们希望在一台计算机上安装 Team Foundation Server 2010 我们都使用 Windows 7 并将其用作我们的中央源代码存储库和
  • Jquery 正则表达式验证

    我想检查输入字段是否具有 模式 属性 如果是 则针对所述模式执行正则表达式检查 我知道 HTML5 已经完成了这一操作 但我想自己处理该事件 我收到此错误 未捕获的类型错误 对象 a zA Z 没有方法 测试 Check Perform R
  • 在主视图控制器的自定义单元格内使用 UIButton 中的 IBAction

    我创建了一个带有自己的 m h 和 xib 文件的自定义单元 在单元格中 我有一个 UIButton 已添加到 IB 中的 xib 中 我可以从这个自定义单元格的 m 中的 UIButton 接收 IBAction 但实际上 我想将该按钮按
  • Android - 获取计时器小部件的时间

    如何从天文台表获取时间 我尝试了 getText getFormat getBase 等 但它们都不起作用 示例代码片段 Chronometer t Chronometer findViewById R id toptime long ti
  • Object.toString 和 Object.prototype.toString 之间的不同

    我们可以用Object prototype toString call foo 检测对象类 foo 的类型 并且效果很好 但为什么Object toString call throw TypeError Function prototype
  • 日期时间选择器验证

    我很抱歉发布这个问题 因为它可能对所有人来说都很愚蠢 但我没有得到确切的解决方案 问题是 我的项目中有一个日期时间选择器 它位于表单中的 3 个文本框之后 如果文本框中没有输入任何文本并在提交时输入 它会给出一条消息 验证 表明数据将被进入
  • 当属性达到目的时,标记接口需要什么?

    我有点困惑 标记接口 Vs 的目的 属性 他们的目的在我看来是一样的 如果我错了 请原谅我 谁能解释一下它们的目的有何不同 以下是两者的一些优点 标记接口 使用动态类型检查更容易检查 对象是 IMarker 允许未来的功能和数据可扩展性 即
  • Logback 中的条件功能如何工作?

    我使用这个 logback 配置文件