grails - Grails-如何将日志模式添加到文件追加器

标签 grails grails-2.0

我正在实现对应用程序的日志记录,我正在尝试向日志文件追加程序添加模式,

我的代码是这样的:

log4j = {
    appenders {

        //  append new appenders of your own and add log level and packages/files like to add.
        rollingFile name: "myAppender",
                    maxFileSize: 1024,
                    file: "C:/GrailsWS/BaseGrails/target/basegrails.log"//""basegrails.log"  //  C:\GrailsWS\BaseGrails\target\basegrails.log

        console name: "myAppender",
                layout: pattern(conversionPattern: "%c{2} %m%n")
    }

我正在关注Grails Logging页面,添加模式行之后,我的basegrails.log没有得到任何日志数据。

最佳答案

您不想具有相同名称的追加程序。我相信您想要做的就是给您的附加程序赋予不同的名称,然后根据需要应用转换模式。如果需要,可以使用通用模式定义变量。因此,类似:

log4j = {
    def commonPattern = "%c{2} %m%n"

    appenders {

        //  append new appenders of your own and add log level and packages/files like to add.
        rollingFile name: "rollingLog",
                maxFileSize: 1024,
                file: "C:/GrailsWS/BaseGrails/target/basegrails.log",
                layout: pattern(conversionPattern: commonPattern)

        console name: "stdout",
            layout: pattern(conversionPattern: commonPattern )
    }

    // then, use your appenders
    trace stdout ['grails.app', ...]
    debug rollingFile: ['your.package', ...]

}

关于grails - Grails-如何将日志模式添加到文件追加器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23882690/

相关文章:

grails - 删除按钮在Grails的list.gsp中不起作用

grails - 将 Grails 应用程序从 1.3.7 升级到 Java 8 兼容版本

grails - Grails删除 child

grails - Spring Security核心插件从1.3.x升级到2.0.4时出错

unit-testing - PageRenderer 在单元测试期间返回空对象

grails - 如何在grails 2.5.6中的运行时异常期间隔离单个delete(..)使其不回滚?

grails - 异步作业出错

email - 在grails发送邮件之前弹出Outlook消息

grails - 使用Dynamodb的Grails Spring 安全性

grails-orm - 类 [] 上的方法在 Grails 应用程序之外使用。如果在使用模拟 API 或引导 Grails 的测试上下文中正确运行