Skip to content

Commit

Permalink
Fix logging NPE and change log level of BlockTransformListener (PGMDe…
Browse files Browse the repository at this point in the history
…v#1096)

Signed-off-by: KingSimon <[email protected]>
  • Loading branch information
KingOfSquares authored and calcastor committed Nov 14, 2022
1 parent 551af9d commit 31a4c2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
13 changes: 12 additions & 1 deletion util/src/main/java/tc/oc/pgm/util/ClassLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
}
Expand Down

0 comments on commit 31a4c2f

Please sign in to comment.