diff options
Diffstat (limited to 'aai-els-onap-logging/src/main/java/org/onap/logging/ref')
3 files changed, 105 insertions, 66 deletions
diff --git a/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/ONAPLogAdapter.java b/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/ONAPLogAdapter.java index aafc74d4..4670f500 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/ONAPLogAdapter.java +++ b/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/ONAPLogAdapter.java @@ -37,48 +37,56 @@ import org.slf4j.event.Level; * Extensible adapter for cheaply meeting ONAP logging obligations using * an SLF4J facade. * - * <p>This can be used with any SLF4J-compatible logging provider, with - * appropriate provider configuration.</p> + * <p> + * This can be used with any SLF4J-compatible logging provider, with + * appropriate provider configuration. + * </p> * - * <p>The basics are that: + * <p> + * The basics are that: * <ul> - * <li>{@link #entering} sets all MDCs.</li> - * <li>{@link #exiting} unsets all MDCs *and* logs response information.</li> - * <li>{@link #invoke} logs and returns a UUID to passed during invocation, - * and optionally sets these for you on your downstream request by way of - * an adapter.</li> - * <li>Call {@link #getServiceDescriptor()} and its setters to set service-related MDCs.</li> - * <li>Call {@link #getResponseDescriptor()} and its setters to set response-related MDCs.</li> + * <li>{@link #entering} sets all MDCs.</li> + * <li>{@link #exiting} unsets all MDCs *and* logs response information.</li> + * <li>{@link #invoke} logs and returns a UUID to passed during invocation, + * and optionally sets these for you on your downstream request by way of + * an adapter.</li> + * <li>Call {@link #getServiceDescriptor()} and its setters to set service-related MDCs.</li> + * <li>Call {@link #getResponseDescriptor()} and its setters to set response-related MDCs.</li> * </ul> * </p> * - * <p>Minimal usage is: + * <p> + * Minimal usage is: * <ol> - * <li>#entering(RequestAdapter)</li> - * <li>#invoke, #invoke, ...</li> - * <li>#getResponse + setters (or #setResponse)</li> - * <li>#exiting</li> + * <li>#entering(RequestAdapter)</li> + * <li>#invoke, #invoke, ...</li> + * <li>#getResponse + setters (or #setResponse)</li> + * <li>#exiting</li> * </ol> * </p> * - * <p> ... if you're happy for service information to be automatically derived as follows: + * <p> + * ... if you're happy for service information to be automatically derived as follows: * <ul> - * <li><tt>ServiceName</tt> - from <tt>HttpServletRequest#getRequestURI()</tt></li> - * <li><tt>InstanceUUID</tt> - classloader-scope UUID.</li> + * <li><tt>ServiceName</tt> - from <tt>HttpServletRequest#getRequestURI()</tt></li> + * <li><tt>InstanceUUID</tt> - classloader-scope UUID.</li> * </ul> * </p> * - * <p>... and if those defaults don't suit, then you can override using properties on + * <p> + * ... and if those defaults don't suit, then you can override using properties on * {@link #getServiceDescriptor()}, or by injecting your own adapter using * {@link #setServiceDescriptor(ServiceDescriptor)}, or by overriding - * a <tt>protected</tt> methods like{@link #setEnteringMDCs}.</p> + * a <tt>protected</tt> methods like{@link #setEnteringMDCs}. + * </p> * - * <p>For everything else: + * <p> + * For everything else: * <ul> - * <li>The underlying SLF4J {@link Logger} can be retrieved using {@link #unwrap}. - * Use this or create your own using the usual SLF4J factor.</li> - * <li>Set whatever MDCs you like.</li> - * <li>Log whatever else you like.</li> + * <li>The underlying SLF4J {@link Logger} can be retrieved using {@link #unwrap}. + * Use this or create your own using the usual SLF4J factor.</li> + * <li>Set whatever MDCs you like.</li> + * <li>Log whatever else you like.</li> * </ul> * </p> */ @@ -178,8 +186,7 @@ public class ONAPLogAdapter { try { this.mResponseDescriptor.setMDCs(); this.mLogger.info(ONAPLogConstants.Markers.EXIT, EMPTY_MESSAGE); - } - finally { + } finally { MDC.clear(); } return this; @@ -188,8 +195,10 @@ public class ONAPLogAdapter { /** * Report pending invocation with <tt>INVOKE</tt> marker. * - * <p>If you call this variant, then YOU are assuming responsibility for - * setting the requisite ONAP headers.</p> + * <p> + * If you call this variant, then YOU are assuming responsibility for + * setting the requisite ONAP headers. + * </p> * * @param sync whether synchronous. * @return invocation ID to be passed with invocation. @@ -218,8 +227,7 @@ public class ONAPLogAdapter { * @param sync whether synchronous, nullable. * @return invocation ID to be passed with invocation. */ - public UUID invoke(final RequestBuilder builder, - final ONAPLogConstants.InvocationMode sync) { + public UUID invoke(final RequestBuilder builder, final ONAPLogConstants.InvocationMode sync) { // Sync can be defaulted. Builder cannot. @@ -233,8 +241,7 @@ public class ONAPLogAdapter { builder.setHeader(ONAPLogConstants.Headers.REQUEST_ID, defaultToEmpty(MDC.get(ONAPLogConstants.MDCs.REQUEST_ID))); - builder.setHeader(ONAPLogConstants.Headers.INVOCATION_ID, - defaultToEmpty(invocationID)); + builder.setHeader(ONAPLogConstants.Headers.INVOCATION_ID, defaultToEmpty(invocationID)); builder.setHeader(ONAPLogConstants.Headers.PARTNER_NAME, defaultToEmpty(MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME))); @@ -245,15 +252,16 @@ public class ONAPLogAdapter { * Report vanilla <tt>INVOKE</tt> marker. * * @param builder builder for downstream requests, if you want the - * standard ONAP headers to be added automatically. + * standard ONAP headers to be added automatically. * @return invocation ID to be passed with invocation. */ public UUID invoke(final RequestBuilder builder) { - return this.invoke(builder, (ONAPLogConstants.InvocationMode)null); + return this.invoke(builder, (ONAPLogConstants.InvocationMode) null); } /** * Get descriptor, for overriding service details. + * * @return non-null descriptor. */ public ServiceDescriptor getServiceDescriptor() { @@ -262,6 +270,7 @@ public class ONAPLogAdapter { /** * Override {@link ServiceDescriptor}. + * * @param d non-null override. * @return this. */ @@ -272,6 +281,7 @@ public class ONAPLogAdapter { /** * Get descriptor, for setting response details. + * * @return non-null descriptor. */ public ResponseDescriptor getResponseDescriptor() { @@ -280,6 +290,7 @@ public class ONAPLogAdapter { /** * Override {@link ResponseDescriptor}. + * * @param d non-null override. * @return this. */ @@ -297,9 +308,11 @@ public class ONAPLogAdapter { /** * Set MDCs that persist for the duration of an invocation. * - * <p>It would be better to roll this into {@link #entering}, like + * <p> + * It would be better to roll this into {@link #entering}, like * with {@link #exiting}. Then it would be easier to do, but it - * would mean more work. </p> + * would mean more work. + * </p> * * @param request incoming HTTP request. * @return this. @@ -318,8 +331,7 @@ public class ONAPLogAdapter { // ServiceDescriptor to add them. MDC.put(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP, - ZonedDateTime.now(ZoneOffset.UTC) - .format(DateTimeFormatter.ISO_INSTANT)); + ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT)); MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestID); MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationID); MDC.put(ONAPLogConstants.MDCs.PARTNER_NAME, partnerName); @@ -333,8 +345,8 @@ public class ONAPLogAdapter { // Default the service name to the requestURI, in the event that // no value has been provided. - if (MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME) == null || - MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME).equalsIgnoreCase(EMPTY_MESSAGE)) { + if (MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME) == null + || MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME).equalsIgnoreCase(EMPTY_MESSAGE)) { MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, request.getRequestURI()); } @@ -390,7 +402,9 @@ public class ONAPLogAdapter { /** * Extensible descriptor for reporting service details. * - * <p>In most cases extension isn't required. </p> + * <p> + * In most cases extension isn't required. + * </p> */ public static class ServiceDescriptor { @@ -402,6 +416,7 @@ public class ONAPLogAdapter { /** * Set name. + * * @param name <tt>ServiceName</tt>. * @return this. */ @@ -412,6 +427,7 @@ public class ONAPLogAdapter { /** * Set name. + * * @param uuid <tt>InstanceUUID</tt>. * @return this. */ @@ -507,11 +523,15 @@ public class ONAPLogAdapter { /** * Adapter for reading information from an incoming HTTP request. * - * <p>Incoming is generally easy, because in most cases you'll be able to - * get your hands on the <tt>HttpServletRequest</tt>.</p> + * <p> + * Incoming is generally easy, because in most cases you'll be able to + * get your hands on the <tt>HttpServletRequest</tt>. + * </p> * - * <p>Perhaps should be generalized to refer to constants instead of - * requiring the implementation of specific methods.</p> + * <p> + * Perhaps should be generalized to refer to constants instead of + * requiring the implementation of specific methods. + * </p> * * @param <T> type, for chaining. */ @@ -519,6 +539,7 @@ public class ONAPLogAdapter { /** * Get header by name. + * * @param name header name. * @return header value, or null. */ @@ -526,18 +547,21 @@ public class ONAPLogAdapter { /** * Get client address. + * * @return address, if available. */ String getClientAddress(); /** * Get server address. + * * @return address, if available. */ String getServerAddress(); /** * Get default service name, from service URI. + * * @return service name default. */ String getRequestURI(); @@ -554,6 +578,7 @@ public class ONAPLogAdapter { /** * Construct adapter for HTTP request. + * * @param request to be wrapped; */ public HttpServletRequestAdapter(final HttpServletRequest request) { @@ -598,8 +623,10 @@ public class ONAPLogAdapter { * vary a lot from caller to caller, since they each get to choose their * own REST (or HTTP, or whatever) client APIs. * - * <p>No default implementation, because there's no HTTP client that's - * sufficiently ubiquitous to warrant incurring a mandatory dependency.</p> + * <p> + * No default implementation, because there's no HTTP client that's + * sufficiently ubiquitous to warrant incurring a mandatory dependency. + * </p> * * @param <T> type, for chaining. */ @@ -607,6 +634,7 @@ public class ONAPLogAdapter { /** * Set HTTP header. + * * @param name header name. * @param value header value. * @return this. diff --git a/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/ONAPLogConstants.java b/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/ONAPLogConstants.java index 77ca084d..027a99db 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/ONAPLogConstants.java +++ b/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/ONAPLogConstants.java @@ -27,7 +27,9 @@ import org.slf4j.MarkerFactory; /** * Constants for standard ONAP headers, MDCs, etc. * - * <p>See <tt>package-info.java</tt>.</p> + * <p> + * See <tt>package-info.java</tt>. + * </p> */ public final class ONAPLogConstants { @@ -57,7 +59,7 @@ public final class ONAPLogConstants { /** Marker reporting invocation. */ public static final Marker INVOKE = MarkerFactory.getMarker("INVOKE"); - + /** Marker reporting invocation return. */ public static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE_RETURN"); @@ -75,6 +77,7 @@ public final class ONAPLogConstants { /** * Build nested, detached marker. + * * @param m1 top token. * @param m2 sub-token. * @return detached Marker. @@ -114,7 +117,7 @@ public final class ONAPLogConstants { /** MDC recording target service. */ public static final String TARGET_SERVICE_NAME = "TargetServiceName"; - + /** MDC recording target entity. */ public static final String TARGET_ENTITY = "TargetEntity"; @@ -124,7 +127,7 @@ public final class ONAPLogConstants { /** MDC recording current service instance id. */ public static final String SERVICE_INSTANCE_ID = "ServiceInstanceID"; - /** MDC recording current instance id. */ + /** MDC recording current instance id. */ public static final String INSTANCE_UUID = "InstanceID"; // Network. //////////////////////////////////////////////////////////// @@ -148,14 +151,21 @@ public final class ONAPLogConstants { * MDC recording timestamp at the start of the current request, * with the same scope as {@link #REQUEST_ID}. * - * <p>Open issues: + * <p> + * Open issues: + * <ul> * <ul> - * <ul>Easily confused with {@link #INVOKE_TIMESTAMP}.</ul> - * <ul>No mechanism for propagation between components, e.g. via HTTP headers.</ul> - * <ul>Whatever mechanism we define, it's going to be costly.</ul> + * Easily confused with {@link #INVOKE_TIMESTAMP}. + * </ul> + * <ul> + * No mechanism for propagation between components, e.g. via HTTP headers. + * </ul> + * <ul> + * Whatever mechanism we define, it's going to be costly. + * </ul> * </ul> * </p> - * */ + */ public static final String ENTRY_TIMESTAMP = "EntryTimestamp"; /** MDC recording timestamp at the start of the current invocation. */ @@ -164,7 +174,7 @@ public final class ONAPLogConstants { /** MDC recording elapsed time. */ public static final String ELAPSED_TIME = "ElapsedTime"; - /** MDC recording log timestamp. */ + /** MDC recording log timestamp. */ public static final String LOG_TIMESTAMP = "LogTimestamp"; // Outcomes. /////////////////////////////////////////////////////////// @@ -182,8 +192,8 @@ public final class ONAPLogConstants { public static final String RESPONSE_STATUS_CODE = "StatusCode"; /** MDC recording error code. */ - public static final String ERROR_CODE = "ErrorCode"; - + public static final String ERROR_CODE = "ErrorCode"; + /** MDC recording error description. */ public static final String ERROR_DESC = "ErrorDesc"; @@ -235,7 +245,7 @@ public final class ONAPLogConstants { /** Not. */ ERROR, - + /** In Progress. */ INPROGRESS } diff --git a/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/package-info.java b/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/package-info.java index d9a62472..561cc94b 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/package-info.java +++ b/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/package-info.java @@ -9,7 +9,7 @@ * 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 + * 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, @@ -22,11 +22,12 @@ package org.onap.logging.ref.slf4j; /** - * <p>Code in here has potential application outside this reference + * <p> + * Code in here has potential application outside this reference * example, and accordingly: * <ul> - * <li>Packaged in <tt>common</tt>.</li> - * <li>Has minimal dependencies.</li> + * <li>Packaged in <tt>common</tt>.</li> + * <li>Has minimal dependencies.</li> * </ul> * </p> - */
\ No newline at end of file + */ |