2024-04-19 09:46:54 +08:00
|
|
|
package com.coloryr.allmusic.server.core.utils;
|
2020-02-21 01:31:50 +08:00
|
|
|
|
2024-04-19 09:46:54 +08:00
|
|
|
import com.coloryr.allmusic.server.core.AllMusic;
|
2019-03-24 02:58:50 +08:00
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileWriter;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
2022-12-27 10:31:41 +08:00
|
|
|
public class Logs {
|
2020-04-19 20:36:12 +08:00
|
|
|
private static final Date date = new Date();
|
2020-05-02 21:53:22 +08:00
|
|
|
public static File file;
|
2020-03-19 21:30:34 +08:00
|
|
|
private static FileWriter fw;
|
|
|
|
|
private static PrintWriter pw;
|
2019-03-24 02:58:50 +08:00
|
|
|
|
2020-03-20 22:25:51 +08:00
|
|
|
public static void logWrite(String text) {
|
2019-12-15 13:15:14 +08:00
|
|
|
try {
|
2020-03-19 21:30:34 +08:00
|
|
|
if (fw == null)
|
|
|
|
|
fw = new FileWriter(file, true);
|
2019-12-15 13:15:14 +08:00
|
|
|
String year = String.format("%tF", date);
|
|
|
|
|
String time = String.format("%tT", date);
|
|
|
|
|
String write = "[" + year + "]" + "[" + time + "]" + text;
|
2020-03-19 21:30:34 +08:00
|
|
|
if (pw == null)
|
|
|
|
|
pw = new PrintWriter(fw);
|
2019-12-15 13:15:14 +08:00
|
|
|
pw.println(write);
|
|
|
|
|
pw.flush();
|
|
|
|
|
fw.flush();
|
2020-03-19 21:30:34 +08:00
|
|
|
|
2019-12-15 13:15:14 +08:00
|
|
|
} catch (IOException e) {
|
2020-04-19 20:36:12 +08:00
|
|
|
AllMusic.log.warning("§c日志文件写入失败");
|
2020-02-20 23:22:58 +08:00
|
|
|
e.printStackTrace();
|
2019-12-15 13:15:14 +08:00
|
|
|
}
|
|
|
|
|
}
|
2020-02-26 22:04:53 +08:00
|
|
|
|
2020-03-19 21:30:34 +08:00
|
|
|
public static void stop() throws IOException {
|
|
|
|
|
if (fw != null)
|
|
|
|
|
pw.close();
|
|
|
|
|
if (fw != null)
|
|
|
|
|
fw.close();
|
|
|
|
|
}
|
2019-03-24 02:58:50 +08:00
|
|
|
}
|