我正在尝试将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'找不到文件错误当我启动我的服务器时。
答案 0 :(得分:1)
当您使用路径/logs/mylog.log
引用日志文件时,您在服务器所使用的系统中使用了绝对路径,这并不意味着它位于WEB-INF
之下,同时将日志文件放在WEB-INF
是个好主意,因为在部署新战争时该文件将被删除。
可能的解决方案:
/log
目录。/log
目录。如果没有,请授予其权限。如何添加滚动文件追加器?
rollingFile name: "file",
maxFileSize: 5000000,
file: "/log/mylog.log",
threshold: org.apache.log4j.Level.DEBUG
official doc已详细记录。