Use slf4j Marker from common repo 74/123074/7
authorTaka Cho <takamune.cho@att.com>
Tue, 3 Aug 2021 17:28:28 +0000 (13:28 -0400)
committerTaka Cho <takamune.cho@att.com>
Fri, 6 Aug 2021 17:13:13 +0000 (13:13 -0400)
using slf4j Marker from common repo

Issue-ID: POLICY-3087
Change-Id: Iefbd6fa9ab2dfa6388508cb6ffd6cf1358b45ccc
Signed-off-by: Taka Cho <takamune.cho@att.com>
18 files changed:
feature-lifecycle/pom.xml
feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java
feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java
feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java
feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java
feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java
policy-management/pom.xml
policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java
policy-management/src/main/java/org/onap/policy/drools/system/Main.java
policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java
policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsControllerUpgradesTest.java
policy-utils/pom.xml
policy-utils/src/main/java/org/onap/policy/drools/utils/logging/LoggerMarkerFilter.java [deleted file]
policy-utils/src/main/java/org/onap/policy/drools/utils/logging/LoggerUtil.java
policy-utils/src/main/java/org/onap/policy/drools/utils/logging/MdcTransactionImpl.java
policy-utils/src/test/java/org/onap/policy/drools/utils/PropertyUtilTest.java
policy-utils/src/test/java/org/onap/policy/drools/utils/logging/LoggerUtilTest.java
policy-utils/src/test/resources/interpolation.properties

index 5775afe..9bec81e 100644 (file)
             <version>${policy.common.version}</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.onap.policy.common</groupId>
+            <artifactId>utils</artifactId>
+            <version>${policy.common.version}</version>
+            <scope>provided</scope>
+        </dependency>
+
         <dependency>
             <groupId>org.onap.policy.models</groupId>
             <artifactId>policy-models-examples</artifactId>
index 7201d62..df9e5ee 100644 (file)
@@ -36,12 +36,12 @@ import org.junit.Before;
 import org.junit.Test;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.logging.LoggerUtils;
 import org.onap.policy.common.utils.resources.ResourceUtils;
 import org.onap.policy.common.utils.time.PseudoScheduledExecutorService;
 import org.onap.policy.common.utils.time.TestTimeMulti;
 import org.onap.policy.drools.persistence.SystemPersistenceConstants;
 import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.drools.utils.logging.LoggerUtil;
 import org.onap.policy.models.pdp.concepts.PdpStatus;
 import org.onap.policy.models.pdp.enums.PdpState;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -101,9 +101,9 @@ public class LifecycleFsmTest {
      */
     @Before
     public void beforeTest() throws CoderException, IOException {
-        LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
-        LoggerUtil.setLevel("org.onap.policy.common.endpoints", "WARN");
-        LoggerUtil.setLevel("org.onap.policy.drools", "INFO");
+        LoggerUtils.setLevel(LoggerUtils.ROOT_LOGGER, "INFO");
+        LoggerUtils.setLevel("org.onap.policy.common.endpoints", "WARN");
+        LoggerUtils.setLevel("org.onap.policy.drools", "INFO");
         SystemPersistenceConstants.getManager().setConfigurationDir("target/test-classes");
 
         fsm = new LifecycleFsm() {
index 15af959..c97133b 100644 (file)
@@ -46,6 +46,7 @@ import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicFactories;
 import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.logging.LoggerUtils;
 import org.onap.policy.common.utils.resources.ResourceUtils;
 import org.onap.policy.common.utils.time.PseudoScheduledExecutorService;
 import org.onap.policy.common.utils.time.TestTimeMulti;
@@ -54,7 +55,6 @@ import org.onap.policy.drools.domain.models.controller.ControllerPolicy;
 import org.onap.policy.drools.persistence.SystemPersistenceConstants;
 import org.onap.policy.drools.system.PolicyControllerConstants;
 import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.drools.utils.logging.LoggerUtil;
 import org.onap.policy.models.pdp.concepts.PdpStateChange;
 import org.onap.policy.models.pdp.concepts.PdpUpdate;
 import org.onap.policy.models.pdp.enums.PdpState;
@@ -117,9 +117,9 @@ public class LifecycleFsmUpdateTest {
      */
     @BeforeClass
     public static void setUp() throws IOException {
-        LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
-        LoggerUtil.setLevel("org.onap.policy.common.endpoints", "WARN");
-        LoggerUtil.setLevel("org.onap.policy.drools", "INFO");
+        LoggerUtils.setLevel(LoggerUtils.ROOT_LOGGER, "INFO");
+        LoggerUtils.setLevel("org.onap.policy.common.endpoints", "WARN");
+        LoggerUtils.setLevel("org.onap.policy.drools", "INFO");
 
         SystemPersistenceConstants.getManager().setConfigurationDir("target/test-classes");
 
index 67c7898..eeac888 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -31,12 +31,12 @@ import org.junit.BeforeClass;
 import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicFactories;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.logging.LoggerUtils;
 import org.onap.policy.common.utils.resources.ResourceUtils;
 import org.onap.policy.common.utils.time.PseudoScheduledExecutorService;
 import org.onap.policy.common.utils.time.TestTimeMulti;
 import org.onap.policy.drools.persistence.SystemPersistenceConstants;
 import org.onap.policy.drools.system.PolicyControllerConstants;
-import org.onap.policy.drools.utils.logging.LoggerUtil;
 import org.onap.policy.models.pdp.concepts.PdpStatus;
 import org.onap.policy.models.pdp.enums.PdpMessageType;
 import org.onap.policy.models.pdp.enums.PdpState;
@@ -56,9 +56,9 @@ public abstract class LifecycleStateRunningTest {
      */
     @BeforeClass
     public static void setUp() throws IOException {
-        LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
-        LoggerUtil.setLevel("org.onap.policy.common.endpoints", "WARN");
-        LoggerUtil.setLevel("org.onap.policy.drools", "INFO");
+        LoggerUtils.setLevel(LoggerUtils.ROOT_LOGGER, "INFO");
+        LoggerUtils.setLevel("org.onap.policy.common.endpoints", "WARN");
+        LoggerUtils.setLevel("org.onap.policy.drools", "INFO");
         SystemPersistenceConstants.getManager().setConfigurationDir("target/test-classes");
         controllerSupport.createController();
     }
index cf6f451..3d8d08b 100644 (file)
@@ -33,9 +33,9 @@ import java.util.Collections;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.onap.policy.common.utils.logging.LoggerUtils;
 import org.onap.policy.drools.persistence.SystemPersistenceConstants;
 import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.drools.utils.logging.LoggerUtil;
 import org.onap.policy.models.pdp.concepts.PdpStateChange;
 import org.onap.policy.models.pdp.concepts.PdpUpdate;
 import org.onap.policy.models.pdp.enums.PdpState;
@@ -49,7 +49,7 @@ public class LifecycleStateTerminatedTest {
     @BeforeClass
     public static void setUp() {
         SystemPersistenceConstants.getManager().setConfigurationDir("src/test/resources");
-        LoggerUtil.setLevel("org.onap.policy.common.endpoints", "WARN");
+        LoggerUtils.setLevel("org.onap.policy.common.endpoints", "WARN");
     }
 
     @AfterClass
index de67c02..65228a9 100644 (file)
@@ -49,6 +49,7 @@ import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
 import org.onap.policy.common.gson.JacksonHandler;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.logging.LoggerUtils;
 import org.onap.policy.common.utils.network.NetworkUtil;
 import org.onap.policy.common.utils.resources.ResourceUtils;
 import org.onap.policy.drools.lifecycle.ControllerSupport;
@@ -56,7 +57,6 @@ import org.onap.policy.drools.lifecycle.LifecycleFeature;
 import org.onap.policy.drools.lifecycle.LifecycleFsm;
 import org.onap.policy.drools.persistence.SystemPersistenceConstants;
 import org.onap.policy.drools.system.PolicyControllerConstants;
-import org.onap.policy.drools.utils.logging.LoggerUtil;
 import org.onap.policy.models.pdp.enums.PdpState;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -105,9 +105,9 @@ public class RestLifecycleManagerTest {
         SystemPersistenceConstants.getManager().setConfigurationDir("target/test-classes");
         fsm = newFsmInstance();
 
-        LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
-        LoggerUtil.setLevel("org.onap.policy.common.endpoints", "WARN");
-        LoggerUtil.setLevel("org.onap.policy.drools", "INFO");
+        LoggerUtils.setLevel(LoggerUtils.ROOT_LOGGER, "INFO");
+        LoggerUtils.setLevel("org.onap.policy.common.endpoints", "WARN");
+        LoggerUtils.setLevel("org.onap.policy.drools", "INFO");
 
         HttpServletServerFactoryInstance.getServerFactory().destroy();
         HttpClientFactoryInstance.getClientFactory().destroy();
index fa60373..6aa7b87 100644 (file)
             <version>${policy.common.version}</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.onap.policy.common</groupId>
+            <artifactId>utils</artifactId>
+            <version>${policy.common.version}</version>
+        </dependency>
+
         <dependency>
             <groupId>org.onap.policy.models</groupId>
             <artifactId>policy-models-pdp</artifactId>
index 4374eb8..dfcfe43 100644 (file)
@@ -65,6 +65,7 @@ import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
 import org.onap.policy.common.endpoints.event.comm.TopicSink;
 import org.onap.policy.common.endpoints.event.comm.TopicSource;
 import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
+import org.onap.policy.common.utils.logging.LoggerUtils;
 import org.onap.policy.drools.controller.DroolsController;
 import org.onap.policy.drools.features.PolicyControllerFeatureApi;
 import org.onap.policy.drools.features.PolicyEngineFeatureApi;
@@ -79,7 +80,6 @@ import org.onap.policy.drools.system.PolicyController;
 import org.onap.policy.drools.system.PolicyControllerConstants;
 import org.onap.policy.drools.system.PolicyEngine;
 import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.drools.utils.logging.LoggerUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -2071,7 +2071,7 @@ public class RestManager {
                                .entity(new Error("logger level: " + NOT_ACCEPTABLE_MSG))
                                .build();
             }
-            newLevel = LoggerUtil.setLevel(loggerName, loggerLevel);
+            newLevel = LoggerUtils.setLevel(loggerName, loggerLevel);
         } catch (final IllegalArgumentException e) {
             logger.warn("{}: invalid operation for logger {} and level {}", this, loggerName, loggerLevel, e);
             return Response.status(Status.NOT_FOUND).build();
index c28d4c9..e92d05d 100644 (file)
@@ -28,6 +28,7 @@ import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
 import org.onap.policy.common.endpoints.http.client.HttpClientConfigException;
 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
 import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
+import org.onap.policy.common.utils.logging.LoggerUtils;
 import org.onap.policy.common.utils.resources.MessageConstants;
 import org.onap.policy.common.utils.security.CryptoUtils;
 import org.onap.policy.drools.persistence.SystemPersistenceConstants;
@@ -142,7 +143,7 @@ public class Main {
             if (!success) {
                 trans.setStatusCode(false).setResponseDescription("partial start").flush();
                 logger.warn(
-                        LoggerUtil.TRANSACTION_LOG_MARKER,
+                        LoggerUtils.TRANSACTION_LOG_MARKER,
                         "Main: {} has been partially started",
                         PolicyEngineConstants.getManager());
                 throw new PolicyDroolsPdpRuntimeException(
@@ -157,7 +158,7 @@ public class Main {
                 .setResponseDescription(e.getMessage())
                 .flush();
             logger.warn(
-                    LoggerUtil.TRANSACTION_LOG_MARKER,
+                    LoggerUtils.TRANSACTION_LOG_MARKER,
                     "Main: cannot start {} (bad state)",
                     PolicyEngineConstants.getManager());
             throw new PolicyDroolsPdpRuntimeException(
@@ -169,7 +170,7 @@ public class Main {
                 .setResponseDescription(e.getMessage())
                 .flush();
             logger.warn(
-                    LoggerUtil.TRANSACTION_LOG_MARKER,
+                    LoggerUtils.TRANSACTION_LOG_MARKER,
                     "Main: cannot start {}",
                     PolicyEngineConstants.getManager());
             throw new PolicyDroolsPdpRuntimeException(
@@ -205,7 +206,7 @@ public class Main {
                     .setResponseDescription(e.getMessage())
                     .flush();
                 logger.error(
-                        LoggerUtil.TRANSACTION_LOG_MARKER,
+                        LoggerUtils.TRANSACTION_LOG_MARKER,
                         "Main: cannot instantiate policy-controller {}",
                         controllerName);
                 throw new PolicyDroolsPdpRuntimeException(
@@ -217,7 +218,7 @@ public class Main {
                     .setResponseDescription(e.getMessage())
                     .flush();
                 logger.warn(
-                        LoggerUtil.TRANSACTION_LOG_MARKER,
+                        LoggerUtils.TRANSACTION_LOG_MARKER,
                         "Main: cannot instantiate policy-controller {} (linkage)",
                         controllerName);
                 throw new PolicyDroolsPdpRuntimeException(
index 664f7c7..d5f7ae0 100644 (file)
@@ -56,6 +56,7 @@ import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInst
 import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
 import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
 import org.onap.policy.common.gson.annotation.GsonJsonProperty;
+import org.onap.policy.common.utils.logging.LoggerUtils;
 import org.onap.policy.common.utils.services.FeatureApiUtils;
 import org.onap.policy.drools.controller.DroolsControllerConstants;
 import org.onap.policy.drools.core.PolicyContainer;
@@ -398,7 +399,7 @@ class PolicyEngineManager implements PolicyEngine {
         } else {
             final String msg = "Configuration Entity is not supported: " + entity;
             mdcTrans.resetSubTransaction().setStatusCode(false).setResponseDescription(msg).flush();
-            logger.warn(LoggerUtil.TRANSACTION_LOG_MARKER, msg);
+            logger.warn(LoggerUtils.TRANSACTION_LOG_MARKER, msg);
             throw new IllegalArgumentException(msg);
         }
     }
@@ -468,7 +469,7 @@ class PolicyEngineManager implements PolicyEngine {
             } catch (final Exception e) {
                 mdcTrans.setStatusCode(false).setResponseCode(e.getClass().getName())
                         .setResponseDescription(e.getMessage()).flush();
-                logger.error(LoggerUtil.TRANSACTION_LOG_MARKER,
+                logger.error(LoggerUtils.TRANSACTION_LOG_MARKER,
                         "{}: cannot update-policy-controllers because of {}", this, e.getMessage(), e);
             }
         }
index db2062f..b71403e 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -51,9 +51,9 @@ import org.kie.api.event.rule.ObjectUpdatedEvent;
 import org.kie.api.event.rule.RuleFlowGroupActivatedEvent;
 import org.kie.api.event.rule.RuleFlowGroupDeactivatedEvent;
 import org.kie.api.event.rule.RuleRuntimeEventListener;
+import org.onap.policy.common.utils.logging.LoggerUtils;
 import org.onap.policy.drools.controller.DroolsController;
 import org.onap.policy.drools.util.KieUtils;
-import org.onap.policy.drools.utils.logging.LoggerUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -105,8 +105,8 @@ public class MavenDroolsControllerUpgradesTest {
                           Paths.get(DROOLS_RESOURCES_DIR + "rules2" + DRL_EXT).toFile())
                       .collect(Collectors.toList()));
 
-        LoggerUtil.setLevel("ROOT", "WARN");
-        LoggerUtil.setLevel("org.onap.policy.drools.controller.internal", "INFO");
+        LoggerUtils.setLevel("ROOT", "WARN");
+        LoggerUtils.setLevel("org.onap.policy.drools.controller.internal", "INFO");
     }
 
     /**
index 5bbcded..fd33700 100644 (file)
             <artifactId>gson</artifactId>
             <version>${policy.common.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.onap.policy.common</groupId>
+            <artifactId>utils</artifactId>
+            <version>${policy.common.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/LoggerMarkerFilter.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/LoggerMarkerFilter.java
deleted file mode 100644 (file)
index 7468b52..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 2017-2018, 2021 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.utils.logging;
-
-import ch.qos.logback.classic.spi.ILoggingEvent;
-import ch.qos.logback.core.filter.AbstractMatcherFilter;
-import ch.qos.logback.core.spi.FilterReply;
-import lombok.AccessLevel;
-import lombok.AllArgsConstructor;
-import org.slf4j.Marker;
-
-/**
- * Logger Marker Filters to be used in logback.xml configuration
- * to accept/deny metric or transaction (audit) events
- */
-@AllArgsConstructor(access = AccessLevel.PROTECTED)
-public abstract class LoggerMarkerFilter extends AbstractMatcherFilter<ILoggingEvent> {
-
-    protected final Marker marker;
-
-    @Override
-    public FilterReply decide(ILoggingEvent event) {
-
-        if (this.marker == null || !isStarted()) {
-            return FilterReply.DENY;
-        }
-
-        if (event == null || event.getMarker() == null) {
-            return FilterReply.DENY;
-        }
-
-        if (event.getMarker().equals(marker)) {
-            return FilterReply.ACCEPT;
-        } else {
-            return FilterReply.DENY;
-        }
-    }
-
-    /**
-     * Metric Logger Marker Filter.
-     */
-    public static class MetricLoggerMarkerFilter extends LoggerMarkerFilter {
-
-        public MetricLoggerMarkerFilter() {
-            super(LoggerUtil.METRIC_LOG_MARKER);
-        }
-
-    }
-
-    /**
-     * Transaction Logger Marker Filter.
-     */
-    public static class TransactionLoggerMarkerFilter extends LoggerMarkerFilter {
-
-        public TransactionLoggerMarkerFilter() {
-            super(LoggerUtil.TRANSACTION_LOG_MARKER);
-        }
-    }
-}
index eef0fa3..9c6dad7 100644 (file)
 
 package org.onap.policy.drools.utils.logging;
 
-import ch.qos.logback.classic.LoggerContext;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.slf4j.Marker;
-import org.slf4j.MarkerFactory;
 
 /**
  * Loger Utils.
@@ -46,58 +43,5 @@ public final class LoggerUtil {
      */
     public static final String LOGBACK_CONFIGURATION_FILE_DEFAULT = "config/logback.xml";
 
-    /**
-     * Root logger.
-     */
-    public static final String ROOT_LOGGER = "ROOT";
-
-    /**
-     * Metric Log Marker Name.
-     */
-    public static final String METRIC_LOG_MARKER_NAME = "metric";
-
-    /**
-     * Transaction Log Marker Name.
-     */
-    public static final String TRANSACTION_LOG_MARKER_NAME = "transaction";
-
-    /**
-     * Marks a logging record as a metric.
-     */
-    public static final Marker METRIC_LOG_MARKER = MarkerFactory.getMarker(METRIC_LOG_MARKER_NAME);
-
-    /**
-     * Marks a logging record as an end-to-end transaction.
-     */
-    public static final Marker TRANSACTION_LOG_MARKER = MarkerFactory.getMarker(TRANSACTION_LOG_MARKER_NAME);
-
-    /**
-     * Set the log level of a logger.
-     *
-     * @param loggerName logger name
-     * @param loggerLevel logger level
-     */
-    public static String setLevel(String loggerName, String loggerLevel) {
-        if (!(LoggerFactory.getILoggerFactory() instanceof LoggerContext)) {
-            throw new IllegalStateException("The SLF4J logger factory is not configured for logback");
-        }
-
-        final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
-        final var logger = context.getLogger(loggerName);
-        if (logger == null) {
-            throw new IllegalArgumentException("no logger " + loggerName);
-        }
-
-        LOGGER.warn("setting {} logger to level {}", loggerName, loggerLevel);
-
-        // use the current log level if the string provided cannot be converted to a valid Level.
-
-        // NOSONAR: this method is currently used by the telemetry api (which should be authenticated).
-        // It is no more or no less dangerous than an admin changing the logback level on the fly.
-        // This is a controlled admin function that should not cause any risks when the system
-        // is configured properly.
-        logger.setLevel(ch.qos.logback.classic.Level.toLevel(loggerLevel, logger.getLevel()));  // NOSONAR
-
-        return logger.getLevel().toString();
-    }
 }
+
index 583360b..819e5e3 100644 (file)
@@ -54,6 +54,7 @@ import java.time.Instant;
 import lombok.Getter;
 import lombok.ToString;
 import org.apache.commons.lang3.StringUtils;
+import org.onap.policy.common.utils.logging.LoggerUtils;
 import org.onap.policy.drools.metrics.Metric;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -234,14 +235,14 @@ class MdcTransactionImpl implements MdcTransaction {
     @Override
     public MdcTransaction metric() {
         flush();
-        logger.info(LoggerUtil.METRIC_LOG_MARKER, "");
+        logger.info(LoggerUtils.METRIC_LOG_MARKER, "");
         return this;
     }
 
     @Override
     public MdcTransaction transaction() {
         flush();
-        logger.info(LoggerUtil.TRANSACTION_LOG_MARKER, "");
+        logger.info(LoggerUtils.TRANSACTION_LOG_MARKER, "");
         return this;
     }
 
index 4b4b9d6..c19adea 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -34,8 +34,8 @@ import org.apache.commons.lang3.StringUtils;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.onap.policy.common.utils.logging.LoggerUtils;
 import org.onap.policy.common.utils.security.CryptoUtils;
-import org.onap.policy.drools.utils.logging.LoggerUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -244,7 +244,7 @@ public class PropertyUtilTest {
         assertEquals(System.getenv("HOME"), props.getProperty(INTERPOLATION_ENVD));
         assertEquals(StringUtils.EMPTY, props.getProperty(INTERPOLATION_ENVD_NONE));
         assertEquals(StringUtils.EMPTY, props.getProperty(INTERPOLATION_ENVD_NO_DEFAULT));
-        assertEquals(LoggerUtil.ROOT_LOGGER, props.getProperty(INTERPOLATION_CONST));
+        assertEquals(LoggerUtils.ROOT_LOGGER, props.getProperty(INTERPOLATION_CONST));
         assertEquals(System.getProperty("user.home"), props.getProperty(INTERPOLATION_SYS));
         assertEquals(INTERPOLATION_ENVD_DEFAULT_VALUE, props.getProperty(INTERPOLATION_ENVD_DEFAULT));
     }
index be1a8a9..195a7ad 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * policy-utils
  * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
+import org.onap.policy.common.utils.logging.LoggerUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,20 +38,20 @@ public class LoggerUtilTest {
         assertTrue(logger.isInfoEnabled());
 
         logger.info("line 1");
-        logger.info(LoggerUtil.METRIC_LOG_MARKER, "line 1 Metric");
-        logger.info(LoggerUtil.TRANSACTION_LOG_MARKER, "line 1 Transaction");
+        logger.info(LoggerUtils.METRIC_LOG_MARKER, "line 1 Metric");
+        logger.info(LoggerUtils.TRANSACTION_LOG_MARKER, "line 1 Transaction");
 
-        LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "warn");
+        LoggerUtils.setLevel(LoggerUtils.ROOT_LOGGER, "warn");
         logger.info("line 2");
-        logger.info(LoggerUtil.METRIC_LOG_MARKER, "line 2 Metric");
-        logger.info(LoggerUtil.TRANSACTION_LOG_MARKER, "line 2 Transaction");
+        logger.info(LoggerUtils.METRIC_LOG_MARKER, "line 2 Metric");
+        logger.info(LoggerUtils.TRANSACTION_LOG_MARKER, "line 2 Transaction");
 
         assertFalse(logger.isInfoEnabled());
 
-        LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "debug");
+        LoggerUtils.setLevel(LoggerUtils.ROOT_LOGGER, "debug");
         logger.debug("line 3");
-        logger.debug(LoggerUtil.METRIC_LOG_MARKER, "line 3 Metric");
-        logger.debug(LoggerUtil.TRANSACTION_LOG_MARKER, "line 3 Transaction");
+        logger.debug(LoggerUtils.METRIC_LOG_MARKER, "line 3 Metric");
+        logger.debug(LoggerUtils.TRANSACTION_LOG_MARKER, "line 3 Transaction");
 
         assertTrue(logger.isDebugEnabled());
     }
index 78ec546..aeb88a9 100644 (file)
@@ -2,7 +2,7 @@
 # ============LICENSE_START=======================================================
 # ONAP
 # ================================================================================
-# Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
 # ================================================================================
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@
 
 interpolation.no=no
 interpolation.env=${env:HOME}
-interpolation.const=${const:org.onap.policy.drools.utils.logging.LoggerUtil.ROOT_LOGGER}
+interpolation.const=${const:org.onap.policy.common.utils.logging.LoggerUtils.ROOT_LOGGER}
 interpolation.sys=${sys:user.home}
 interpolation.envd=${envd:HOME}
 interpolation.envd.default=${envd:BLAH:default}