From 31f92ec91b2df3924fc47d4fc9961b8ffa6f684a Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Thu, 21 Nov 2024 09:55:48 +0000 Subject: [PATCH] XmlBeansLogManager handle null logger case git-svn-id: https://svn.apache.org/repos/asf/xmlbeans/trunk@1921989 13f79535-47bb-0310-9956-ffa450edef68 --- .../xmlbeans/impl/logging/XmlBeansLogManager.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/xmlbeans/impl/logging/XmlBeansLogManager.java b/src/main/java/org/apache/xmlbeans/impl/logging/XmlBeansLogManager.java index 623d8ea2b..5300a3ae4 100644 --- a/src/main/java/org/apache/xmlbeans/impl/logging/XmlBeansLogManager.java +++ b/src/main/java/org/apache/xmlbeans/impl/logging/XmlBeansLogManager.java @@ -36,11 +36,19 @@ private XmlBeansLogManager() { } public static Logger getLogger(Class clz) { + final long time = System.currentTimeMillis(); try { - return LogManager.getLogger(clz); + final Logger logger = LogManager.getLogger(clz); + if (logger == null) { + if (time > LAST_TIME + SLEEP_TIME) { + LAST_TIME = time; + System.err.println("Log4J returned null logger. Falling back to No-Op logger."); + } + return NoOpLogger.INSTANCE; + } + return logger; } catch (Throwable t) { if (!ExceptionUtil.isFatal(t)) { - final long time = System.currentTimeMillis(); if (time > LAST_TIME + SLEEP_TIME) { LAST_TIME = time; System.err.println("Issue loading Log4J. Falling back to No-Op logger.");