From 8f1202899b2be8ebae58746a9be564225a3514ce Mon Sep 17 00:00:00 2001 From: Mark Payne Date: Wed, 29 Jun 2016 16:36:55 -0400 Subject: [PATCH] NIFI-2158 : return 'true' for isXYZEnabled() for ComponentLog if either the slf4j logger has that level enabled or the bulletin repository does, instead of only checking if slf4j logger has it enabled This closes #598 --- .../apache/nifi/logging/LogRepository.java | 8 ++++++ .../repository/StandardLogRepository.java | 25 +++++++++++++++++++ .../nifi/processor/SimpleProcessLogger.java | 24 +++++++++--------- 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/logging/LogRepository.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/logging/LogRepository.java index 54bb6720d4..06ddab4ea1 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/logging/LogRepository.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/logging/LogRepository.java @@ -76,4 +76,12 @@ public interface LogRepository { * @return the current logger for the component */ ComponentLog getLogger(); + + boolean isDebugEnabled(); + + boolean isInfoEnabled(); + + boolean isWarnEnabled(); + + boolean isErrorEnabled(); } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/logging/repository/StandardLogRepository.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/logging/repository/StandardLogRepository.java index f6c55b6d99..8baf04aca0 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/logging/repository/StandardLogRepository.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/logging/repository/StandardLogRepository.java @@ -183,4 +183,29 @@ public class StandardLogRepository implements LogRepository { public ComponentLog getLogger() { return componentLogger; } + + private boolean hasObserver(final LogLevel logLevel) { + final Collection logLevelObservers = observers.get(logLevel); + return (logLevelObservers != null && !logLevelObservers.isEmpty()); + } + + @Override + public boolean isDebugEnabled() { + return hasObserver(LogLevel.DEBUG); + } + + @Override + public boolean isInfoEnabled() { + return hasObserver(LogLevel.INFO); + } + + @Override + public boolean isWarnEnabled() { + return hasObserver(LogLevel.WARN); + } + + @Override + public boolean isErrorEnabled() { + return hasObserver(LogLevel.ERROR); + } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/processor/SimpleProcessLogger.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/processor/SimpleProcessLogger.java index 4f31722810..cc17abc31b 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/processor/SimpleProcessLogger.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/processor/SimpleProcessLogger.java @@ -167,29 +167,29 @@ public class SimpleProcessLogger implements ComponentLog { logRepository.addLogMessage(LogLevel.TRACE, msg, os, t); } - @Override - public boolean isWarnEnabled() { - return logger.isWarnEnabled(); - } - @Override public boolean isTraceEnabled() { return logger.isTraceEnabled(); } + @Override + public boolean isDebugEnabled() { + return logger.isDebugEnabled() || logRepository.isDebugEnabled(); + } + @Override public boolean isInfoEnabled() { - return logger.isInfoEnabled(); + return logger.isInfoEnabled() || logRepository.isInfoEnabled(); + } + + @Override + public boolean isWarnEnabled() { + return logger.isWarnEnabled() || logRepository.isWarnEnabled(); } @Override public boolean isErrorEnabled() { - return logger.isErrorEnabled(); - } - - @Override - public boolean isDebugEnabled() { - return logger.isDebugEnabled(); + return logger.isErrorEnabled() || logRepository.isErrorEnabled(); } @Override