?? sysloglistener.java
字號:
package logToMySQL;
import java.net.*;
import java.text.DateFormat;
import java.util.*;
public class SyslogListener {
final static LogReader curr = new LogReader();
public static void main(String[] argv) {
TimeZone tz = TimeZone.getTimeZone("ETC/GMT-8");
TimeZone.setDefault(tz);
DatagramSocket ds = null;
DatagramPacket dp = null;
byte[] buf = new byte[1024];
String log;
InetAddress addr = null;
LogConfigure.loadConfig();
System.out.println(getTime());
if (LogReader.existConfig)
try {
addr = Inet4Address.getByName("192.168.65.1");
ds = new DatagramSocket(514,addr);
dp = new DatagramPacket(buf,1000);
System.out.println("Listening......");
while(true) {
ds.receive(dp);
log = new String(Arrays.copyOf(buf, dp.getLength()));
log = getTime() + log;
curr.processNewLog(log);
System.out.println(log);
}
}catch(BindException e){
System.out.println("Error:An error occurred while attempting to bind a socket to a local address and port.");
System.out.println("Another instance may be in running.");
}
catch (Exception e) {
e.printStackTrace();
}
}
public static String getTime() {
return DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.MEDIUM,Locale.ENGLISH).format(new Date())+" ";
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -