From 455999fe660897fefd8d4f84a47ab5caca6c247a Mon Sep 17 00:00:00 2001 From: "Smokowski, Kevin (ks6305)" Date: Fri, 18 Oct 2019 18:23:10 +0000 Subject: enhance AbstractMetricLogFilter make metric filters easily extendable Issue-ID: LOG-1171 Signed-off-by: Smokowski, Kevin (ks6305) Change-Id: Ibd3f96cc8abbfa4728605f9f4c4d2472475b2dba --- .../org/onap/logging/filter/base/AbstractMetricLogFilter.java | 10 ++++++++++ .../logging-filter-base/src/test/resources/log4j2.properties | 2 ++ 2 files changed, 12 insertions(+) (limited to 'reference') diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java index 79649a2..23d83fb 100644 --- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java +++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java @@ -56,12 +56,17 @@ public abstract class AbstractMetricLogFilter try { setupMDC(request); setupHeaders(request, requestHeaders); + additionalPre(request, requestHeaders); logger.info(ONAPLogConstants.Markers.INVOKE, "Invoke"); } catch (Exception e) { logger.warn("Error in AbstractMetricLogFilter pre", e); } } + protected void additionalPre(Request request, RequestHeaders requestHeaders) { + // override to add application specific logic + } + protected void setupHeaders(Request clientRequest, RequestHeaders requestHeaders) { String requestId = extractRequestID(); addHeader(requestHeaders, ONAPLogConstants.Headers.REQUEST_ID, requestId); @@ -114,6 +119,7 @@ public abstract class AbstractMetricLogFilter setResponseStatusCode(getHttpStatusCode(response)); setResponseDescription(getHttpStatusCode(response)); MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, getResponseCode(response)); + additionalPost(request, response); logger.info(INVOKE_RETURN, "InvokeReturn"); clearClientMDCs(); } catch (Exception e) { @@ -121,6 +127,10 @@ public abstract class AbstractMetricLogFilter } } + protected void additionalPost(Request request, Response response) { + // override to add application specific logic + } + protected String getPartnerName() { return getProperty(Constants.Property.PARTNER_NAME); } diff --git a/reference/logging-filter/logging-filter-base/src/test/resources/log4j2.properties b/reference/logging-filter/logging-filter-base/src/test/resources/log4j2.properties index 856bb26..04446cd 100644 --- a/reference/logging-filter/logging-filter-base/src/test/resources/log4j2.properties +++ b/reference/logging-filter/logging-filter-base/src/test/resources/log4j2.properties @@ -1,6 +1,8 @@ appenders = console appender.console.type = Console appender.console.name = STDOUT +appender.console.layout.type = PatternLayout +appender.console.layout.pattern = %X|%m%n rootLogger.level = TRACE rootLogger.appenderRefs = stdout -- cgit 1.2.3-korg