From 6c7d638cfad4c7c230b5d84a7ca9f2d0682c35a0 Mon Sep 17 00:00:00 2001 From: phit Date: Tue, 18 Apr 2017 12:36:48 +0200 Subject: [PATCH] 1.1.1 * actually fix logging --- build.gradle | 2 +- .../prometheusexporter/JettyNullLogger.java | 63 +++++-------------- .../prometheusexporter/MetricsController.java | 3 +- .../PrometheusExporter.java | 16 ++--- src/main/resources/jetty-logging.properties | 1 + 5 files changed, 26 insertions(+), 59 deletions(-) create mode 100644 src/main/resources/jetty-logging.properties diff --git a/build.gradle b/build.gradle index f2b84de6..8257fcd4 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ plugins { } group = 'de.sldk.mc.prometheusexporter' -version = '1.1.0' +version = '1.1.1' description = "Sponge Minecraft Prometheus Exporter" ext.url = 'https://github.com/Stonebound/minecraft-prometheus-exporter' diff --git a/src/main/java/de/sldk/mc/prometheusexporter/JettyNullLogger.java b/src/main/java/de/sldk/mc/prometheusexporter/JettyNullLogger.java index 37964854..a11a586b 100644 --- a/src/main/java/de/sldk/mc/prometheusexporter/JettyNullLogger.java +++ b/src/main/java/de/sldk/mc/prometheusexporter/JettyNullLogger.java @@ -3,52 +3,19 @@ import org.eclipse.jetty.util.log.Logger; public class JettyNullLogger implements Logger { - public String getName() { - return "Jetty"; - } - - public void warn(String s, Object... objects) { - } - - public void warn(Throwable throwable) { - } - - public void warn(String s, Throwable throwable) { - } - - public void info(String s, Object... objects) { - } - - public void info(Throwable throwable) { - } - - public void info(String s, Throwable throwable) { - } - - public boolean isDebugEnabled() { - return false; - } - - public void setDebugEnabled(boolean b) { - } - - public void debug(String s, Object... objects) { - } - - public void debug(String msg, long value) { - - } - - public void debug(Throwable throwable) { - } - - public void debug(String s, Throwable throwable) { - } - - public Logger getLogger(String s) { - return this; - } - - public void ignore(Throwable throwable) { - } + @Override public String getName() { return "Jetty"; } + @Override public void warn(String msg, Object... args) { } + @Override public void warn(Throwable thrown) { } + @Override public void warn(String msg, Throwable thrown) { } + @Override public void info(String msg, Object... args) { } + @Override public void info(Throwable thrown) { } + @Override public void info(String msg, Throwable thrown) { } + @Override public boolean isDebugEnabled() { return false; } + @Override public void setDebugEnabled(boolean enabled) { } + @Override public void debug(String msg, Object... args) { } + @Override public void debug(String msg, long value) { } + @Override public void debug(Throwable thrown) { } + @Override public void debug(String msg, Throwable thrown) { } + @Override public Logger getLogger(String name) { return this; } + @Override public void ignore(Throwable ignored) { } } \ No newline at end of file diff --git a/src/main/java/de/sldk/mc/prometheusexporter/MetricsController.java b/src/main/java/de/sldk/mc/prometheusexporter/MetricsController.java index 44ebaac3..ed547e52 100644 --- a/src/main/java/de/sldk/mc/prometheusexporter/MetricsController.java +++ b/src/main/java/de/sldk/mc/prometheusexporter/MetricsController.java @@ -57,8 +57,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques baseRequest.setHandled(true); } catch (IOException e) { - exporter.getLogger().error("Failed to read server statistics"); - e.printStackTrace(); + exporter.getLogger().error("Failed to read server statistics", e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } diff --git a/src/main/java/de/sldk/mc/prometheusexporter/PrometheusExporter.java b/src/main/java/de/sldk/mc/prometheusexporter/PrometheusExporter.java index 0b6f375e..8c87bd4f 100644 --- a/src/main/java/de/sldk/mc/prometheusexporter/PrometheusExporter.java +++ b/src/main/java/de/sldk/mc/prometheusexporter/PrometheusExporter.java @@ -32,22 +32,23 @@ public class PrometheusExporter { @Inject @DefaultConfig(sharedRoot = false) private File config; + @Inject @DefaultConfig(sharedRoot = false) private ConfigurationLoader cfgMgr; private ConfigurationNode cfg; - private static PrometheusExporter instance; - public static PrometheusExporter getInstance() { - return PrometheusExporter.instance; - } - @Inject private Logger logger; public Logger getLogger() { return this.logger; } + private static PrometheusExporter instance; + public static PrometheusExporter getInstance() { + return PrometheusExporter.instance; + } + @Listener public void onPreinit(GamePreInitializationEvent event) { logger.info("Setting up config..."); @@ -69,17 +70,16 @@ public void onPreinit(GamePreInitializationEvent event) { @Listener public void onServerStarted(GameStartedServerEvent event) { - org.eclipse.jetty.util.log.Log.setLog(new JettyNullLogger()); try { server = new Server(port); server.setHandler(new MetricsController(this)); server.start(); - getLogger().info("Started Prometheus metrics endpoint on port " + port); + logger.info("Started Prometheus metrics endpoint on port " + port); } catch (Exception e) { - getLogger().error("Could not start embedded Jetty server", e); + logger.error("Could not start embedded Jetty server", e); } } diff --git a/src/main/resources/jetty-logging.properties b/src/main/resources/jetty-logging.properties new file mode 100644 index 00000000..7139c041 --- /dev/null +++ b/src/main/resources/jetty-logging.properties @@ -0,0 +1 @@ +org.eclipse.jetty.util.log.class=de.sldk.mc.prometheusexporter.JettyNullLogger \ No newline at end of file