You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by jg...@apache.org on 2022/04/14 16:31:16 UTC
[nifi] branch main updated: NIFI-9923 Corrected SimpleProcessLogger handling of Throwable causes
This is an automated email from the ASF dual-hosted git repository.
jgresock pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new e76acabe9e NIFI-9923 Corrected SimpleProcessLogger handling of Throwable causes
e76acabe9e is described below
commit e76acabe9eda709f580a8d8a535cba78c2b61d18
Author: exceptionfactory <ex...@apache.org>
AuthorDate: Wed Apr 13 21:19:37 2022 -0500
NIFI-9923 Corrected SimpleProcessLogger handling of Throwable causes
- Changed log methods that accept a String and Object array to replace the last Throwable argument with a formatted summary of causes when calling LogRepository.addLogMessage()
Signed-off-by: Joe Gresock <jg...@gmail.com>
This closes #5965.
---
.../org/apache/nifi/processor/SimpleProcessLogger.java | 17 ++++++++++++-----
.../apache/nifi/processor/TestSimpleProcessLogger.java | 6 +++---
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/processor/SimpleProcessLogger.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/processor/SimpleProcessLogger.java
index 7262724dd4..32f19e328a 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/processor/SimpleProcessLogger.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/processor/SimpleProcessLogger.java
@@ -76,7 +76,7 @@ public class SimpleProcessLogger implements ComponentLog {
logRepository.addLogMessage(LogLevel.WARN, componentMessage, arguments);
} else {
logger.warn(componentMessage, setFormattedThrowable(arguments, lastThrowable));
- logRepository.addLogMessage(LogLevel.WARN, getCausesMessage(msg), addCauses(arguments, lastThrowable), lastThrowable);
+ logRepository.addLogMessage(LogLevel.WARN, getCausesMessage(msg), setCauses(arguments, lastThrowable), lastThrowable);
}
}
}
@@ -138,7 +138,7 @@ public class SimpleProcessLogger implements ComponentLog {
logRepository.addLogMessage(LogLevel.TRACE, componentMessage, arguments);
} else {
logger.trace(componentMessage, setFormattedThrowable(arguments, lastThrowable));
- logRepository.addLogMessage(LogLevel.TRACE, getCausesMessage(msg), addCauses(arguments, lastThrowable), lastThrowable);
+ logRepository.addLogMessage(LogLevel.TRACE, getCausesMessage(msg), setCauses(arguments, lastThrowable), lastThrowable);
}
}
}
@@ -225,7 +225,7 @@ public class SimpleProcessLogger implements ComponentLog {
logRepository.addLogMessage(LogLevel.INFO, componentMessage, arguments);
} else {
logger.info(componentMessage, setFormattedThrowable(arguments, lastThrowable));
- logRepository.addLogMessage(LogLevel.INFO, getCausesMessage(msg), addCauses(arguments, lastThrowable), lastThrowable);
+ logRepository.addLogMessage(LogLevel.INFO, getCausesMessage(msg), setCauses(arguments, lastThrowable), lastThrowable);
}
}
}
@@ -297,7 +297,7 @@ public class SimpleProcessLogger implements ComponentLog {
logRepository.addLogMessage(LogLevel.ERROR, componentMessage, arguments);
} else {
logger.error(componentMessage, setFormattedThrowable(arguments, lastThrowable));
- logRepository.addLogMessage(LogLevel.ERROR, getCausesMessage(msg), addCauses(arguments, lastThrowable), lastThrowable);
+ logRepository.addLogMessage(LogLevel.ERROR, getCausesMessage(msg), setCauses(arguments, lastThrowable), lastThrowable);
}
}
}
@@ -354,7 +354,7 @@ public class SimpleProcessLogger implements ComponentLog {
logRepository.addLogMessage(LogLevel.DEBUG, componentMessage, arguments);
} else {
logger.debug(componentMessage, setFormattedThrowable(arguments, lastThrowable));
- logRepository.addLogMessage(LogLevel.DEBUG, getCausesMessage(msg), addCauses(arguments, lastThrowable), lastThrowable);
+ logRepository.addLogMessage(LogLevel.DEBUG, getCausesMessage(msg), setCauses(arguments, lastThrowable), lastThrowable);
}
}
}
@@ -538,6 +538,13 @@ public class SimpleProcessLogger implements ComponentLog {
return ArrayUtils.add(arguments, causes);
}
+ private Object[] setCauses(final Object[] arguments, final Throwable throwable) {
+ final String causes = getCauses(throwable);
+ final int lastIndex = arguments.length - 1;
+ final Object[] argumentsThrowableRemoved = ArrayUtils.remove(arguments, lastIndex);
+ return ArrayUtils.add(argumentsThrowableRemoved, causes);
+ }
+
private Object[] setFormattedThrowable(final Object[] arguments, final Throwable throwable) {
final int lastIndex = arguments.length - 1;
final Object[] argumentsThrowableRemoved = ArrayUtils.remove(arguments, lastIndex);
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/processor/TestSimpleProcessLogger.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/processor/TestSimpleProcessLogger.java
index 0ef86821b0..2ed6723114 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/processor/TestSimpleProcessLogger.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/processor/TestSimpleProcessLogger.java
@@ -83,7 +83,7 @@ public class TestSimpleProcessLogger {
private Object[] componentValueArguments;
- private Object[] componentValueExceptionStringCausesArguments;
+ private Object[] componentValueCausesArguments;
private Object[] componentCausesArguments;
@@ -96,7 +96,7 @@ public class TestSimpleProcessLogger {
componentArguments = new Object[]{component};
componentValueArguments = new Object[]{component, FIRST, SECOND};
- componentValueExceptionStringCausesArguments = new Object[]{component, FIRST, SECOND, EXCEPTION, EXPECTED_CAUSES};
+ componentValueCausesArguments = new Object[]{component, FIRST, SECOND, EXPECTED_CAUSES};
componentCausesArguments = new Object[]{component, EXPECTED_CAUSES};
when(logger.isTraceEnabled()).thenReturn(true);
@@ -218,7 +218,7 @@ public class TestSimpleProcessLogger {
continue;
}
- verify(logRepository).addLogMessage(eq(logLevel), eq(LOG_ARGUMENTS_MESSAGE_WITH_COMPONENT_AND_CAUSES), eq(componentValueExceptionStringCausesArguments), eq(EXCEPTION));
+ verify(logRepository).addLogMessage(eq(logLevel), eq(LOG_ARGUMENTS_MESSAGE_WITH_COMPONENT_AND_CAUSES), eq(componentValueCausesArguments), eq(EXCEPTION));
}
}