Grails 1.1.1 log4j DSL 对 PatternLayout 配置抛出 MissingMethodException

发布于 2024-08-13 20:25:14 字数 1113 浏览 1 评论 0原文

我已将 Grails 1.0.3 应用程序升级到 Grails 1.1.1。我已升级 Config.groovy 中的 log4j 配置以符合 新 DSL。但是,在使用 PatternLayout 定义 ConsoleAppender 后,应用程序将不会启动,而是抛出 MissingMethodException 并显示以下消息:(

groovy.lang.MissingMethodException: No signature of method: \
groovy.util.ConfigSlurper$_parse_closure5.pattern() is applicable \
for argument types: (java.util.LinkedHashMap) \
values: [[conversionPattern:%d{ISO8601} [%10.10t] [%18.18c] [%5p] - %m%n]]

为了便于阅读,我将上述消息分成多行)。

我的配置是:

environments {
  development {
    log4j {
      appenders {
        console name: 'myAppender',
                layout: pattern(conversionPattern: '%d{ISO8601} [%10.10t] [%18.18c] [%5p] - %m%n')
        ...
      }
      root {
        error 'myAppender'
        additivity = true
      }
      error 'org.codehaus.groovy.grails.plugins',
            'org.codehaus.groovy.grails.orm.hibernate',
      ...
  }
  ...
}

我尝试更改模式,为 console() 函数添加括号,但没有成功。 是什么原因导致此异常?

I've upgraded a Grails 1.0.3 app to Grails 1.1.1. I've upgraded the log4j configuration in Config.groovy to conform to the new DSL. However, after defining a ConsoleAppender with a PatternLayout, the application won't start, and instead throws a MissingMethodException with the message:

groovy.lang.MissingMethodException: No signature of method: \
groovy.util.ConfigSlurper$_parse_closure5.pattern() is applicable \
for argument types: (java.util.LinkedHashMap) \
values: [[conversionPattern:%d{ISO8601} [%10.10t] [%18.18c] [%5p] - %m%n]]

(I broke the above message into multiple lines for readability).

My configuration is:

environments {
  development {
    log4j {
      appenders {
        console name: 'myAppender',
                layout: pattern(conversionPattern: '%d{ISO8601} [%10.10t] [%18.18c] [%5p] - %m%n')
        ...
      }
      root {
        error 'myAppender'
        additivity = true
      }
      error 'org.codehaus.groovy.grails.plugins',
            'org.codehaus.groovy.grails.orm.hibernate',
      ...
  }
  ...
}

I've tried changing the pattern, adding parentheses for the console() function, but with no success. What's causing this Exception?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

西瓜 2024-08-20 20:25:14

事实证明我在配置中错过了一个等号。解决方案是更改:

log4j {
  ...
}

与文档中的示例相比,一旦您看到它,就会发现它是

log4j = {
  ...
}

非常明显的解决方案,但是当您在 DSL 中的特定闭包/方法中遇到错误时,这些错误并不能明显看出真正的问题问题是。

Turns out I had missed an equals sign in the configuration. The solution was to change:

log4j {
  ...
}

to

log4j = {
  ...
}

Pretty obvious solution once you see it as compared to the examples in the documentation, but when you're getting errors for specific closures/methods within the DSL, the errors don't make it obvious what the real issue is.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文