Glassfish to Syslog

房东的猫 提交于 2019-12-06 03:17:42

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