Search code examples
loggingglassfish-3syslog

Glassfish to Syslog


I'm struggling to make Glassfish 3.1.1 to log to syslog, but I'm unable to. I don't know if it's a bug, but I don't even know how to debug it.

First and obvious step: I checked the box on the administration console to write to system log, and after I also marked the checkbox write to system console. None of them worked.

I checked the logging.properties and this line is there

com.sun.enterprise.server.logging.SyslogHandler.useSystemLogging=true

Googling I found a few people complaining with abandoned questions. Is there anything else I should do or I have to write a custom log handler to do that ?


Solution

  • The connection to syslog has changed since GF 2.1 where a native library "libutilforsyslog.so" was used. Seems to me you now have to provide UDP port 514 on localhost to receive syslog messages by GlassFish 3.

    com.sun.enterprise.server.logging.SyslogHandler creates an syslog instance like this:

    sysLogger = new Syslog("localhost");  //for now only write to this host
    

    ... which is an instance of com.sun.enterprise.server.logging.Syslog. This class builds a UDP datagram that gets sent to port 514 (hardcoded).

    I have the syslog-ng package on my Debian host on which I run GlassFish. syslog-ng is configured with a default local log src:

    source s_src { unix-dgram("/dev/log"); internal();
                 file("/proc/kmsg" program_override("kernel"));
    };
    

    In this example you can simply add a listener for UDP port 514:

    udp(ip(127.0.0.1) port(514));