开发者

How can I get Syslogging to work on the JVM?

I want to do syslogging from Java. There is a log4j appender, but it doesn't seem to work (for me anyway ... though Google results show many others with this issue still unresolved).

I'm trying to debug the appender, so I've written the following script based upon RFC3164

It runs, but no logging appears in the syslog.

// scala
import java.io._
import java.net._
val ds = new DatagramSocket()
val fullMsg = "<11>May 26 14:47:22 Hello World"
val packet = new DatagramPacket(fullMsg.getBytes("UTF-8"), fullMsg.length, 
  InetAddress.getLocalHost, 5开发者_C百科14)
ds send packet
ds.close

I also tried using /bin/nc, but it doesn't work either.

echo "<14>May 26 15:23:33 Hello world" > nc -u localhost 514

The Ubuntu command /usr/bin/logger does work, however.

logger -p user.info hello world
# logs: May 26 15:25:10 dsupport2 jem: hello world

What could I be doing wrong?

Edit

Both nc & the scala generate the following packet:

jem@dsupport2:~/projects/log4j$ grep -A 10 514 out
xxx.xxx.xxx.xxx:37920(unknown) -> xxx.xxx.xxx.xxx:514(syslog)
Version: 4   Total Lenght: 63   TTL: 64
Packet Number: 4

---[ UDP Data ]------------------------------------------------------

<14>May 26 15:26:33 Hello world 22

It seems I cannot get /usr/bin/logger (the one that works) to talk remotely. I assume you're supposed to set up the local syslogd as a relay.

Edit

Using nc, wireshark shows the message to be formatted OK, but that the port is unreachable.


The network firewall in Ubuntu needs to be explicitly told to allow traffic to a given port, this includes Syslog.


Have you tried sniffing the local network traffic to see if the log messages are actually sent, if they seem well-formed, etc? You could use nast or something like it.


Syslogd is probaby not listening on an IP socket but a unix domain socket. The standard socket is /dev/log. You will need to use a library such as JUDS to connect to this socket. This will give an OutputStream that you can write the log record to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜