是否有一个健壮的 java.util.logging 处理程序实现 syslog?
我正在考虑将第 3 方 Java 应用程序连接到我们的日志聚合/分析解决方案(可能是 Splunk,但我们尚未最终确定我们的选择)。将 Splunk 代理挂接到 syslog 似乎是最简单的方法,因此我正在寻找一种将应用程序日志重定向到服务器上的本地 syslog 守护进程的方法。
Java 应用程序使用 java.util.logging,遗憾的是它没有现成的 syslog 处理程序(不过我相信 log4j 有)。有没有经过验证的库可以做到这一点?日志负载并不大(每个进程每分钟可能有 10-20 条消息,每个主机最多 6 个进程),但我关心可靠性和持久性(例如,当守护进程关闭时会发生什么?...)。
任何帮助将不胜感激...
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.
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SLF4J 有一个 bridge 用于传递
java.util.logging< /code> 您可以使用的 SLF4J(以及 log4j 或 logback)事件。它具有性能成本(请参阅链接),但考虑到您的负载,这应该不是什么大问题。因此,您可以使用 Log4J 的
SyslogAppender< /code>
(或者更好的是它的后继者 logback,它也有一个
SyslogAppender
)。我对这个附加程序没有任何经验(所以这可能需要一些测试),但 logback 绝对是一个可靠的库,我知道它可以配置为不使用“nopexception”或“nopex”打印堆栈跟踪 转换词(以防在守护进程关闭时发送消息会产生一些异常)。将此附加程序与另一个附加程序(例如基于文件的)耦合将允许不会丢失任何消息。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'sSyslogAppender
(or better its successor, logback, which also has aSyslogAppender
). 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.我们的项目也使用 java.util.Logging 机制,因此,在花了一些时间找到 syslog 协议的现成处理程序实现之后,我最终阅读了 RFC 3164 并创建了自己的实现 http://code.google.com/p/agafua-syslog/
我们在生产中使用它,支持 UDP 和 TCP 传输。在我们的示例中,日志消息流约为每秒 1-2 条消息,因此我想它可能适合您的需求。
Our project is also using java.util.Logging mechanism, so, after spending some time to find the ready Handler implementation for syslog protocol, I ended up by reading RFC 3164 and creating my own implementation http://code.google.com/p/agafua-syslog/
We using it in production, both with UDP and TCP transports. In our case flow of log messages is approximately 1-2 msg per second, so I guess it is probably applicable for your needs.