aboutsummaryrefslogtreecommitdiffstats
path: root/policy-utils
diff options
context:
space:
mode:
Diffstat (limited to 'policy-utils')
-rw-r--r--policy-utils/pom.xml5
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/utils/logging/LoggerMarkerFilter.java77
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/utils/logging/LoggerUtil.java58
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/utils/logging/MdcTransactionImpl.java5
-rw-r--r--policy-utils/src/test/java/org/onap/policy/drools/utils/PropertyUtilTest.java6
-rw-r--r--policy-utils/src/test/java/org/onap/policy/drools/utils/logging/LoggerUtilTest.java19
-rw-r--r--policy-utils/src/test/resources/interpolation.properties4
7 files changed, 24 insertions, 150 deletions
diff --git a/policy-utils/pom.xml b/policy-utils/pom.xml
index 5bbcded9..fd337002 100644
--- a/policy-utils/pom.xml
+++ b/policy-utils/pom.xml
@@ -67,6 +67,11 @@
<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>
<scope>provided</scope>
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
index 7468b523..00000000
--- a/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/LoggerMarkerFilter.java
+++ /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);
- }
- }
-}
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/LoggerUtil.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/LoggerUtil.java
index eef0fa3d..9c6dad79 100644
--- a/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/LoggerUtil.java
+++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/LoggerUtil.java
@@ -20,13 +20,10 @@
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();
- }
}
+
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/MdcTransactionImpl.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/MdcTransactionImpl.java
index 583360b3..819e5e32 100644
--- a/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/MdcTransactionImpl.java
+++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/MdcTransactionImpl.java
@@ -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;
}
diff --git a/policy-utils/src/test/java/org/onap/policy/drools/utils/PropertyUtilTest.java b/policy-utils/src/test/java/org/onap/policy/drools/utils/PropertyUtilTest.java
index 4b4b9d64..c19adea4 100644
--- a/policy-utils/src/test/java/org/onap/policy/drools/utils/PropertyUtilTest.java
+++ b/policy-utils/src/test/java/org/onap/policy/drools/utils/PropertyUtilTest.java
@@ -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));
}
diff --git a/policy-utils/src/test/java/org/onap/policy/drools/utils/logging/LoggerUtilTest.java b/policy-utils/src/test/java/org/onap/policy/drools/utils/logging/LoggerUtilTest.java
index be1a8a97..195a7add 100644
--- a/policy-utils/src/test/java/org/onap/policy/drools/utils/logging/LoggerUtilTest.java
+++ b/policy-utils/src/test/java/org/onap/policy/drools/utils/logging/LoggerUtilTest.java
@@ -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());
}
diff --git a/policy-utils/src/test/resources/interpolation.properties b/policy-utils/src/test/resources/interpolation.properties
index 78ec546b..aeb88a9b 100644
--- a/policy-utils/src/test/resources/interpolation.properties
+++ b/policy-utils/src/test/resources/interpolation.properties
@@ -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}