From 88b62cc225e032cb4bba384dca9c3bd752d4f50c Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 29 Apr 2024 07:40:25 +0100 Subject: [PATCH] update logging --- .../cc/fascinated/piaservers/pia/PiaManager.java | 15 ++++++++------- .../piaservers/readme/ReadMeManager.java | 2 ++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/cc/fascinated/piaservers/pia/PiaManager.java b/src/main/java/cc/fascinated/piaservers/pia/PiaManager.java index e5e4547..4fd01a2 100644 --- a/src/main/java/cc/fascinated/piaservers/pia/PiaManager.java +++ b/src/main/java/cc/fascinated/piaservers/pia/PiaManager.java @@ -31,7 +31,7 @@ public class PiaManager { public PiaManager() { File serversFile = new File("servers.json"); if (!serversFile.exists()) { - System.out.println("servers.json does not exist, creating..."); + System.out.println("The servers file doesn't exist, creating it..."); serversFile.createNewFile(); } // Load the serversFile from the file @@ -39,7 +39,7 @@ public class PiaManager { if (SERVERS == null) { SERVERS = new HashSet<>(); } - System.out.println("Loaded " + SERVERS.size() + " servers from the file"); + System.out.printf("Loaded %s servers from the file%n", SERVERS.size()); // Set the DNS resolver to Cloudflare Lookup.setDefaultResolver(new SimpleResolver("1.1.1.1")); @@ -67,11 +67,8 @@ public class PiaManager { @SneakyThrows public static void updateServers(File serversFile) { List servers = getPiaServers(); - System.out.println("Found " + servers.size() + " pia server tokens"); - List toRemove = new ArrayList<>(); - System.out.println("Removing old servers..."); // Get the servers that need to be removed for (PiaServer server : SERVERS) { if (server.getLastSeen().getTime() < System.currentTimeMillis() - REMOVAL_THRESHOLD) { @@ -79,7 +76,7 @@ public class PiaManager { } } toRemove.forEach(SERVERS::remove); // Remove the servers - System.out.printf("Removed %s old servers\n", toRemove.size()); + System.out.printf("Removed %s servers that haven't been active in 2 weeks\n", toRemove.size()); int newServers = 0; @@ -96,11 +93,12 @@ public class PiaManager { // Save the servers to the file Files.writeString(serversFile.toPath(), Main.GSON.toJson(SERVERS)); - System.out.printf("Wrote %s new servers to the file\n", newServers); + System.out.printf("Wrote %s servers to the file (+%s new)%n", SERVERS.size(), newServers); } @SneakyThrows private static List getPiaServers() { + long start = System.currentTimeMillis(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(PIA_OPENVPN_CONFIGS_URL)) .GET() @@ -111,6 +109,7 @@ public class PiaManager { System.out.println("Failed to get the PIA OpenVPN configs, status code: " + response.statusCode()); System.exit(1); } + System.out.printf("Downloaded the OpenVPN configs in %sms%n", System.currentTimeMillis() - start); Path downloadedFile = response.body(); File tempDir = Files.createTempDirectory("openvpn").toFile(); ZipUnArchiver unArchiver = new ZipUnArchiver(); @@ -127,6 +126,8 @@ public class PiaManager { System.exit(1); } + System.out.printf("Found %s regions%n", files.length - 1); + // Search for the servers List servers = new ArrayList<>(); for (File file : files) { diff --git a/src/main/java/cc/fascinated/piaservers/readme/ReadMeManager.java b/src/main/java/cc/fascinated/piaservers/readme/ReadMeManager.java index 836326d..9c57af0 100644 --- a/src/main/java/cc/fascinated/piaservers/readme/ReadMeManager.java +++ b/src/main/java/cc/fascinated/piaservers/readme/ReadMeManager.java @@ -19,6 +19,7 @@ public class ReadMeManager { @SneakyThrows public static Path updateReadme() { + System.out.println("Updating README.md"); InputStream readmeStream = Main.class.getResourceAsStream("/README.md"); if (readmeStream == null) { System.out.println("Failed to find README.md"); @@ -49,6 +50,7 @@ public class ReadMeManager { .reduce((a, b) -> a + "\n" + b).orElse("")); // Reduce the entries to a single string Files.write(readmeFile.toPath(), contents.getBytes()); + System.out.println("Finished updating README.md"); return readmeFile.toPath(); } }