Added dedicated loggers for each extension if logger flag is set

This commit is contained in:
dorving 2022-07-12 01:39:01 +02:00
parent c603cdbd61
commit 8b8c4fff72

View File

@ -12,7 +12,9 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.nio.file.*; import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import java.util.Random; import java.util.Random;
@ -110,36 +112,37 @@ public final class NormalExtensionRunner implements ExtensionRunner {
final Process process = processBuilder.start(); final Process process = processBuilder.start();
maybeLogExtension(path, process); maybeLogExtension(path, process);
} catch (IOException e) { } catch (IOException e) {
LOGGER.error("Failed to run extension at path {} using port {}", path, port, e); LOGGER.error("Failed to run extension at path {} using port {}", path, port, e);
} }
} }
public static void maybeLogExtension(String path, Process process) { public static void maybeLogExtension(String path, Process process) {
if (GEarth.hasFlag(ExtensionRunner.SHOW_EXTENSIONS_LOG)) { if (GEarth.hasFlag(ExtensionRunner.SHOW_EXTENSIONS_LOG)) {
final String separator = "" + System.lineSeparator(); final Logger logger = LoggerFactory.getLogger(path);
LOGGER.info(path + separator + "Launching" + separator + "----------" + separator);
logger.info("Launching...");
final BufferedReader processInputReader = new BufferedReader(new InputStreamReader(process.getInputStream())); final BufferedReader processInputReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
new Thread(() -> { new Thread(() -> {
try { try {
String line; String line;
while ((line = processInputReader.readLine()) != null) while ((line = processInputReader.readLine()) != null)
LOGGER.info(path + separator + "Output" + separator + line + separator + "----------" + separator); logger.info(line);
} catch (IOException e) { } catch (IOException e) {
LOGGER.error("Failed to read input line from process {}", process, e); LOGGER.error("Failed to read input line from process {}", process, e);
} }
}).start(); }, path+"-input").start();
final BufferedReader processErrorReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); final BufferedReader processErrorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
new Thread(() -> { new Thread(() -> {
try { try {
String line; String line;
while((line = processErrorReader.readLine()) != null) { while ((line = processErrorReader.readLine()) != null)
LOGGER.error(path + separator + "Error" + separator + line + separator + "----------" + separator); logger.error(line);
}
} catch (IOException e) { } catch (IOException e) {
LOGGER.error("Failed to read error line from process {}", process, e); LOGGER.error("Failed to read error line from process {}", process, e);
} }