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 ?
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));
In order to enable the syslog in Glassfish 4.1 we have to change the logging.properties under domain (e.g. glassfish/domains/domain1/config)
The line
handlerServices=com.sun.enterprise.server.logging.GFFileHandler
should be changed in
handlerServices=com.sun.enterprise.server.logging.GFFileHandler,com.sun.enterprise.server.logging.SyslogHandler
see: [GLASSFISH-20718] Write to System Log option do not send log on localhost udp port 514
In order to make this change in a cleaner way instead of changing the logging.properties directly you can use the asadmin as follow:
bash-4.3# asadmin set-log-attributes handlers=java.util.logging.ConsoleHandler,com.sun.enterprise.server.logging.SyslogHandler
handlers logging attribute value set to java.util.logging.ConsoleHandler,com.sun.enterprise.server.logging.SyslogHandler.
The logging attributes are saved successfully for server.
Finally, in order to enable the Syslog you can invoke asadmin as follow:
bash-4.3# asadmin set-log-attributes com.sun.enterprise.server.logging.SyslogHandler.useSystemLogging=true
com.sun.enterprise.server.logging.SyslogHandler.useSystemLogging logging attribute value set to true.
The logging attributes are saved successfully for server.
来源:https://stackoverflow.com/questions/9243723/glassfish-to-syslog