问题描述
我正在考虑将第三方Java应用程序连接到我们的日志聚合/分析解决方案(可能是Splunk,但我们还没有完成我们的选择)。将Splunk代理挂钩到syslog似乎是最简单的,所以我正在寻找一种方法将应用程序日志重定向到服务器上的本地syslog守护程序。
I'm looking into hooking up a 3rd party Java application to our log aggregation/analysis solution (probably Splunk, we haven't finalized our selection yet though). It seems to be easiest to hook the Splunk agent to syslog, so I'm looking for a way to redirect the application logs to a local syslog daemon on the server.
Java应用程序使用java.util.logging,遗憾的是它没有开箱即用的syslog处理程序(我相信log4j确实如此)。有没有经过验证的库可以做到这一点?日志负载不是很大(每个进程大概每分钟10-20条消息,每个主机最多6个进程)但我关注可靠性和持久性(例如当守护进程停止时会发生什么?...)。
The Java application uses java.util.logging, which unfortunately does not feature a syslog handler out of the box (I believe log4j does, though). Are there any proven libraries to do this? The log load isn't huge (probably 10-20 messages per minute from each process, up to 6 processes per host) but I'm concerned with reliability and durability (e.g. what happens when the daemon is down?...).
任何帮助都将不胜感激...
Any help would be appreciated...
推荐答案
SLF4J有传递 java.util.logging的
您可以使用的SLF4J(以及log4j或logback)事件。它有性能成本(参见链接)但是考虑到你的负载,这应该不是什么大问题。那么你就可以使用Log4J的(或更好的继承者,,也有)。我对这个appender没有任何经验(所以这可能需要一些测试)但是logback绝对是一个可靠的库,我知道它可以配置为不使用nopexception或nopex打印堆栈跟踪(如果守护程序关闭时发送消息会产生一些异常)。将此appender与另一个appender(例如基于文件)耦合将允许不会丢失任何消息。
SLF4J has a bridge for passing java.util.logging
events to SLF4J (and hence to log4j or logback) that you could use. It has a performance cost (see the link) but given your load, this shouldn't be a big deal. So you could then use Log4J's SyslogAppender
(or better its successor, logback, which also has a SyslogAppender
). I do not have any experience with this appender (so this might require some testing) but logback is definitely a reliable library and I know that it can be configured to not print stack traces using the "nopexception" or "nopex" conversion word (in case sending messages when the daemon is down would generate some exception). Coupling this appender with another one (e.g. file based) would allow to not loose any message.
这篇关于是否有一个强大的syslog的java.util.logging处理程序实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!