summaryrefslogtreecommitdiffstats
path: root/policy-utils/src/main
diff options
context:
space:
mode:
authorTaka Cho <takamune.cho@att.com>2021-08-03 13:28:28 -0400
committerTaka Cho <takamune.cho@att.com>2021-08-06 13:13:13 -0400
commitaabb9e500132bbcd639bc4b8bda34e8fde3a3676 (patch)
tree15d2d58f918ca30f0160c550fd1d2814d04d5816 /policy-utils/src/main
parent1744dac574fb771301027be74c9257eb070125f7 (diff)
Use slf4j Marker from common repo
using slf4j Marker from common repo Issue-ID: POLICY-3087 Change-Id: Iefbd6fa9ab2dfa6388508cb6ffd6cf1358b45ccc Signed-off-by: Taka Cho <takamune.cho@att.com>
Diffstat (limited to 'policy-utils/src/main')
-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
3 files changed, 4 insertions, 136 deletions
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;
}