|
@@ -3,7 +3,11 @@ package Utils;
|
|
|
import com.google.gson.JsonObject;
|
|
import com.google.gson.JsonObject;
|
|
|
import com.nju.edu.logTracking.enums.SeecSystem;
|
|
import com.nju.edu.logTracking.enums.SeecSystem;
|
|
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.net.URL;
|
|
|
|
|
+import java.net.URLConnection;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
|
|
|
public class LogBuilder {
|
|
public class LogBuilder {
|
|
|
private final JsonObject log = new JsonObject();
|
|
private final JsonObject log = new JsonObject();
|
|
@@ -36,11 +40,22 @@ public class LogBuilder {
|
|
|
log.addProperty("message", message);
|
|
log.addProperty("message", message);
|
|
|
return this;
|
|
return this;
|
|
|
}
|
|
}
|
|
|
|
|
+ private String getTimeByWeb(){
|
|
|
|
|
+ try {
|
|
|
|
|
+ URL url=new URL("https://baidu.com");
|
|
|
|
|
+ URLConnection conn=url.openConnection();
|
|
|
|
|
+ conn.connect();
|
|
|
|
|
+ long dateL=conn.getDate();
|
|
|
|
|
+ Date date=new Date(dateL);
|
|
|
|
|
+ SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
|
|
+ return dateFormat.format(date);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ return "无法获取时间";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
public String build() {
|
|
public String build() {
|
|
|
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
- String dateString = formatter.format(System.currentTimeMillis());
|
|
|
|
|
- log.addProperty("created_time", dateString);
|
|
|
|
|
|
|
+ log.addProperty("created_time", getTimeByWeb());
|
|
|
return log.toString();
|
|
return log.toString();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|