在Grails

时间:2015-05-28 06:37:25

标签: grails logging

我正在尝试将log4j日志(信息和调试)放在/logs/mylog.log中的单独文件中。我在Grails项目的文件夹结构中创建了WEB-INF下的" logs / mylog.log。我还在Config.groovy中添加了appender。下面是我在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'找不到文件错误当我启动我的服务器时。

1 个答案:

答案 0 :(得分:1)

当您使用路径/logs/mylog.log引用日志文件时,您在服务器所使用的系统中使用了绝对路径,这并不意味着它位于WEB-INF之下,同时将日志文件放在WEB-INF是个好主意,因为在部署新战争时该文件将被删除。

可能的解决方案:

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

    如何添加滚动文件追加器?

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

    official doc已详细记录。