From 87f944c240fdc6f9b6bb8efc50921d9eac99b220 Mon Sep 17 00:00:00 2001 From: KingOfSquares <19822231+KingOfSquares@users.noreply.github.com> Date: Sat, 5 Nov 2022 21:56:11 +0100 Subject: [PATCH] Fix logging NPE and change log level of BlockTransformListener (#1096) Signed-off-by: KingSimon <19822231+KingOfSquares@users.noreply.github.com> --- .../tc/oc/pgm/listeners/BlockTransformListener.java | 2 +- util/src/main/java/tc/oc/pgm/util/ClassLogger.java | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/tc/oc/pgm/listeners/BlockTransformListener.java b/core/src/main/java/tc/oc/pgm/listeners/BlockTransformListener.java index 605b48b9f4..dc7c3a55d5 100644 --- a/core/src/main/java/tc/oc/pgm/listeners/BlockTransformListener.java +++ b/core/src/main/java/tc/oc/pgm/listeners/BlockTransformListener.java @@ -200,7 +200,7 @@ private void callEvent(final BlockTransformEvent event, boolean checked) { handleDoor(event, (Door) newData); } } - logger.fine("Generated event " + event); + logger.finest("Generated event " + event); currentEvents.put(event.getCause(), event); } diff --git a/util/src/main/java/tc/oc/pgm/util/ClassLogger.java b/util/src/main/java/tc/oc/pgm/util/ClassLogger.java index 95822bfe78..6aabea5643 100644 --- a/util/src/main/java/tc/oc/pgm/util/ClassLogger.java +++ b/util/src/main/java/tc/oc/pgm/util/ClassLogger.java @@ -113,6 +113,17 @@ private ClassLogger(@Nullable Logger parent, Class klass, @Nullable String in this.setLevel(null); } + public Level getEffectiveLevel() { + Level level = this.getLevel(); + Logger someParent = this.getParent(); + while (level == null) { + level = someParent.getLevel(); + someParent = someParent.getParent(); + } + + return level; + } + @Override public void log(LogRecord record) { record.setMessage(this.prefix + record.getMessage()); @@ -121,7 +132,7 @@ public void log(LogRecord record) { // Check the level ourselves and then promote the record // to make sure it gets through. if (record.getLevel().intValue() < Level.INFO.intValue() - && record.getLevel().intValue() >= this.getLevel().intValue()) { + && record.getLevel().intValue() >= this.getEffectiveLevel().intValue()) { record.setLevel(Level.INFO); }