Skip to content

Commit

Permalink
PoiLogManager
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1922056 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
pjfanning committed Nov 24, 2024
1 parent 924d8e7 commit a2af565
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions poi/src/main/java/org/apache/poi/logging/PoiLogManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ public static Logger getLogger(Class<?> clz) {
}
}

public static Logger getLogger(String name) {
try {
final Logger logger = LogManager.getLogger(name);
if (logger == null) {
if (shouldLog()) {
System.err.println("[PoiLogManager] Log4J returned null logger. Falling back to No-Op logger.");
}
return NoOpLogger.INSTANCE;
}
return logger;
} catch (Throwable t) {
if (!ExceptionUtil.isFatal(t)) {
if (shouldLog()) {
System.err.println("[PoiLogManager] Issue loading Log4J. Falling back to No-Op logger.");
t.printStackTrace();
}
}
return NoOpLogger.INSTANCE;
}
}

private static synchronized boolean shouldLog() {
final long time = System.currentTimeMillis();
if (time > LAST_TIME + SLEEP_TIME) {
Expand Down

0 comments on commit a2af565

Please sign in to comment.