Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Directory (?) [-]
-
- java how to connect to develop a syslog application
-
-
- server logging information
This time for everyone to share a log technology,sys log log technology. Public share number:lshaids6688
What is Syslog
Syslog is commonly used for information system management and auditing. Although it has a number of defects, it still receives a considerable number of devices and various platforms to support the receiving side. Therefore, syslog can be used to integrate log records from many different types of systems into a centralized repository. The
Syslog provides a mechanism for administrators to understand the log, which is to document system messages in English text. There are standard format messages in Syslog messages (called Syslog messages, system error messages, or simple system messages), as well as messages that are output from debug commands. These messages are generated during network operation to indicate the type and severity of network problems, or to help reader users detect the activity of the router, such as configuration changes. The
Cisco appliance generates syslog messages based on the results of network events. Each syslog message contains a severity level and an attribute. Many network devices support syslog including routers, switches, application servers, firewalls, and other network devices. A
Syslog is often referred to as a system log or system record, and is a standard used to pass information about a record in an Internet Protocol (TCP/IP) network. This term is commonly used to refer to the actual syslog protocol, or to applications or databases that send out syslog messages.
In layman's terms, Syslog is a protocol for sending and receiving logs, and you can use the Syslog protocol to implement your own application, send logs through the Syslog protocol from the log producer to the log consumer, save the log information to the consumer, and provide log query and management.
The role of the SysLog
First explain why you should use the syslog. Perhaps everyone has this question, we usually do every system does not have its own log module? We log in to our own log module, it is easy to view their own log information. So why use a syslog ?
The answer is this, if only for a system, we generally do not need to use the syslog , if an enterprise deploys a lot of systems, each system has its own log module, each system is independent. If the administrator wants to get the running information or audit log of the system through the log, the workload is quite large. This time, only requires all the system to transfer logs to the syslog server, through the syslog Server Unified Management log, it will be more convenient.
Of course, these systems include all the hardware, software systems, they will continue to send information, by the syslog Server to classify information, sub-level records.
how J Ava connects to developing SysLog applications
The Java Development syslog, which istypically developed by the client, is used by the server as a third-party application. They have already given us a part of the Syslog collection, and we just need to install it.
Pre-development preparation work:
Install a syslog server:syslogwatcher
: Http://pan.baidu.com/s/1dDlEEvJ
After the download is complete, run the exe directly .
After launch, there will be an icon in the tray and click into sysLogwatcher. The first time you use it, you need to set the encoding to utf-8. This is compatible with Chinese journals.
you can Control whether the monitor is turned on by L Isten and Stop
This opens the server and writes the client program as follows:
Java Client development needs to be introduced:sysLog4j.jar package.
:http://pan.baidu.com/s/1qW6qYo0
After the download is introduced into the project, write code examples as follows:
[Java] view plain copy
- Import Java.net.URLDecoder;
- Import Java.util.Date;
- Import Org.productivity.java.syslog4j.Syslog;
- Import Org.productivity.java.syslog4j.SyslogIF;
- /**
- * Syslog sends data
- * @author Lish
- * Date August 1, 2014 11:02:06
- * Class name SyslogTest2
- */
- Public class SyslogTest2 {
- public static void Main (string[] args) {
- try {
- //Gets the operation class for the syslog, using the UDP protocol. Syslog supports "UDP", "TCP", "Unix_syslog", "unix_socket" protocol
- Syslogif syslog = syslog.getinstance ("UDP");
- //Set Syslog server-side address
- Syslog.getconfig (). Sethost ("127.0.0.1");
- //Set syslog receive port, default 514
- Syslog.getconfig (). Setport (514);
- //Splicing syslog log, this log is defined by itself, usually we define the format in line with the company's specifications, convenient query. For example, operation time: August 1, 2014 operator ID: Zhang San. The message is a string.
- StringBuffer buffer = new StringBuffer ();
- Buffer.append ("Operating time:" + new Date (). toString (). substring (4, +) + ";");
- Buffer.append ("operator ID:" + " Zhang San" + ";");
- Buffer.append ("Operating time:" + new Date () + ";");
- Buffer.append ("log Category:" + "+" + " ;");
- Buffer.append ("Perform action:" + " action" + ";");
- Buffer.append ("Remarks:" + "remarks");
- / * Send information to the server, 2 indicates the log level range is 0~7 numeric encoding, indicating the severity of the event. 0 max, 7 min
- * Syslog assigns several different priority levels to each event:
- Log_emerg: Emergency, need to inform technician immediately.
- Log_alert: Problems that should be corrected immediately, such as System database corruption, ISP connection lost.
- Log_crit: Important case, such as hard drive error, standby connection is lost.
- Log_err: Error, not very urgent, can be repaired within a certain time.
- Log_warning: Warning message, not error, such as system disk use 85%.
- Log_notice: It is not an error condition and does not require immediate processing.
- Log_info: Intelligence information, normal system messages, such as harassment reports, bandwidth data, etc., do not need to be processed.
- Log_debug: Information that contains detailed development intelligence, usually used only when debugging a program.
- */
- Syslog.log (0, Urldecoder.decode (buffer.tostring (),"Utf-8"));
- } catch (Exception e) {
- }
- }
- }
Server Record Information
This allows the administrator to query all log information through the Syslog server as long as all systems are required to send log information to the server. And the level of log information can be used to determine the specific response measures. syslog Server can also make some reports, visual view of log information
Here, you have mastered the application method of Syslog,syslog can also monitor Linux,Unix,window and other server log information, so that through syslog can also get server health in real time. If you are interested, you can learn more. In short, so simple can unified log management, why not?
Introduction to Syslog and examples of Java operations