As a result of the work, these days have studied how to write log4j log to the syslog. SYSLOGD is a common component of UNIX systems for performing system logging activities. SYSLOGD reads data from a set of log sources, such as:/dev/log and/dev/klog, and processes the log messages as described in/etc/syslog.conf. Logs an application log message to the syslog through a syslog () call.
Log4j is a fairly powerful open source logging tool that can send logs to files, databases, remote networks, and so on in a simple configuration. To send log4j log information to a remote Linux server's syslog in a Java program, it can be achieved by simply configuring it.
As a first step, you should modify the Syslog configuration file, because the syslog default configuration is that it cannot receive network data, and its profile syslog.conf files are typically under/etc: Add in the file: *.* local5,local7.none;<tab >;<tab>/usr/adm/network.log Second boot syslog to use: syslogd-r command, otherwise can not receive network data, should pay attention to turn off the Linux firewall.
In the second step, configure the Log4j properties file and add the following statement:
Log4j.appender.syslog=org.apache.log4j.net.syslogappender
Log4j.appender.syslog.sysloghost=syslog Server IP
Log4j.appender.syslog.facility=local5
Log4j.appender.syslog.layout=org.apache.log4j.patternlayout
log4j.appender.syslog.layout.conversionpattern=%d [%t]%p%c-%m%n
Through the above configuration, you use log4j in the program, its log information will be sent to the syslog, specifically saved there to see the syslog.conf file
Configuration, such as: *.info;mail.none;authpriv.none;cron.none/var/log/messages This sentence means that only the info level information is saved in the
/var/log/messages file. (syslog.conf detailed configuration on the web there are a lot of introductions, here is not said)
Finally, if you modify the log4j configuration in your program, you can use Propertyconfigurator.configureandwatch (". /sslsec/conf/log4j.properties ", 1000); the command enables log4j to automatically check that the configuration file is modified and automatically uses the new configuration without restarting the log4j, if modified.