ability to upload log.txt file

This commit is contained in:
SuperRonanCraft 2023-03-28 21:47:25 -04:00
parent c96691325b
commit 06453db90c
3 changed files with 13 additions and 13 deletions

View File

@ -70,6 +70,7 @@ public class BetterRTP extends JavaPlugin {
public void onDisable() {
invs.closeAll();
queue.unload();
rtpLogger.unload();
/*if (this.adventure != null) {
this.adventure.close();
this.adventure = null;

View File

@ -47,6 +47,11 @@ public class RTPLogger {
return format.format(new Date());
}
public void unload() {
if (handler != null)
handler.close();
}
static class MyFormatter extends Formatter {
@Override
public String format(LogRecord record) {

View File

@ -10,6 +10,7 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Scanner;
public class LogUploader {
@ -50,17 +51,6 @@ public class LogUploader {
@Nullable
public static String post(File file) {
FileConfiguration config = new YamlConfiguration();
try {
config.load(file);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
return null;
}
// Convert the config file to a YAML string
String requestBody = config.saveToString();
// Create the connection to the server
try {
URL url = new URL(UPLOAD_URL);
@ -70,8 +60,12 @@ public class LogUploader {
connection.setDoOutput(true);
try (OutputStream outputStream = connection.getOutputStream()) {
byte[] input = requestBody.getBytes(StandardCharsets.UTF_8);
outputStream.write(input, 0, input.length);
Scanner scan = new Scanner(file);
while(scan.hasNextLine()){
String str = scan.nextLine();
byte[] input = (str + System.lineSeparator()).getBytes(StandardCharsets.UTF_8);
outputStream.write(input, 0, input.length);
}
}
StringBuilder response = new StringBuilder();