如何将 log4j 设置为每个错误/警告/信息的特定文件(在 grails 中)

发布于 2024-07-25 11:19:49 字数 186 浏览 2 评论 0原文

我对 grails 中的 log4j 有点困惑。

我需要将信息记录到 info.log,将错误记录到 error.log,将警告记录到 warning.log(

如果可能),所有文件(信息、警告和错误)都应放入 web-app/ 这样我就可以通过互联网(VPN)进行检查

有人可以帮助我做到这一点吗?

I am little bit confuse about log4j in grails.

I need to log info into info.log, error into error.log and warning into warning.log

if possible, all the files (info,warning and error) should be placed into web-app/
so that i can do check via internet (vpn)

can someone help me to do that ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染柒℉ 2024-08-01 11:19:49

假设您使用的是 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 核心)都会被记录。 当然,如果您愿意,您可以对其进行更细粒度的配置。

希望这可以帮助。

Assuming you are using Grails 1.1+, what about:

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'
}

With this configuration, info.log will contain all log messages with level INFO and above (ie. INFO, WARN, ERROR, FATAL), warn.log will contain WARN and above, error.log will contain ERROR and above.

In the example above, I have configured the root logger, so everything (including Grails core) gets logged. But of course, you can configure this more fine-grained if you want.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文