grails - 在Grails中的单独文件中记录log4j消息

标签 grails logging

我正在尝试在/logs/mylog.log中的单独文件中记录log4j日志(信息和调试)。我在Grails项目的文件夹结构中的WEB-INF下创建了“logs / mylog.log。我还在Config.groovy中添加了附加程序。下面是我的config.groovy中log4j = {}内的log4j条目。

appenders {
    console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
    file name:'grailslog', file:'/logs/mylog.log', threshold:org.apache.log4j.Level.DEBUG, org.apache.log4j.Level.INFO
}

root { debug 'stdout', 'file'     }

error  'org.codehaus.groovy.grails.web.servlet',        // controllers
       'org.codehaus.groovy.grails.web.pages',          // GSP
       'org.codehaus.groovy.grails.web.sitemesh',       // layouts
       'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
       'org.codehaus.groovy.grails.web.mapping',        // URL mapping
       'org.codehaus.groovy.grails.commons',            // core / classloading
       'org.codehaus.groovy.grails.plugins',            // plugins
       'org.codehaus.groovy.grails.orm.hibernate',      // hibernate integration
       'org.springframework',
       'org.hibernate',
       'net.sf.ehcache.hibernate',
       'com.test'

info   'com.test.nip'

//trace 'org.hibernate.type'
debug 'org.hibernate.SQL'

debug   'com.test.nip.pacs'

environments {
    production {
        debug   'com.test',
                'org.springframework.security'
    }
}

但是在这里,当我启动服务器时,出现“/logs/mylog.log”文件未找到错误。

最佳答案

当您在安装服务器的系统中使用路径/logs/mylog.log引用日志文件时,您使用的是绝对路径,这并不意味着它位于WEB-INF下,因此将日志文件放在WEB-INF下是个好主意,因为该文件将被删除为你发动新的 war 。

可能的解决方案:

  • 在系统根目录下创建/log目录。
  • 确保服务器进程具有足够的权限来创建和写入/log目录。如果没有,请授予其权限。

  • How to add a rolling file appender?


    rollingFile name: "file",
     maxFileSize: 5000000,
     file: "/log/mylog.log",
     threshold: org.apache.log4j.Level.DEBUG
    

    它被完整记录在official doc中。

    关于grails - 在Grails中的单独文件中记录log4j消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30498940/

    相关文章:

    c# - 从本地 Service Fabric 应用程序登录到 Azure 存储模拟器

    ios - iOS中的App Store应用提交问题

    grails - 检查约束Grails数据库迁移脚本

    grails - 跨多个域类的Grails过滤和排序

    升级到 2.3.5 后不再调用 BootStrap 中添加的 Grails 事件方法

    grails - 使用元类覆盖Domain中的gorm方法

    unit-testing - 为什么没有空格的字段不只包含空格值:错误约束失败验证

    linux - 分析dnsmasq的日志文件

    具有前端的 Java 简单分析/事件流处理

    android - LogCat 中的过滤标签(在 Android Eclipse 插件中)