This is an automated email from the ASF dual-hosted git repository.
clebertsuconic pushed a commit to branch new-logging
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
The following commit(s) were added to refs/heads/new-logging by this push:
new 05856c21ac Fix stacktraces of generated exceptions to not include the
generated logmessage method
05856c21ac is described below
commit 05856c21ac5a9403cbbda2cd13ef9b1a4fde5c65
Author: Clebert Suconic <[email protected]>
AuthorDate: Fri Sep 2 13:33:34 2022 -0400
Fix stacktraces of generated exceptions to not include the generated
logmessage method
---
TODO-new-logging.txt | 9 ++++++---
.../org/apache/activemq/artemis/logprocessor/LogProcessor.java | 7 +++++++
.../apache/activemq/artemis/logprocessor/SimpleBundleTest.java | 6 ++++++
3 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/TODO-new-logging.txt b/TODO-new-logging.txt
index 7dd22f78b1..f154322a1d 100644
--- a/TODO-new-logging.txt
+++ b/TODO-new-logging.txt
@@ -1,12 +1,15 @@
TODOs not explicitly noted in the code itself already:
- Remove JBL use from last remaining tests etc tests still using it
-- Fix stacktraces of generated exceptions not to include the generated
'logmessage' method creating it.
-- Replace logging.properties files in remaining tests/examples needing their
own custom config
+- Replace logging.properties files in remaining tests/examples needing their
own custom config
-- Investigate how ./examples/common/config/logging.properties is used and
what to do with it.
-- Restore the NettySecurityClientTest and figure out what needs changed to
make it work.
- Restore the Travis config file
- Delete the old DELETE-ME-logging.properties and
DELETE-ME-tests-logging.properties files once all needed comparisons during old
test etc config replacements are done.
- Update references to JBL and logging.properties in the documentation
- Decide what if anything should be done around the removed logging config
reload bits (Log4J2 enables reload itself, via its own config...or updates via
management)
- Decide if we should use the auto-detected log4j2.properties config filename
instead
+
+done:
+- Fix stacktraces of generated exceptions not to include the generated
'logmessage' method creating it.
+- Restore the NettySecurityClientTest and figure out what needs changed to
make it work.
+ * Don't restore it at all.. just keep it gone
diff --git
a/artemis-log-processor/src/main/java/org/apache/activemq/artemis/logprocessor/LogProcessor.java
b/artemis-log-processor/src/main/java/org/apache/activemq/artemis/logprocessor/LogProcessor.java
index 15fd37e187..f61c7c1085 100644
---
a/artemis-log-processor/src/main/java/org/apache/activemq/artemis/logprocessor/LogProcessor.java
+++
b/artemis-log-processor/src/main/java/org/apache/activemq/artemis/logprocessor/LogProcessor.java
@@ -140,6 +140,12 @@ public class LogProcessor extends AbstractProcessor {
writerOutput.println(" private final Logger logger;");
writerOutput.println();
+ writerOutput.println(" private static void
_copyStackTraceMinusOne(final Throwable e) {");
+ writerOutput.println(" final StackTraceElement[] st =
e.getStackTrace();");
+ writerOutput.println("
e.setStackTrace(java.util.Arrays.copyOfRange(st, 1, st.length));");
+ writerOutput.println(" }");
+ writerOutput.println();
+
writerOutput.println(" public " + simpleClassName + "(Logger
logger ) {");
writerOutput.println(" this.logger = logger;");
writerOutput.println(" }");
@@ -288,6 +294,7 @@ public class LogProcessor extends AbstractProcessor {
if (exceptionParameter != null) {
writerOutput.println(" " + exceptionVariableName +
".initCause(" + exceptionParameter.getSimpleName() + ");");
}
+ writerOutput.println(" _copyStackTraceMinusOne(" +
exceptionVariableName + ");");
writerOutput.println(" return " + exceptionVariableName +
";");
writerOutput.println(" }");
}
diff --git
a/artemis-log-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundleTest.java
b/artemis-log-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundleTest.java
index 9b79db82cf..b228035360 100644
---
a/artemis-log-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundleTest.java
+++
b/artemis-log-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundleTest.java
@@ -18,6 +18,8 @@
package org.apache.activemq.artemis.logprocessor;
import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.util.UUID;
import org.junit.Assert;
@@ -41,6 +43,10 @@ public class SimpleBundleTest {
public void testException() {
Exception ex = SimpleBundle.MESSAGES.someException();
Assert.assertEquals("TST3: EX", ex.getMessage());
+ StringWriter stringWriter = new StringWriter();
+ PrintWriter writer = new PrintWriter(stringWriter);
+ ex.printStackTrace(writer);
+ Assert.assertEquals("The method name (someException) should not be part
of the stack trace", -1, stringWriter.toString().lastIndexOf("someException"));
}
@Test