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() { public void onDisable() {
invs.closeAll(); invs.closeAll();
queue.unload(); queue.unload();
rtpLogger.unload();
/*if (this.adventure != null) { /*if (this.adventure != null) {
this.adventure.close(); this.adventure.close();
this.adventure = null; this.adventure = null;

View File

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

View File

@ -10,6 +10,7 @@ import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.Scanner;
public class LogUploader { public class LogUploader {
@ -50,17 +51,6 @@ public class LogUploader {
@Nullable @Nullable
public static String post(File file) { 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 // Create the connection to the server
try { try {
URL url = new URL(UPLOAD_URL); URL url = new URL(UPLOAD_URL);
@ -70,8 +60,12 @@ public class LogUploader {
connection.setDoOutput(true); connection.setDoOutput(true);
try (OutputStream outputStream = connection.getOutputStream()) { try (OutputStream outputStream = connection.getOutputStream()) {
byte[] input = requestBody.getBytes(StandardCharsets.UTF_8); Scanner scan = new Scanner(file);
outputStream.write(input, 0, input.length); 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(); StringBuilder response = new StringBuilder();