You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ro...@apache.org on 2022/09/23 17:03:33 UTC

[activemq-artemis] branch new-logging updated (fa5f5b0a11 -> 44e33869ff)

This is an automated email from the ASF dual-hosted git repository.

robbie pushed a change to branch new-logging
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


    from fa5f5b0a11 Adding regex attribute on LogProcessor to validate IDs.
     new cb8626b244 tweaks
     new 3041671694 remove unused out-of-order exception support to simplify
     new 48181263f0 remove TODO as we arent doing async append in ALH
     new 62c0edbdf0 remove seemingly unnecessary space, see what happens
     new d704500af3 format some generated bits more consistent with regular code style
     new 44e33869ff consolidate generated logger output regardless of exception arg, gate with enabled checks to avoid overhead for many-arg methods if not enabled

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../activemq/artemis/utils/SpawnedVMSupport.java   |   3 +-
 .../artemis/logs/annotation/LogBundle.java         |   2 -
 .../processor/LogAnnotationProcessor.java          | 121 +++++++++++----------
 .../artemis/logprocessor/SimpleBundle.java         |  12 +-
 .../artemis/logprocessor/SimpleBundleTest.java     |  52 +--------
 .../artemis/logs/AssertionLoggerHandler.java       |   1 -
 6 files changed, 76 insertions(+), 115 deletions(-)


[activemq-artemis] 04/06: remove seemingly unnecessary space, see what happens

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

robbie pushed a commit to branch new-logging
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit 62c0edbdf0bcd229d387744f4a3d9aaf99785883
Author: Robbie Gemmell <ro...@apache.org>
AuthorDate: Fri Sep 23 16:22:28 2022 +0100

    remove seemingly unnecessary space, see what happens
---
 .../main/java/org/apache/activemq/artemis/utils/SpawnedVMSupport.java  | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/SpawnedVMSupport.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/SpawnedVMSupport.java
index 164d1d5da0..393682d03f 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/SpawnedVMSupport.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/SpawnedVMSupport.java
@@ -206,8 +206,7 @@ public class SpawnedVMSupport {
 
       String loggingConfigFile = System.getProperty("log4j2.configurationFile");
       if (loggingConfigFile != null) {
-         // TODO: why does it add the trailing space here but not other places?
-         commandList.add("-Dlog4j2.configurationFile=" + loggingConfigFile + " ");
+         commandList.add("-Dlog4j2.configurationFile=" + loggingConfigFile);
       }
 
       String jacocoAgent = System.getProperty("jacoco.agent");


[activemq-artemis] 06/06: consolidate generated logger output regardless of exception arg, gate with enabled checks to avoid overhead for many-arg methods if not enabled

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

robbie pushed a commit to branch new-logging
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit 44e33869ff2aa6ca66e9b3323405fc71a6719c3b
Author: Robbie Gemmell <ro...@apache.org>
AuthorDate: Fri Sep 23 18:02:31 2022 +0100

    consolidate generated logger output regardless of exception arg, gate with enabled checks to avoid overhead for many-arg methods if not enabled
---
 .../processor/LogAnnotationProcessor.java          | 88 ++++++++++++----------
 1 file changed, 48 insertions(+), 40 deletions(-)

diff --git a/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java b/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java
index 67f83d3650..cf1ceae60e 100644
--- a/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java
+++ b/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java
@@ -31,7 +31,6 @@ import javax.lang.model.type.TypeMirror;
 import javax.tools.Diagnostic;
 import javax.tools.JavaFileObject;
 import java.io.PrintWriter;
-import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -282,7 +281,7 @@ public class LogAnnotationProcessor extends AbstractProcessor {
          callList.append(parameter.getSimpleName());
          if (parameters.hasNext()) {
             writerOutput.write(", ");
-            callList.append(",");
+            callList.append(", ");
          }
       }
 
@@ -403,9 +402,7 @@ public class LogAnnotationProcessor extends AbstractProcessor {
       List<? extends VariableElement> parametersList = executableMember.getParameters();
 
       boolean hasParameters = false;
-
       VariableElement exceptionParameter = null;
-      ArrayList<VariableElement> nonExceptionParameters = new ArrayList<>();
 
       Iterator<? extends VariableElement> parameters = parametersList.iterator();
       while (parameters.hasNext()) {
@@ -415,8 +412,6 @@ public class LogAnnotationProcessor extends AbstractProcessor {
          boolean isException = verifyIfExceptionArgument(executableMember, parameter, parameters.hasNext(), exceptionParameter != null);
          if (isException) {
             exceptionParameter = parameter;
-         } else {
-            nonExceptionParameters.add(parameter);
          }
 
          writerOutput.write(parameter.asType() + " " + parameter.getSimpleName());
@@ -427,58 +422,71 @@ public class LogAnnotationProcessor extends AbstractProcessor {
 
       writerOutput.println(") {");
 
-      // the one that will be used on the logger call
-      StringBuffer callList = new StringBuffer();
-      parameters = nonExceptionParameters.iterator();
-
-      while (parameters.hasNext()) {
-         hasParameters = true;
-         VariableElement parameter = parameters.next();
-         callList.append(parameter.getSimpleName());
-         if (parameters.hasNext()) {
-            callList.append(",");
+      StringBuffer callList = null;
+      if (hasParameters) {
+         // the one that will be used on the logger call
+         callList = new StringBuffer();
+
+         parameters = parametersList.iterator();
+         while (parameters.hasNext()) {
+            VariableElement parameter = parameters.next();
+            callList.append(parameter.getSimpleName());
+            if (parameters.hasNext()) {
+               callList.append(", ");
+            }
          }
       }
 
-      final String methodName = getLogOutputMethodName(messageAnnotation);
-
+      final String isEnabledMethodName = getLoggerIsEnabledMethodName(messageAnnotation);
+      final String methodName = getLoggerOutputMethodName(messageAnnotation);
       final String formattingString = encodeSpecialChars(bundleAnnotation.projectCode() + messageAnnotation.id() + ": " + messageAnnotation.value());
-      if (exceptionParameter != null) {
-         // TODO: needed? Logger impl handles picking up exception arg at end itself, would only incur array overhead if needed (>2 args) rather than always as this does.
-         // ALso looks like MessageFormatter always instanceof's the last arg, whereas the Logger impl only does it if there is an unused param.
-         // Could perhaps add if<level>Enabled() guards to avoid overhead in many-arg cases.
-         // Could optimise for the 2arg message+throwable case.
-         writerOutput.println("     FormattingTuple output = org.slf4j.helpers.MessageFormatter.arrayFormat(\"" + formattingString + "\",new Object[] {" + callList + "});");
-         writerOutput.println("     logger." + methodName + "(output.getMessage(), " + exceptionParameter.getSimpleName() + ");");
+
+      writerOutput.println("      if (logger." + isEnabledMethodName + "()) {");
+
+      if (hasParameters) {
+         writerOutput.println("         logger." + methodName + "(\"" + formattingString + "\", " + callList + ");");
       } else {
-         if (!hasParameters) {
-            writerOutput.println("      logger." + methodName + "(\"" + formattingString + "\");");
-         } else {
-            writerOutput.println("      logger." + methodName + "(\"" + formattingString + "\", " + callList + ");");
-         }
+         writerOutput.println("         logger." + methodName + "(\"" + formattingString + "\");");
       }
+
+      writerOutput.println("      }");
+
       writerOutput.println("   }");
       writerOutput.println();
    }
 
-   private static String getLogOutputMethodName(LogMessage messageAnnotation) {
-      final String methodName;
+   private static String getLoggerOutputMethodName(LogMessage messageAnnotation) {
       switch (messageAnnotation.level()) {
          case WARN:
-            methodName = "warn"; break;
+            return "warn";
          case INFO:
-            methodName = "info"; break;
+            return "info";
          case ERROR:
-            methodName = "error"; break;
+            return "error";
          case DEBUG: // TODO remove this
-            methodName = "debug"; break;
+            return "debug";
          case TRACE: // TODO remove this
-            methodName = "trace"; break;
+            return  "trace";
          default:
-            throw new IllegalStateException("Illegal method level: " + messageAnnotation.level());
+            throw new IllegalStateException("Illegal log level: " + messageAnnotation.level());
       }
+   }
 
-      return methodName;
+   private static String getLoggerIsEnabledMethodName(LogMessage messageAnnotation) {
+      switch (messageAnnotation.level()) {
+         case WARN:
+            return "isWarnEnabled";
+         case INFO:
+            return "isInfoEnabled";
+         case ERROR:
+            return "isErrorEnabled";
+         case DEBUG: // TODO remove this
+            return "isDebugEnabled";
+         case TRACE: // TODO remove this
+            return "isTraceEnabled";
+         default:
+            throw new IllegalStateException("Illegal log level: " + messageAnnotation.level());
+      }
    }
 
    private static void tupples(String arg, char open, char close, Consumer<String> stringConsumer) {
@@ -534,4 +542,4 @@ public class LogAnnotationProcessor extends AbstractProcessor {
 
       return isException;
    }
-}
\ No newline at end of file
+}


[activemq-artemis] 02/06: remove unused out-of-order exception support to simplify

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

robbie pushed a commit to branch new-logging
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit 30416716944b94ce84770d046a8c36e5922cc5a9
Author: Robbie Gemmell <ro...@apache.org>
AuthorDate: Fri Sep 23 16:10:13 2022 +0100

    remove unused out-of-order exception support to simplify
---
 .../artemis/logs/annotation/LogBundle.java         |  2 -
 .../processor/LogAnnotationProcessor.java          | 11 ++---
 .../artemis/logprocessor/SimpleBundle.java         | 12 ++---
 .../artemis/logprocessor/SimpleBundleTest.java     | 52 +++-------------------
 4 files changed, 13 insertions(+), 64 deletions(-)

diff --git a/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/LogBundle.java b/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/LogBundle.java
index b57c4b820b..3c6086fffc 100644
--- a/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/LogBundle.java
+++ b/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/LogBundle.java
@@ -30,6 +30,4 @@ public @interface LogBundle {
    /** if set, every code generated must match this regular expression.
     *  this is useful to validate ranges.*/
    String regexID() default "";
-
-   boolean enforceExceptionParameterAsLast() default true;
 }
diff --git a/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java b/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java
index 7bed6c9cf1..2d9e0bd666 100644
--- a/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java
+++ b/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java
@@ -265,9 +265,7 @@ public class LogAnnotationProcessor extends AbstractProcessor {
       Iterator<? extends VariableElement> parameters = executableMember.getParameters().iterator();
 
       boolean hasParameters = false;
-
       VariableElement exceptionParameter = null;
-      final boolean enforceLastParam = bundleAnnotation.enforceExceptionParameterAsLast();
 
       // the one that will be used on the call
       StringBuffer callList = new StringBuffer();
@@ -275,7 +273,7 @@ public class LogAnnotationProcessor extends AbstractProcessor {
          hasParameters = true;
          VariableElement parameter = parameters.next();
 
-         boolean isException = verifyIfExceptionArgument(executableMember, parameter, enforceLastParam, parameters.hasNext(), exceptionParameter != null);
+         boolean isException = verifyIfExceptionArgument(executableMember, parameter, parameters.hasNext(), exceptionParameter != null);
          if (isException) {
             exceptionParameter = parameter;
          }
@@ -407,14 +405,13 @@ public class LogAnnotationProcessor extends AbstractProcessor {
 
       VariableElement exceptionParameter = null;
       ArrayList<VariableElement> nonExceptionParameters = new ArrayList<>();
-      final boolean enforceLastParam = bundleAnnotation.enforceExceptionParameterAsLast();
 
       Iterator<? extends VariableElement> parameters = parametersList.iterator();
       while (parameters.hasNext()) {
          hasParameters = true;
          VariableElement parameter = parameters.next();
 
-         boolean isException = verifyIfExceptionArgument(executableMember, parameter, enforceLastParam, parameters.hasNext(), exceptionParameter != null);
+         boolean isException = verifyIfExceptionArgument(executableMember, parameter, parameters.hasNext(), exceptionParameter != null);
          if (isException) {
             exceptionParameter = parameter;
          } else {
@@ -519,14 +516,14 @@ public class LogAnnotationProcessor extends AbstractProcessor {
       }
    }
 
-   private static boolean verifyIfExceptionArgument(final ExecutableElement executableMember, final VariableElement parameter, final boolean enforceLastParam, final boolean hasMoreParams, final boolean hasExistingException) {
+   private static boolean verifyIfExceptionArgument(final ExecutableElement executableMember, final VariableElement parameter, final boolean hasMoreParams, final boolean hasExistingException) {
       boolean isException = isException(parameter.asType(), parameter);
       if (DEBUG) {
          debug("Parameter " + parameter + (isException ? "is" : "is not") + " an exception");
       }
 
       if (isException) {
-         if (enforceLastParam && hasMoreParams) {
+         if (hasMoreParams) {
             throw new IllegalArgumentException("Exception argument " + parameter + " has to be the last argument on the list. Look at: " + executableMember);
          }
 
diff --git a/artemis-log-annotation-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundle.java b/artemis-log-annotation-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundle.java
index 5ae8285dd2..c7636159e7 100644
--- a/artemis-log-annotation-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundle.java
+++ b/artemis-log-annotation-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundle.java
@@ -26,7 +26,7 @@ import org.apache.activemq.artemis.logs.annotation.Message;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@LogBundle(projectCode = "TST", enforceExceptionParameterAsLast = false)
+@LogBundle(projectCode = "TST")
 public interface SimpleBundle {
 
    static SimpleBundle init() {
@@ -77,16 +77,10 @@ public interface SimpleBundle {
    @LogMessage(id = 12, value = "This message has the following parameter:: {}", level = LogMessage.Level.WARN)
    void myExceptionLogger(String parameter, MyException e);
 
-   @LogMessage(id = 13, value = "This message has the following parameter:: p{}", level = LogMessage.Level.WARN)
-   void outOfOrder(MyException e, String parameter);
-
-   @LogMessage(id = 14, value = "OutOfOrder with 4 parameters p{} p{} p{}", level = LogMessage.Level.WARN)
-   void outOfOrder(MyException p1, String p2, String p3, String p4);
-
-   @LogMessage(id = 15, value = "Long with 5 parameters p{} p{} p{} p{} p{}", level = LogMessage.Level.WARN)
+   @LogMessage(id = 13, value = "Long with 5 parameters p{} p{} p{} p{} p{}", level = LogMessage.Level.WARN)
    void longParameters(String p1, String p2, String p3, String p4, String p5);
 
-   @LogMessage(id = 16, value = "An Exceptional example", level = LogMessage.Level.WARN)
+   @LogMessage(id = 14, value = "An Exceptional example", level = LogMessage.Level.WARN)
    void onlyException(MyException e);
 
 
diff --git a/artemis-log-annotation-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundleTest.java b/artemis-log-annotation-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundleTest.java
index b228035360..e9cf827364 100644
--- a/artemis-log-annotation-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundleTest.java
+++ b/artemis-log-annotation-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundleTest.java
@@ -97,46 +97,6 @@ public class SimpleBundleTest {
       SimpleBundle.MESSAGES.myExceptionLogger("hello2", new MyException("this is an exception"));
    }
 
-   @Test
-   public void outOfOrderException() {
-      AssertionLoggerHandler.startCapture(false, true);
-      try {
-         SimpleBundle.MESSAGES.outOfOrder(createMyException("NotHere"), "2");
-         Assert.assertTrue("parameter2 was not on the output", AssertionLoggerHandler.findText("p2"));
-         Assert.assertFalse(AssertionLoggerHandler.findText("pNotHere"));
-         Assert.assertTrue("Stack trace was not printed", AssertionLoggerHandler.findText("createMyException"));
-         Assert.assertFalse("logging not working", AssertionLoggerHandler.findText("{}"));
-      } finally {
-         AssertionLoggerHandler.stopCapture();
-      }
-   }
-
-   @Test
-   public void outOfOrderExceptionLongParameter() {
-      try {
-         AssertionLoggerHandler.startCapture(false, false);
-         SimpleBundle.MESSAGES.outOfOrder(new MyException("ex1"), "2", "3", "4");
-         Assert.assertFalse("Exception should not be on the output", AssertionLoggerHandler.findText("pex1"));
-         Assert.assertTrue("parameter not found", AssertionLoggerHandler.findText("p2"));
-         Assert.assertTrue("parameter not found", AssertionLoggerHandler.findText("p3"));
-         Assert.assertTrue("parameter not found", AssertionLoggerHandler.findText("p4"));
-         Assert.assertFalse("formatting not working", AssertionLoggerHandler.findText("{}"));
-
-         AssertionLoggerHandler.clear();
-         AssertionLoggerHandler.startCapture(false, true);
-
-         SimpleBundle.MESSAGES.outOfOrder(createMyException("ex1"), "2", "3", "4");
-         Assert.assertFalse("Exception should not be on the output", AssertionLoggerHandler.findText("pex1"));
-         Assert.assertTrue("parameter not found", AssertionLoggerHandler.findText("p3"));
-         Assert.assertTrue("parameter not found", AssertionLoggerHandler.findText("p4"));
-         Assert.assertTrue("stack not found", AssertionLoggerHandler.findText("createMyException"));
-         Assert.assertFalse("formatting not working", AssertionLoggerHandler.findText("{}"));
-
-      } finally {
-         AssertionLoggerHandler.stopCapture();
-      }
-   }
-
    @Test
    public void longList() {
       AssertionLoggerHandler.startCapture(false, true);
@@ -159,18 +119,18 @@ public class SimpleBundleTest {
       try {
          AssertionLoggerHandler.startCapture(false, false);
 
-         SimpleBundle.MESSAGES.onlyException(createMyException("MSG7777"));
+         SimpleBundle.MESSAGES.onlyException(createMyExceptionBreadcrumbMethod("MSG7777"));
 
-         Assert.assertTrue(AssertionLoggerHandler.findText("TST16"));
+         Assert.assertTrue(AssertionLoggerHandler.findText("TST14"));
          Assert.assertFalse(AssertionLoggerHandler.findText("MSG7777"));
 
          AssertionLoggerHandler.clear();
 
          AssertionLoggerHandler.startCapture(false, true);
-         SimpleBundle.MESSAGES.onlyException(createMyException("MSG7777"));
-         Assert.assertTrue(AssertionLoggerHandler.findText("TST16"));
+         SimpleBundle.MESSAGES.onlyException(createMyExceptionBreadcrumbMethod("MSG7777"));
+         Assert.assertTrue(AssertionLoggerHandler.findText("TST14"));
          Assert.assertTrue(AssertionLoggerHandler.findText("MSG7777"));
-         Assert.assertTrue(AssertionLoggerHandler.findText("createMyException"));
+         Assert.assertTrue(AssertionLoggerHandler.findText("createMyExceptionBreadcrumbMethod"));
       } finally {
          AssertionLoggerHandler.stopCapture();
       }
@@ -178,7 +138,7 @@ public class SimpleBundleTest {
 
 
    // I'm doing it on a method just to assert if this method will appear on the stack trace
-   private MyException createMyException(String message) {
+   private MyException createMyExceptionBreadcrumbMethod(String message) {
       return new MyException(message);
    }
 


[activemq-artemis] 01/06: tweaks

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

robbie pushed a commit to branch new-logging
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit cb8626b244fcc3f47ceb07f4f481e2bd5411d48e
Author: Robbie Gemmell <ro...@apache.org>
AuthorDate: Fri Sep 23 15:44:54 2022 +0100

    tweaks
---
 .../processor/LogAnnotationProcessor.java          | 40 +++++++++++++---------
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java b/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java
index 0de79c2606..7bed6c9cf1 100644
--- a/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java
+++ b/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java
@@ -65,7 +65,7 @@ public class LogAnnotationProcessor extends AbstractProcessor {
    }
 
    /**
-    * define a system variable ARTEMIS_LOG_ANNOTATION_PROCESSOR_DEBUG=true in order to see debug output
+    * define environment variable ARTEMIS_LOG_ANNOTATION_PROCESSOR_DEBUG=true in order to see debug output
     */
    protected static void debug(String debugMessage) {
       if (DEBUG) {
@@ -443,23 +443,9 @@ public class LogAnnotationProcessor extends AbstractProcessor {
          }
       }
 
-      String methodName;
-      switch (messageAnnotation.level()) {
-         case WARN:
-            methodName = "warn"; break;
-         case INFO:
-            methodName = "info"; break;
-         case ERROR:
-            methodName = "error"; break;
-         case DEBUG: // TODO remove this
-            methodName = "debug"; break;
-         case TRACE: // TODO remove this
-            methodName = "trace"; break;
-         default:
-            throw new IllegalStateException("illegal method level " + messageAnnotation.level());
-      }
+      final String methodName = getLogOutputMethodName(messageAnnotation);
 
-      String formattingString = encodeSpecialChars(bundleAnnotation.projectCode() + messageAnnotation.id() + ": " + messageAnnotation.value());
+      final String formattingString = encodeSpecialChars(bundleAnnotation.projectCode() + messageAnnotation.id() + ": " + messageAnnotation.value());
       if (exceptionParameter != null) {
          // TODO: needed? Logger impl handles picking up exception arg at end itself, would only incur array overhead if needed (>2 args) rather than always as this does.
          // ALso looks like MessageFormatter always instanceof's the last arg, whereas the Logger impl only does it if there is an unused param.
@@ -478,6 +464,26 @@ public class LogAnnotationProcessor extends AbstractProcessor {
       writerOutput.println();
    }
 
+   private static String getLogOutputMethodName(LogMessage messageAnnotation) {
+      final String methodName;
+      switch (messageAnnotation.level()) {
+         case WARN:
+            methodName = "warn"; break;
+         case INFO:
+            methodName = "info"; break;
+         case ERROR:
+            methodName = "error"; break;
+         case DEBUG: // TODO remove this
+            methodName = "debug"; break;
+         case TRACE: // TODO remove this
+            methodName = "trace"; break;
+         default:
+            throw new IllegalStateException("Illegal method level: " + messageAnnotation.level());
+      }
+
+      return methodName;
+   }
+
    private static void tupples(String arg, char open, char close, Consumer<String> stringConsumer) {
       int openAt = -1;
       for (int i = 0; i < arg.length(); i++) {


[activemq-artemis] 05/06: format some generated bits more consistent with regular code style

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

robbie pushed a commit to branch new-logging
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit d704500af32ecd49e854bd516bc1467a7435c7b6
Author: Robbie Gemmell <ro...@apache.org>
AuthorDate: Fri Sep 23 17:14:54 2022 +0100

    format some generated bits more consistent with regular code style
---
 .../annotation/processor/LogAnnotationProcessor.java     | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java b/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java
index 2d9e0bd666..67f83d3650 100644
--- a/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java
+++ b/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java
@@ -287,18 +287,17 @@ public class LogAnnotationProcessor extends AbstractProcessor {
       }
 
       // the real implementation
-      writerOutput.println(")");
-      writerOutput.println("   {");
+      writerOutput.println(") {");
 
       String formattingString = encodeSpecialChars(bundleAnnotation.projectCode() + messageAnnotation.id() + ": " + messageAnnotation.value());
       if (!hasParameters) {
-         writerOutput.println("     String returnString = \"" + formattingString + "\";");
+         writerOutput.println("      String returnString = \"" + formattingString + "\";");
       } else {
-         writerOutput.println("     String returnString = MessageFormatter.arrayFormat(\"" + formattingString + "\", new Object[]{" + callList + "}).getMessage();");
+         writerOutput.println("      String returnString = MessageFormatter.arrayFormat(\"" + formattingString + "\", new Object[]{" + callList + "}).getMessage();");
       }
 
       if (executableMember.getReturnType().toString().equals(String.class.getName())) {
-         writerOutput.println("     return returnString;");
+         writerOutput.println("      return returnString;");
       } else {
          writerOutput.println();
          writerOutput.println("      {");
@@ -378,7 +377,9 @@ public class LogAnnotationProcessor extends AbstractProcessor {
       // This is really a debug output
       writerOutput.println("   // " + loggerAnnotation.toString());
       writerOutput.println("   @Override");
-      writerOutput.println("   public Logger " + executableMember.getSimpleName() + "() { return logger; }");
+      writerOutput.println("   public Logger " + executableMember.getSimpleName() + "() {");
+      writerOutput.println("      return logger;");
+      writerOutput.println("   }");
       writerOutput.println();
    }
 
@@ -424,8 +425,7 @@ public class LogAnnotationProcessor extends AbstractProcessor {
          }
       }
 
-      writerOutput.println(")");
-      writerOutput.println("   {");
+      writerOutput.println(") {");
 
       // the one that will be used on the logger call
       StringBuffer callList = new StringBuffer();


[activemq-artemis] 03/06: remove TODO as we arent doing async append in ALH

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

robbie pushed a commit to branch new-logging
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit 48181263f06d6491fe8a1c387077b83f6e00d9d9
Author: Robbie Gemmell <ro...@apache.org>
AuthorDate: Fri Sep 23 16:10:49 2022 +0100

    remove TODO as we arent doing async append in ALH
---
 .../java/org/apache/activemq/artemis/logs/AssertionLoggerHandler.java    | 1 -
 1 file changed, 1 deletion(-)

diff --git a/artemis-unit-test-support/src/main/java/org/apache/activemq/artemis/logs/AssertionLoggerHandler.java b/artemis-unit-test-support/src/main/java/org/apache/activemq/artemis/logs/AssertionLoggerHandler.java
index f78f92bb9a..e47565716e 100644
--- a/artemis-unit-test-support/src/main/java/org/apache/activemq/artemis/logs/AssertionLoggerHandler.java
+++ b/artemis-unit-test-support/src/main/java/org/apache/activemq/artemis/logs/AssertionLoggerHandler.java
@@ -72,7 +72,6 @@ public class AssertionLoggerHandler extends AbstractAppender {
    @Override
    public void append(LogEvent event) {
       if (capture) {
-         //TODO: see getFormattedMessage() around handling StringBuilderFormattable interface as well, check it out
          String formattedMessage = event.getMessage().getFormattedMessage();
 
          if (captureStackTrace && event.getThrown() != null) {