diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api')
8 files changed, 65 insertions, 95 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/AuditData.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/AuditData.java index 090f680aa7..8bf8852354 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/AuditData.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/AuditData.java @@ -13,15 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.api; -import org.onap.logging.ref.slf4j.ONAPLogConstants.ResponseStatus; import lombok.Getter; +import org.onap.logging.ref.slf4j.ONAPLogConstants.ResponseStatus; /** - * Builder to populate <i>audit</i> data. This includes only data known to an application, and not otherwise available - * to the logging framework. As opposed, for example, to local runtime, host address, etc. + * Builder to populate <i>audit</i> data. This includes only data known to an application, and not otherwise available to the logging framework. As + * opposed, for example, to local runtime, host address, etc. * * @author KATYR, evitaliy * @since February 15, 2018 @@ -30,7 +29,6 @@ import lombok.Getter; public class AuditData { // don't inherit from MetricsData because it has a very different meaning - private final long startTime; private final long endTime; private final ResponseStatus statusCode; @@ -47,17 +45,16 @@ public class AuditData { this.clientIpAddress = builder.clientIpAddress; } - @Override - public String toString() { - return "AuditData{startTime=" + startTime + ", endTime=" + endTime + ", statusCode=" + statusCode - + ", responseCode=" + responseCode + ", responseDescription=" + responseDescription - + ", clientIpAddress=" + clientIpAddress + '}'; - } - public static AuditDataBuilder builder() { return new AuditDataBuilder(); } + @Override + public String toString() { + return "AuditData{startTime=" + startTime + ", endTime=" + endTime + ", statusCode=" + statusCode + ", responseCode=" + responseCode + + ", responseDescription=" + responseDescription + ", clientIpAddress=" + clientIpAddress + '}'; + } + /** * Fluent API for building audit data. */ @@ -95,8 +92,8 @@ public class AuditData { } /** - * Indicate whether an invocation was successful. It is up the the application to decide if a particular result - * must be treated as a success or a failure. + * Indicate whether an invocation was successful. It is up the the application to decide if a particular result must be treated as a success + * or a failure. * * @param statusCode invocation status success/failure * @return this builder for fluent API @@ -118,8 +115,8 @@ public class AuditData { } /** - * Response description that explains {@link #responseCode(String)} in a human-friendly way. For a Web API, it - * is likely to be a standard HTTP response phrase. + * Response description that explains {@link #responseCode(String)} in a human-friendly way. For a Web API, it is likely to be a standard HTTP + * response phrase. * * @param responseDescription human-friendly response description * @return this builder for fluent API diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ContextData.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ContextData.java index 6eb747f9d9..ba556caac3 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ContextData.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ContextData.java @@ -13,15 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.api; import java.util.Objects; /** - * Builder to populate logging <i>context</i> data, i.e. data that should be available to any log writing event - * throughout an application. This includes only data known at some point to the application (e.g. at an API call), - * and not otherwise available to the logging framework (e.g. information about local runtime, machine, etc.). + * Builder to populate logging <i>context</i> data, i.e. data that should be available to any log writing event throughout an application. This + * includes only data known at some point to the application (e.g. at an API call), and not otherwise available to the logging framework (e.g. + * information about local runtime, machine, etc.). * * @author evitaliy * @since Mar 22, 2018 @@ -38,6 +37,10 @@ public class ContextData { this.partnerName = builder.partnerName; } + public static ContextDataBuilder builder() { + return new ContextDataBuilder(); + } + /** * Uniques request ID received from a calling peer, or created. * @@ -67,18 +70,15 @@ public class ContextData { @Override public boolean equals(Object o) { - if (this == o) { return true; } - if (o == null || getClass() != o.getClass()) { return false; } - ContextData that = (ContextData) o; - return Objects.equals(requestId, that.requestId) && Objects.equals(serviceName, that.serviceName) - && Objects.equals(partnerName, that.partnerName); + return Objects.equals(requestId, that.requestId) && Objects.equals(serviceName, that.serviceName) && Objects + .equals(partnerName, that.partnerName); } @Override @@ -88,12 +88,7 @@ public class ContextData { @Override public String toString() { - return "ContextData{responseCode=" + requestId + ", responseDescription=" + serviceName - + ", clientIpAddress=" + partnerName + '}'; - } - - public static ContextDataBuilder builder() { - return new ContextDataBuilder(); + return "ContextData{responseCode=" + requestId + ", responseDescription=" + serviceName + ", clientIpAddress=" + partnerName + '}'; } /** diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java index 6fbd25a134..9d670e8dcb 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java @@ -4,16 +4,15 @@ * 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. */ - package org.openecomp.sdc.logging.api; /** diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java index 6ef57761d8..b772f5682c 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.api; import java.util.Objects; @@ -22,22 +21,19 @@ import org.openecomp.sdc.logging.spi.LoggerCreationService; /** * <a>Factory to hide a concrete, framework-specific implementation of logger creation.</a> * <p>The service used by this factory must implement {@link LoggerCreationService}. If no - * implementation has been configured or could be instantiated, a <b>no-op logger</b> will be - * used, and <b>no events</b> will be logged. This is done to prevent recursion if attempts are - * being made to log exceptions that resulted from logger initialization. </p> + * implementation has been configured or could be instantiated, a <b>no-op logger</b> will be used, and <b>no events</b> will be logged. This is done + * to prevent recursion if attempts are being made to log exceptions that resulted from logger initialization. </p> * * @author evitaliy - * @since 13/09/2016. - * * @see ServiceBinder * @see LoggerCreationService + * @since 13/09/2016. */ public class LoggerFactory { - // use the no-op service to prevent recursion in case of an attempt to log an exception as a + // result of a logger initialization error - private static final LoggerCreationService SERVICE = ServiceBinder.getCreationServiceBinding().orElseGet( - NoOpLoggerCreationService::new); + private static final LoggerCreationService SERVICE = ServiceBinder.getCreationServiceBinding().orElseGet(NoOpLoggerCreationService::new); private LoggerFactory() { // prevent instantiation @@ -53,6 +49,18 @@ public class LoggerFactory { private static class NoOpLoggerCreationService implements LoggerCreationService { + @Override + public Logger getLogger(String className) { + Objects.requireNonNull(className, "Name cannot be null"); + return NoOpLogger.INSTANCE; + } + + @Override + public Logger getLogger(Class<?> clazz) { + Objects.requireNonNull(clazz, "Class cannot be null"); + return NoOpLogger.INSTANCE; + } + private static class NoOpLogger implements Logger { private static final Logger INSTANCE = new NoOpLogger(); @@ -212,18 +220,5 @@ public class LoggerFactory { // no-op } } - - @Override - public Logger getLogger(String className) { - Objects.requireNonNull(className, "Name cannot be null"); - return NoOpLogger.INSTANCE; - } - - @Override - public Logger getLogger(Class<?> clazz) { - Objects.requireNonNull(clazz, "Class cannot be null"); - return NoOpLogger.INSTANCE; - } } } - diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggingContext.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggingContext.java index 894dd2c00c..29e3f33fa0 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggingContext.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggingContext.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.api; import java.util.Objects; @@ -24,9 +23,8 @@ import org.openecomp.sdc.logging.spi.LoggingContextService; * <p>Factory to hide a concrete, framework-specific implementation of diagnostic context.</p> * * <p>The service used by this factory must implement {@link LoggingContextService}. If no implementation has been - * configured or could be instantiated, a <b>no-op context service</b> will be used, and <b>no context</b> will be - * stored or propagated. No errors will be generated, so that the application can still work (albeit without proper - * logging).</p> + * configured or could be instantiated, a <b>no-op context service</b> will be used, and <b>no context</b> will be stored or propagated. No errors + * will be generated, so that the application can still work (albeit without proper logging).</p> * * @author evitaliy * @see ServiceBinder @@ -35,8 +33,7 @@ import org.openecomp.sdc.logging.spi.LoggingContextService; */ public class LoggingContext { - private static final LoggingContextService SERVICE = - ServiceBinder.getContextServiceBinding().orElseGet(NoOpLoggingContextService::new); + private static final LoggingContextService SERVICE = ServiceBinder.getContextServiceBinding().orElseGet(NoOpLoggingContextService::new); private LoggingContext() { // prevent instantiation diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/MetricsData.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/MetricsData.java index 2fef96d2bb..e85c22cb67 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/MetricsData.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/MetricsData.java @@ -13,15 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.api; -import org.onap.logging.ref.slf4j.ONAPLogConstants.ResponseStatus; import lombok.Getter; +import org.onap.logging.ref.slf4j.ONAPLogConstants.ResponseStatus; /** - * Builder to populate <i>metrics</i> data. This includes only data known to an application, and not otherwise available - * to the logging framework. + * Builder to populate <i>metrics</i> data. This includes only data known to an application, and not otherwise available to the logging framework. * * @author evitaliy * @since 26 Mar 2018 @@ -30,7 +28,6 @@ import lombok.Getter; public class MetricsData { // don't inherit from AuditData because it has a very different meaning - private final long startTime; private final long endTime; private final ResponseStatus statusCode; @@ -51,17 +48,16 @@ public class MetricsData { this.targetVirtualEntity = builder.targetVirtualEntity; } - @Override - public String toString() { - return "AuditData{startTime=" + startTime + ", endTime=" + endTime + ", statusCode=" + statusCode - + ", responseCode=" + responseCode + ", responseDescription=" + responseDescription - + ", clientIpAddress=" + clientIpAddress + '}'; - } - public static MetricsDataBuilder builder() { return new MetricsDataBuilder(); } + @Override + public String toString() { + return "AuditData{startTime=" + startTime + ", endTime=" + endTime + ", statusCode=" + statusCode + ", responseCode=" + responseCode + + ", responseDescription=" + responseDescription + ", clientIpAddress=" + clientIpAddress + '}'; + } + /** * Fluent API for building metrics data. */ @@ -101,8 +97,8 @@ public class MetricsData { } /** - * Indicate whether an invocation was successful. It is up the the application to decide if a particular result - * must be treated as a success or a failure. + * Indicate whether an invocation was successful. It is up the the application to decide if a particular result must be treated as a success + * or a failure. * * @param statusCode invocation status success/failure * @return this builder for fluent API @@ -124,8 +120,8 @@ public class MetricsData { } /** - * Response description that explains {@link #responseCode(String)} in a human-friendly way. For a Web API, it - * is likely to be a standard HTTP response phrase. + * Response description that explains {@link #responseCode(String)} in a human-friendly way. For a Web API, it is likely to be a standard HTTP + * response phrase. * * @param responseDescription human-friendly response description * @return this builder for fluent API diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ServiceBinder.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ServiceBinder.java index 6e5b3e3501..65d624aa86 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ServiceBinder.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ServiceBinder.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.api; import java.util.Iterator; @@ -35,6 +34,7 @@ import org.openecomp.sdc.logging.spi.LoggingServiceProvider; */ // No advanced logging can be used here because we don't know + // which underlying implementation will be used @SuppressWarnings({"UseOfSystemOutOrSystemErr", "squid:S106", "squid:S1166"}) class ServiceBinder { @@ -46,31 +46,23 @@ class ServiceBinder { } private static LoggingServiceProvider lookupProvider() { - ServiceLoader<LoggingServiceProvider> loader = ServiceLoader.load(LoggingServiceProvider.class); Iterator<LoggingServiceProvider> iterator = loader.iterator(); - if (!iterator.hasNext()) { - System.err.printf("[ERROR] No provider configured for logging services %s. " - + "Default implementation will be used.\n", LoggingServiceProvider.class.getName()); + System.err.printf("[ERROR] No provider configured for logging services %s. " + "Default implementation will be used.\n", + LoggingServiceProvider.class.getName()); return null; } - try { - LoggingServiceProvider provider = iterator.next(); if (!iterator.hasNext()) { return provider; } - Logger logger = provider.getLogger(ServiceBinder.class); if (logger.isWarnEnabled()) { - logger.warn("More than one provider for logging services {} found", - LoggingServiceProvider.class.getName()); + logger.warn("More than one provider for logging services {} found", LoggingServiceProvider.class.getName()); } - return provider; - } catch (Exception e) { // don't fail if the provider cannot be instantiated e.printStackTrace(System.err); @@ -86,4 +78,3 @@ class ServiceBinder { return Optional.ofNullable(PROVIDER); } } - diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/package-info.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/package-info.java index cfe80da244..5faad5a7a3 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/package-info.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/package-info.java @@ -17,9 +17,9 @@ /** * <p>Client-visible API for logging, implemented according to * <a href="https://wiki.onap.org/download/attachments/1015849/ONAP%20application%20logging%20guidelines.pdf?api=v2"> - * ONAP application logging guidelines</a>. The actual implementation is delegated to a service provider bound through - * the <a href="https://docs.oracle.com/javase/tutorial/ext/basics/spi.html">Java SPI</a> mechanism. The provider must - * implement {@link org.openecomp.sdc.logging.spi.LoggingServiceProvider}.</p> + * ONAP application logging guidelines</a>. The actual implementation is delegated to a service provider bound through the <a + * href="https://docs.oracle.com/javase/tutorial/ext/basics/spi.html">Java SPI</a> mechanism. The provider must implement {@link + * org.openecomp.sdc.logging.spi.LoggingServiceProvider}.</p> * <p>The logging API collects the following types of data:</p> * <ol> * <li>Context that must be propagated throughout the application, and available at any point for debug and error @@ -35,4 +35,4 @@ * @author evitaliy * @since 26 Mar 2018 */ -package org.openecomp.sdc.logging.api; +package org.openecomp.sdc.logging.api; |