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/07/29 16:25:56 UTC

[activemq-artemis] branch new-logging updated: make start on updating remaining integration tests, manipulating levels etc

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


The following commit(s) were added to refs/heads/new-logging by this push:
     new d49f604bd0 make start on updating remaining integration tests, manipulating levels etc
d49f604bd0 is described below

commit d49f604bd0bd6c9c044feebea2392a9914a0ccdd
Author: Robbie Gemmell <ro...@apache.org>
AuthorDate: Fri Jul 29 17:25:07 2022 +0100

    make start on updating remaining integration tests, manipulating levels etc
---
 .../artemis/logs/AssertionLoggerHandler.java       | 28 ++++++++++++++++++++++
 .../integration/paging/AddressFullLoggingTest.java | 15 +++++++-----
 2 files changed, 37 insertions(+), 6 deletions(-)

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 224f016e6a..4456c5d34d 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
@@ -26,6 +26,8 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.regex.Pattern;
 
 import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.Filter;
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.LogEvent;
@@ -110,6 +112,13 @@ public class AssertionLoggerHandler extends AbstractAppender {
       return false;
    }
 
+   public static LogLevel setLevel(String loggerName, LogLevel level) {
+      final Logger logger = LogManager.getLogger(loggerName);
+      final Level implLevel = logger.getLevel();
+
+      return LogLevel.fromImplLevel(implLevel);
+   }
+
    public static boolean findText(long mstimeout, String... text) {
 
       long timeMax = System.currentTimeMillis() + mstimeout;
@@ -243,6 +252,7 @@ public class AssertionLoggerHandler extends AbstractAppender {
    }
 
    public enum LogLevel {
+      OFF(Level.OFF),
       ERROR(Level.ERROR),
       WARN(Level.WARN),
       INFO(Level.INFO),
@@ -258,6 +268,24 @@ public class AssertionLoggerHandler extends AbstractAppender {
       private Level toImplLevel() {
          return implLevel;
       }
+
+      private static LogLevel fromImplLevel(Level implLevel) {
+         if (Level.ERROR.equals(implLevel)) {
+            return ERROR;
+         } else if (Level.WARN.equals(implLevel)) {
+            return WARN;
+         } else if (Level.INFO.equals(implLevel)) {
+            return INFO;
+         } else if (Level.DEBUG.equals(implLevel)) {
+            return DEBUG;
+         } else if (Level.TRACE.equals(implLevel)) {
+            return TRACE;
+         } else if (Level.OFF.equals(implLevel)) {
+            return OFF;
+         } else {
+            throw new IllegalArgumentException("Unexpected level:" + implLevel);
+         }
+      }
    }
 
 }
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/paging/AddressFullLoggingTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/paging/AddressFullLoggingTest.java
index 0430365642..97821433c3 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/paging/AddressFullLoggingTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/paging/AddressFullLoggingTest.java
@@ -32,33 +32,36 @@ import org.apache.activemq.artemis.api.core.client.ClientSession;
 import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
 import org.apache.activemq.artemis.api.core.client.ServerLocator;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.core.server.ActiveMQServerLogger;
 import org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy;
 import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
 import org.apache.activemq.artemis.logs.AssertionLoggerHandler;
+import org.apache.activemq.artemis.logs.AssertionLoggerHandler.LogLevel;
 import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
 import org.apache.activemq.artemis.utils.ActiveMQThreadFactory;
 import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 
-@Ignore("Needs updated to account for logging impl changes") //TODO: reinstate
 public class AddressFullLoggingTest extends ActiveMQTestBase {
 
-   //TODO: private static final Logger logManager = org.jboss.logmanager.Logger.getLogger(ActiveMQServerLogger.class.getPackage().getName());
-   //TODO: private static java.util.logging.Level previousLevel = logManager.getLevel();
+   private static final String SERVER_LOGGER_NAME = ActiveMQServerLogger.class.getPackage().getName();
+
+   private static LogLevel previousLevel = null;
 
    @BeforeClass
    public static void prepareLogger() {
-      //TODO: logManager.setLevel(Level.INFO);
+      previousLevel = AssertionLoggerHandler.setLevel(SERVER_LOGGER_NAME, LogLevel.INFO);
+
       AssertionLoggerHandler.startCapture();
    }
 
    @AfterClass
    public static void clearLogger() {
       AssertionLoggerHandler.stopCapture();
-      //TODO: logManager.setLevel(previousLevel);
+
+      AssertionLoggerHandler.setLevel(SERVER_LOGGER_NAME, previousLevel);
    }
 
    @Test