我对 grails 中的 log4j 有点困惑。
我需要将信息记录到 info.log,将错误记录到 error.log,将警告记录到 warning.log
如果可能,所有文件(信息、警告和错误)应放入 web-app/ 这样我就可以通过互联网(VPN)进行检查
有人可以帮我做到这一点吗?
最佳答案
假设您使用的是 Grails 1.1+,那么:
appenders {
file name:'infoLog', file:'info.log', threshold: org.apache.log4j.Level.INFO
file name:'warnLog', file:'warn.log', threshold: org.apache.log4j.Level.WARN
file name:'errorLog', file:'error.log', threshold: org.apache.log4j.Level.ERROR
}
root {
info 'infoLog','warnLog','errorLog'
}
通过此配置,info.log
将包含级别为 INFO 及以上的所有日志消息(即 INFO、WARN、ERROR、FATAL),warn.log
将包含 WARN 及以上内容,error.log
将包含 ERROR 及以上内容。
在上面的示例中,我配置了根记录器,因此所有内容(包括 Grails 核心)都会被记录。当然,如果您愿意,您可以更细粒度地进行配置。
希望这有帮助。
关于java - 如何将 log4j 设置为每个错误/警告/信息的特定文件(在 grails 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1068687/