使用 java.util.logging 处理程序记录到 syslog 的最现代方法是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6206936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the most modern way to log to syslog using a java.util.logging handler?
提问by
I am specifically looking for the most up to date, modern SysLogHandler
for java.util.logging
.
我特别在寻找最新的、现代SysLogHandler
的java.util.logging
.
I have found a few that date back to 2001 - 2003, mostly un-supported now.
我发现了一些可以追溯到 2001 - 2003 年的,现在大部分都不受支持。
I know that syslog
is a pretty static service, I am wondering before I write something myself, if there are any newer handler implementations that support the Java 1.5 and newer features.
我知道这syslog
是一个非常静态的服务,在我自己编写一些东西之前,我想知道是否有任何更新的处理程序实现支持 Java 1.5 和更新的功能。
I am notinterested in any of the other logging frameworks or wrapper / proxy libraries.
我对任何其他日志框架或包装器/代理库都不感兴趣。
I am notlooking for SLF4J or any other alternative logging frameworks, as suggested in this question.
我不是在寻找 SLF4J 或任何其他替代日志框架,如本问题所建议的那样。
采纳答案by Nulldevice
I met same problem - I was need a Syslog extension class for java.util.logging.Handler
我遇到了同样的问题 - 我需要一个用于java.util.logging.Handler的 Syslog 扩展类
After searching in Internet without any success, I ended up creating my own implementation - http://code.google.com/p/agafua-syslog/with support of UDP and TCP protocols. I use it in production project.
在互联网上搜索没有任何成功后,我最终创建了自己的实现 - http://code.google.com/p/agafua-syslog/支持 UDP 和 TCP 协议。我在生产项目中使用它。
回答by Darien
In an old job, I used the Syslog4jlibrary and wired up a custom Log4j-appender for it, so you can probably do something similar by implementing a custom java.util.logging.Handler
that passes messages along.
在以前的工作中,我使用了Syslog4j库并为它连接了一个自定义的 Log4j-appender,因此您可能可以通过实现一个java.util.logging.Handler
传递消息的自定义来做类似的事情。
回答by simon.watts
Syslog (at least on Linux) listens on a UDP port for input (514/udp by default).
Syslog(至少在 Linux 上)在 UDP 端口上侦听输入(默认为 514/udp)。
So implement a Handlerwhich sends the formatted messages to this port. I used the existing SocketHandlerfor reference, and implemented an alterative around a DatagramSocket. Mine came to about 200 lines all-in.
因此,实现一个将格式化消息发送到该端口的处理程序。我使用现有的SocketHandler作为参考,并围绕DatagramSocket实现了一个替代方案。我的全押到了大约 200 行。