我正在尝试在/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/