What is the most modern way to log to syslog using a java.util.logging handler?

爷,独闯天下 提交于 2019-12-05 11:26:48

问题


I am specifically looking for the most up to date, modern SysLogHandler for java.util.logging.

I have found a few that date back to 2001 - 2003, mostly un-supported now.

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.

I am not interested in any of the other logging frameworks or wrapper / proxy libraries.

I am not looking for SLF4J or any other alternative logging frameworks, as suggested in this question.


回答1:


I met same problem - I was need a Syslog extension class for java.util.logging.Handler

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.




回答2:


In an old job, I used the Syslog4j library 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.




回答3:


Syslog (at least on Linux) listens on a UDP port for input (514/udp by default).

So implement a Handler which sends the formatted messages to this port. I used the existing SocketHandler for reference, and implemented an alterative around a DatagramSocket. Mine came to about 200 lines all-in.



来源:https://stackoverflow.com/questions/6206936/what-is-the-most-modern-way-to-log-to-syslog-using-a-java-util-logging-handler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!