From eaeba3db217233dd20972f2d3d8a094d44ce0637 Mon Sep 17 00:00:00 2001 From: "Singla, Rajiv (rs153v)" Date: Wed, 25 Jul 2018 12:04:38 -0400 Subject: Initial commit for EELF Logger Issue-ID: DCAEGEN2-633 Change-Id: I108929219d2d6570080d2fe7792cbc5a6530bb59 Signed-off-by: Singla, Rajiv (rs153v) --- .gitignore | 13 + eelf-logger/cpd-exclude.properties | 21 + eelf-logger/eelf-logger-api/pom.xml | 48 ++ .../utils/eelf/logger/api/info/AppLogInfo.java | 101 ++++ .../utils/eelf/logger/api/info/CodeLogInfo.java | 55 ++ .../eelf/logger/api/info/CustomFieldsLogInfo.java | 62 +++ .../utils/eelf/logger/api/info/ErrorLogInfo.java | 76 +++ .../dcae/utils/eelf/logger/api/info/LogInfo.java | 30 ++ .../eelf/logger/api/info/LogLevelCategory.java | 36 ++ .../utils/eelf/logger/api/info/MessageLogInfo.java | 62 +++ .../utils/eelf/logger/api/info/MiscLogInfo.java | 45 ++ .../eelf/logger/api/info/NagiosAlertLevel.java | 52 ++ .../eelf/logger/api/info/RequestIdLogInfo.java | 44 ++ .../eelf/logger/api/info/RequestStatusCode.java | 32 ++ .../eelf/logger/api/info/RequestTimingLogInfo.java | 64 +++ .../eelf/logger/api/info/ResponseLogInfo.java | 81 +++ .../utils/eelf/logger/api/info/ServiceLogInfo.java | 61 +++ .../eelf/logger/api/info/TargetServiceLogInfo.java | 54 ++ .../utils/eelf/logger/api/info/package-info.java | 28 + .../dcae/utils/eelf/logger/api/log/AuditLog.java | 130 +++++ .../dcae/utils/eelf/logger/api/log/DebugLog.java | 76 +++ .../utils/eelf/logger/api/log/EELFLogFactory.java | 85 +++ .../dcae/utils/eelf/logger/api/log/EELFLogger.java | 67 +++ .../eelf/logger/api/log/EELFLoggerContext.java | 56 ++ .../dcae/utils/eelf/logger/api/log/ErrorLog.java | 93 ++++ .../dcae/utils/eelf/logger/api/log/MetricLog.java | 130 +++++ .../utils/eelf/logger/api/log/package-info.java | 23 + .../utils/eelf/logger/api/noop/NoOpAuditLog.java | 90 ++++ .../utils/eelf/logger/api/noop/NoOpDebugLog.java | 56 ++ .../utils/eelf/logger/api/noop/NoOpEELFLogger.java | 77 +++ .../utils/eelf/logger/api/noop/NoOpErrorLog.java | 68 +++ .../utils/eelf/logger/api/noop/NoOpMetricLog.java | 89 ++++ .../utils/eelf/logger/api/noop/package-info.java | 26 + .../utils/eelf/logger/api/spec/AppLogSpec.java | 32 ++ .../utils/eelf/logger/api/spec/AuditLogSpec.java | 42 ++ .../utils/eelf/logger/api/spec/DebugLogSpec.java | 34 ++ .../utils/eelf/logger/api/spec/ErrorLogSpec.java | 42 ++ .../utils/eelf/logger/api/spec/MetricLogSpec.java | 36 ++ .../eelf/logger/api/spec/OptionalLogSpec.java | 39 ++ .../utils/eelf/logger/api/spec/package-info.java | 28 + eelf-logger/eelf-logger-logback-impl/pom.xml | 62 +++ .../eelf/logger/logback/EELFLoggerDefaults.java | 105 ++++ .../eelf/logger/logback/filter/MarkerFilter.java | 71 +++ .../eelf/logger/logback/layout/AuditLogLayout.java | 81 +++ .../eelf/logger/logback/layout/ConsoleLayout.java | 56 ++ .../eelf/logger/logback/layout/DebugLogLayout.java | 54 ++ .../eelf/logger/logback/layout/ErrorLogLayout.java | 64 +++ .../logger/logback/layout/MetricLogLayout.java | 83 +++ .../logback/listener/LogbackStartupListener.java | 128 +++++ .../eelf/logger/logback/log/AuditLogImpl.java | 119 +++++ .../eelf/logger/logback/log/DebugLogImpl.java | 88 +++ .../logger/logback/log/EELFLoggerContextImpl.java | 57 ++ .../eelf/logger/logback/log/EELFLoggerImpl.java | 81 +++ .../eelf/logger/logback/log/ErrorLogImpl.java | 98 ++++ .../eelf/logger/logback/log/MetricLogImpl.java | 120 +++++ .../resolver/CompositePropertyResolver.java | 53 ++ .../resolver/EnvironmentPropertyResolver.java | 46 ++ .../logger/logback/resolver/PropertyResolver.java | 41 ++ .../logback/resolver/SystemPropertyResolver.java | 59 +++ .../utils/eelf/logger/logback/utils/LogUtils.java | 590 +++++++++++++++++++++ ....onap.dcae.utils.eelf.logger.api.log.EELFLogger | 20 + .../src/main/resources/eelf-async-appenders.xml | 55 ++ .../src/main/resources/eelf-defaults.xml | 51 ++ .../src/main/resources/eelf-logback.xml | 45 ++ .../src/main/resources/eelf-optional-appenders.xml | 68 +++ .../src/main/resources/eelf-required-appenders.xml | 112 ++++ .../eelf/logger/logback/BaseLogbackUnitTest.java | 157 ++++++ .../eelf/logger/logback/log/AuditLogImplTest.java | 66 +++ .../eelf/logger/logback/log/DebugLogImplTest.java | 53 ++ .../eelf/logger/logback/log/ErrorLogImplTest.java | 61 +++ .../eelf/logger/logback/log/MetricLogImplTest.java | 67 +++ .../src/test/resources/logback.xml | 41 ++ eelf-logger/eelf-logger-model/pom.xml | 77 +++ .../eelf/logger/model/info/AppLogInfoImpl.java | 53 ++ .../eelf/logger/model/info/CodeLogInfoImpl.java | 48 ++ .../logger/model/info/CustomFieldsLogInfoImpl.java | 51 ++ .../eelf/logger/model/info/ErrorLogInfoImpl.java | 47 ++ .../eelf/logger/model/info/MessageLogInfoImpl.java | 54 ++ .../eelf/logger/model/info/MiscLogInfoImpl.java | 47 ++ .../logger/model/info/RequestIdLogInfoImpl.java | 45 ++ .../model/info/RequestTimingLogInfoImpl.java | 51 ++ .../logger/model/info/ResponseLogInfoImpl.java | 47 ++ .../eelf/logger/model/info/ServiceLogInfoImpl.java | 49 ++ .../model/info/TargetServiceLogInfoImpl.java | 48 ++ .../utils/eelf/logger/model/info/package-info.java | 23 + .../eelf/logger/model/spec/AppLogSpecImpl.java | 47 ++ .../eelf/logger/model/spec/AuditLogSpecImpl.java | 61 +++ .../eelf/logger/model/spec/DebugLogSpecImpl.java | 48 ++ .../eelf/logger/model/spec/ErrorLogSpecImpl.java | 61 +++ .../eelf/logger/model/spec/MetricLogSpecImpl.java | 64 +++ .../logger/model/spec/OptionalLogSpecImpl.java | 60 +++ .../utils/eelf/logger/model/spec/package-info.java | 23 + eelf-logger/findbugs-exclude.xml | 30 ++ eelf-logger/pmd-exclude.properties | 22 + eelf-logger/pom.xml | 476 +++++++++++++++++ eelf-logger/version.properties | 25 + pom.xml | 1 + 97 files changed, 6694 insertions(+) create mode 100644 eelf-logger/cpd-exclude.properties create mode 100644 eelf-logger/eelf-logger-api/pom.xml create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/AppLogInfo.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/CodeLogInfo.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/CustomFieldsLogInfo.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ErrorLogInfo.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/LogInfo.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/LogLevelCategory.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/MessageLogInfo.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/MiscLogInfo.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/NagiosAlertLevel.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestIdLogInfo.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestStatusCode.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestTimingLogInfo.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ResponseLogInfo.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ServiceLogInfo.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/TargetServiceLogInfo.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/package-info.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/AuditLog.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/DebugLog.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLogFactory.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLogger.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLoggerContext.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/ErrorLog.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/MetricLog.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/package-info.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpAuditLog.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpDebugLog.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpEELFLogger.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpErrorLog.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpMetricLog.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/package-info.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/AppLogSpec.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/AuditLogSpec.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/DebugLogSpec.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/ErrorLogSpec.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/MetricLogSpec.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/OptionalLogSpec.java create mode 100644 eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/package-info.java create mode 100644 eelf-logger/eelf-logger-logback-impl/pom.xml create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/EELFLoggerDefaults.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/filter/MarkerFilter.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/AuditLogLayout.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/ConsoleLayout.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/DebugLogLayout.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/ErrorLogLayout.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/MetricLogLayout.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/listener/LogbackStartupListener.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/AuditLogImpl.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/DebugLogImpl.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/EELFLoggerContextImpl.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/EELFLoggerImpl.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/ErrorLogImpl.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/MetricLogImpl.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/CompositePropertyResolver.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/EnvironmentPropertyResolver.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/PropertyResolver.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/SystemPropertyResolver.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/utils/LogUtils.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/resources/META-INF/services/org.onap.dcae.utils.eelf.logger.api.log.EELFLogger create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-async-appenders.xml create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-defaults.xml create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-logback.xml create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-optional-appenders.xml create mode 100644 eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-required-appenders.xml create mode 100644 eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/BaseLogbackUnitTest.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/AuditLogImplTest.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/DebugLogImplTest.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/ErrorLogImplTest.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/MetricLogImplTest.java create mode 100644 eelf-logger/eelf-logger-logback-impl/src/test/resources/logback.xml create mode 100644 eelf-logger/eelf-logger-model/pom.xml create mode 100644 eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/AppLogInfoImpl.java create mode 100644 eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/CodeLogInfoImpl.java create mode 100644 eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/CustomFieldsLogInfoImpl.java create mode 100644 eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ErrorLogInfoImpl.java create mode 100644 eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/MessageLogInfoImpl.java create mode 100644 eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/MiscLogInfoImpl.java create mode 100644 eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/RequestIdLogInfoImpl.java create mode 100644 eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/RequestTimingLogInfoImpl.java create mode 100644 eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ResponseLogInfoImpl.java create mode 100644 eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ServiceLogInfoImpl.java create mode 100644 eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/TargetServiceLogInfoImpl.java create mode 100644 eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/package-info.java create mode 100644 eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/AppLogSpecImpl.java create mode 100644 eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/AuditLogSpecImpl.java create mode 100644 eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/DebugLogSpecImpl.java create mode 100644 eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/ErrorLogSpecImpl.java create mode 100644 eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/MetricLogSpecImpl.java create mode 100644 eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/OptionalLogSpecImpl.java create mode 100644 eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/package-info.java create mode 100644 eelf-logger/findbugs-exclude.xml create mode 100644 eelf-logger/pmd-exclude.properties create mode 100644 eelf-logger/pom.xml create mode 100644 eelf-logger/version.properties diff --git a/.gitignore b/.gitignore index 3b3b613..59bb4de 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,16 @@ docs/_build/ target/ logs/ + + +# Intellij Files & Dir # +*.iml +*.ipr +*.iws +*.uml + +atlassian-ide-plugin.xml +out/ +.DS_Store +./lib/ +.idea diff --git a/eelf-logger/cpd-exclude.properties b/eelf-logger/cpd-exclude.properties new file mode 100644 index 0000000..399fb30 --- /dev/null +++ b/eelf-logger/cpd-exclude.properties @@ -0,0 +1,21 @@ +# +# ================================================================================ +# Copyright (c) 2018 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========================================================= +# +# + +# Ignored as there are different log specs +org.onap.dcae.utils.eelf.logger.model.spec.AuditLogSpecImpl,org.onap.dcae.utils.eelf.logger.model.spec.MetricLogSpecImpl diff --git a/eelf-logger/eelf-logger-api/pom.xml b/eelf-logger/eelf-logger-api/pom.xml new file mode 100644 index 0000000..1d7fa1b --- /dev/null +++ b/eelf-logger/eelf-logger-api/pom.xml @@ -0,0 +1,48 @@ + + + + + + 4.0.0 + + + org.onap.dcaegen2.utils + eelf-logger + 1.0.0-SNAPSHOT + + + eelf-logger-api + jar + + + dcaegen2-utils-eelf-logger-api + API contracts for EELF Logging Framework + + + ${project.parent.basedir} + + **/api/** + + + + + diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/AppLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/AppLogInfo.java new file mode 100644 index 0000000..bdce8d1 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/AppLogInfo.java @@ -0,0 +1,101 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.info; + +/** + * Captures information about application which is doing the logging. All app log fields must remain same for + * the whole duration of the application once its instance is created. + * + * @author Rajiv Singla + */ +public interface AppLogInfo extends LogInfo { + + /** + * Required field contains UUID which identifies this service instance inside an inventory management system + * (e.g. A&AI) to reference/manage this service as a unit + * + * @return remote VM Name or service the request is acting upon. + */ + String getServiceInstanceID(); + + /** + * Required field contains a universally unique identifier used to differentiate between multiple instances of + * the same (named), log writing service/application. Its value is set at instance creation time (and read by it, + * e.g. at start/initialization time from the environment). This value should be picked up by the component + * instance from its configuration file and subsequently used to enable differentiating log records created by + * multiple, locally load balanced EELF component or sub component instances that are otherwise identically + * configured. + * + * @return instance UUID + */ + String getInstanceUUID(); + + /** + * Optional field contains VM Name where app is deployed. + * DCAE sub components should populate this field but it can be empty if + * determined that its value can be added by the log files collecting agent itself (e.g. Splunk). + *

+ * Example: host.vm.name.com + *

+ * + * @return virtual server name + */ + String getVirtualServerName(); + + /** + * Optional field contains the logging component host server’s IP address. + *

+ * Example: 127.0.0.100 + *

+ * + * @return server ip address + */ + String getServerIPAddress(); + + /** + * Required field for VM's fully qualified domain name or hosting machine fully qualified domain name. + *

+ * Example: host.fqdn.com + *

+ * + * @return server host fully qualified domain name + */ + String getServerFQDN(); + + + /** + * Contains default values for {@link AppLogInfo} + */ + interface Defaults { + + String DEFAULT_SERVICE_INSTANCE_ID = "UNKNOWN_INSTANCE_ID"; + + String DEFAULT_INSTANCE_UUID = ""; + + String DEFAULT_VIRTUAL_SERVER_NAME = ""; + + String DEFAULT_SERVER_IP_ADDRESS = "UNKNOWN_IP_ADDRESS"; + + String DEFAULT_SERVER_FQDN = "UNKNOWN_SERVER_FQDN"; + + } + + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/CodeLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/CodeLogInfo.java new file mode 100644 index 0000000..bea195d --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/CodeLogInfo.java @@ -0,0 +1,55 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.info; + +/** + * Capture field required to log details about code which is generating the log message. + *

+ * NOTE: When using a logging framework(e.g. logback) implementation these fields may be automatically deduced - so + * settings these fields is not required by the application and even if application sets these fields the logging + * framework may ignore it + * + *

+ * + * @author Rajiv Singla + */ +public interface CodeLogInfo extends LogInfo { + + + /** + * Optional field used if wanting to trace processing of a request over a number of sub-components of a single EELF + * component. It should be preceded by a log record that establishes its chaining back to the corresponding + * requestID. + * + * @return thread ID used to trace processing of request over number of sub-components of single EELF Component. + */ + String getThreadId(); + + + /** + * Optional field: If available for OO programing languages that support this concept. This is the name of the + * class that has caused the log record to be created. + * + * @return name of the class that has the caused the log record to be created + */ + String getClassName(); + + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/CustomFieldsLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/CustomFieldsLogInfo.java new file mode 100644 index 0000000..634afa6 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/CustomFieldsLogInfo.java @@ -0,0 +1,62 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.info; + +/** + * Captures fields required to log Custom fields + * + * @author Rajiv Singla + */ +public interface CustomFieldsLogInfo extends LogInfo { + + /** + * Optional field that can be used by developers to include additional application-specific + * information to support operations and troubleshooting of the system. + * + * @return additional application-specific information to support operations and troubleshooting of the system. + */ + String getCustomField1(); + + /** + * Optional field that can be used by developers to include additional application-specific + * information to support operations and troubleshooting of the system. + * + * @return additional application-specific information to support operations and troubleshooting of the system. + */ + String getCustomField2(); + + /** + * Optional field that can be used by developers to include additional application-specific + * information to support operations and troubleshooting of the system. + * + * @return additional application-specific information to support operations and troubleshooting of the system. + */ + String getCustomField3(); + + /** + * Optional field that can be used by developers to include additional application-specific + * information to support operations and troubleshooting of the system. + * + * @return additional application-specific information to support operations and troubleshooting of the system. + */ + String getCustomField4(); + + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ErrorLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ErrorLogInfo.java new file mode 100644 index 0000000..876037c --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ErrorLogInfo.java @@ -0,0 +1,76 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.info; + +/** + * Captures fields required to log error related information + * + * @author Rajiv Singla + */ +public interface ErrorLogInfo extends LogInfo { + + + /** + * Required field contains an error code representing the error condition. The codes can be chose by + * the logging application but they should adhere to the guidelines embodied in the table below: + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Error typeNotes
100Permission errors
200Availability errors/Timeouts
300Data errors
400Schema errors
500Business process errors
900Unknown Errors
+ * + * @return error Code + */ + Integer getErrorCode(); + + + /** + * Required field contains a human readable description of the error condition. + * + * @return human readable description of the error condition + */ + String getErrorDescription(); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/LogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/LogInfo.java new file mode 100644 index 0000000..4a3680f --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/LogInfo.java @@ -0,0 +1,30 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.info; + +import java.io.Serializable; + +/** + * Marker interface for all EELF Logging Information Components + * + * @author Rajiv Singla + */ +public interface LogInfo extends Serializable { +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/LogLevelCategory.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/LogLevelCategory.java new file mode 100644 index 0000000..665a280 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/LogLevelCategory.java @@ -0,0 +1,36 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.info; + +/** + * Captures various logging levels. + * NOTE: Enum ordered signifies low to high log level severity + * + * @author Rajiv Singla + */ +public enum LogLevelCategory implements LogInfo { + + DEBUG, + INFO, + WARN, + ERROR, + FATAL; + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/MessageLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/MessageLogInfo.java new file mode 100644 index 0000000..cd53ccf --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/MessageLogInfo.java @@ -0,0 +1,62 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.info; + +import java.util.Date; + +/** + * Captures fields required for message level logging. These fields are mostly derived fields. For example: creation + * timestamp can be auto generated based on system time, {@link RequestStatusCode} and {@link NagiosAlertLevel} can be + * derived based on {@link LogLevelCategory} + * + * @author Rajiv Singla + */ +public interface MessageLogInfo extends LogInfo { + + + /** + * Required field to capture when the message was created + * The value should be represented in UTC and formatted according to ISO 8601. + *

+ * Example: 2015-06-03T13:21:58+00:00 + *

+ * + * @return message creation creationTimestamp + */ + Date getCreationTimestamp(); + + /** + * Required field contains a value of COMPLETE or ERROR to indicate high level success or failure of the + * request related activities. + * + * @return value to indicate high level success or failure of the request related activities + */ + RequestStatusCode getStatusCode(); + + + /** + * Optional field for Nagios monitoring/alerting severity code + * + * @return nagios monitoring/alerting severity code + */ + NagiosAlertLevel getAlertSeverity(); + + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/MiscLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/MiscLogInfo.java new file mode 100644 index 0000000..bf1e451 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/MiscLogInfo.java @@ -0,0 +1,45 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.info; + +/** + * Captures optional / deprecated fields that can be populated as per EELF Logging Requirements + * + * @author Rajiv Singla + */ +public interface MiscLogInfo extends LogInfo { + + /** + * Optional field that can can be used to capture the flow of a transaction through the system by + * indicating the components and operations involved in processed. If present, it can be denoted by a comma + * separated list of components and applications. + * + * @return list of comma separated components and operations involved in processing + */ + String getProcessId(); + + /** + * This field is deprecated and should be left empty. + * + * @return deprecated field value - should be empty + */ + String getUnused(); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/NagiosAlertLevel.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/NagiosAlertLevel.java new file mode 100644 index 0000000..3da5fc3 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/NagiosAlertLevel.java @@ -0,0 +1,52 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.info; + +/** + * Enum for Nagios monitoring/alerting codes as per table below. + *

+ * + * + * + * + * + * + *
Return CodeService StateHost State
0OKUP
1WARNINGUP or DOWN/UNREACHABLE*
2CRITICALDOWN/UNREACHABLE
3UNKNOWNDOWN/UNREACHABLE
+ * + * @author Rajiv Singla + */ +public enum NagiosAlertLevel implements LogInfo { + + OK("0"), + WARNING("1"), + CRITICAL("2"), + UNKNOWN("3"); + + private String severityCode; + + NagiosAlertLevel(final String severityCode) { + this.severityCode = severityCode; + } + + public String getSeverityCode() { + return severityCode; + } + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestIdLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestIdLogInfo.java new file mode 100644 index 0000000..68d5a17 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestIdLogInfo.java @@ -0,0 +1,44 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.info; + +/** + * Captures fields required for logging request information + * + * @author Rajiv Singla + */ +public interface RequestIdLogInfo extends LogInfo { + + /** + * Required field containing requestID which uniquely that identifies a single transaction request within the EELF + * platform. Its value is conforms to RFC4122 UUID. The requestID value is passed using a REST API from one + * EELF component to another via HTTP Headers named X-RequestID + *

+ * 724229c0-9945-11e5-bcde-0002a5d5c51b:1234 + *

+ * If receiving a composite requestID value, e.g. something of the form UUID-1:UUID-2, the receiving component + * should only use the UUID-1 portion (i.e. remove the “:” and any trailing suffix, e.g. UUID-2) as the requestID + * field value for its log files. + * + * @return requestID which uniquely that identifies a single transaction request within the EELF + */ + String getRequestId(); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestStatusCode.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestStatusCode.java new file mode 100644 index 0000000..b022b80 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestStatusCode.java @@ -0,0 +1,32 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.info; + +/** + * Enum to indicate high level success or failure of the request related activities + * + * @author Rajiv Singla + */ +public enum RequestStatusCode { + + ERROR, + COMPLETE; + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestTimingLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestTimingLogInfo.java new file mode 100644 index 0000000..7448e69 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/RequestTimingLogInfo.java @@ -0,0 +1,64 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.info; + +import java.util.Date; + +/** + * Captures Logging fields required for request timing related information + * + * @author Rajiv Singla + */ +public interface RequestTimingLogInfo extends LogInfo { + + /** + * Required field containing creationTimestamp when the request processing started. + * The value should be represented in UTC and formatted according to ISO 8601. + *

+ * Example: 2015-06-03T13:21:58+00:00 + *

+ * + * @return request activity begin creationTimestamp + */ + Date getBeginTimestamp(); + + + /** + * Required field containing creationTimestamp when the request processed stopped. + * The value should be represented in UTC and formatted according to ISO 8601. + *

+ * Example: 2015-06-03T13:21:58+00:00 + *

+ * + * @return request activity end creationTimestamp + */ + Date getEndTimestamp(); + + + /** + * Required field contains the elapsed time to complete processing of an API call or transaction request (e.g., + * processing of a message that was received). This value should be the difference between EndTimestamp and + * BeginTimestamp fields and should be expressed in milliseconds. + * + * @return request processing elapsed time in milliseconds + */ + Long getElapsedTime(); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ResponseLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ResponseLogInfo.java new file mode 100644 index 0000000..1929e7f --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ResponseLogInfo.java @@ -0,0 +1,81 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.info; + +/** + * Captures field required for logging Response information + * + * @author Rajiv Singla + */ +public interface ResponseLogInfo extends LogInfo { + + /** + * Required field contains application-specific response codes. While error codes are + * application-specific, they + * should conform categories mentioned in table below in order to provide consistency + *

+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Error typeNotes
0Success
100Permission errors
200Availability errors/Timeouts
300Data errors
400Schema errors
500Business process errors
900Unknown Errors
+ * + * @return application-specific error code + */ + Integer getResponseCode(); + + + /** + * Required field contains a human readable description of the {@link #getResponseCode()}. + * + * @return human readable description of the response code + */ + String getResponseDescription(); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ServiceLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ServiceLogInfo.java new file mode 100644 index 0000000..0287cef --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/ServiceLogInfo.java @@ -0,0 +1,61 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.info; + +/** + * Captures information about logging fields for application acting as service and handling requests from other + * applications + * + * @author Rajiv Singla + */ +public interface ServiceLogInfo extends LogInfo { + + /** + * Required field contains the developer given name of the ecomp component's exposed api (~='method', function') + * invoked. For example if the application is exposing a REST interface and exposing runtime metrics then the + * service name can be: appName-getMetrics + * + * @return name of the API invoked by the application + */ + String getServiceName(); + + + /** + * Optional field contains the name of the client or user invoking the service. + * It may be an application, user name or mech id. + * + * @return name of the client or user invoking the API if known + */ + String getPartnerName(); + + + /** + * Optional field contains requesting remote client application’s IP address. Use UNKNOWN or an empty string if not + * available. + * + * @return remote client application’s IP address + */ + String getClientIPAddress(); + + +} + + + diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/TargetServiceLogInfo.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/TargetServiceLogInfo.java new file mode 100644 index 0000000..d9b1f98 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/TargetServiceLogInfo.java @@ -0,0 +1,54 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.info; + +/** + * Captures fields for logging application which is calling an external/target service + * + * @author Rajiv Singla + */ +public interface TargetServiceLogInfo extends LogInfo { + + /** + * Required field containing name of EELF component/sub component or non-EELF entity which is invoked by the + * logging application + * + * @return target entity name which is invoked by the logging application + */ + String getTargetEntity(); + + + /** + * Required field containing name of External API/operation activities invoked on {@link #getTargetEntity()} + * + * @return target service name invoked by the logging application + */ + String getTargetServiceName(); + + + /** + * Optional field containing target VNF or VM being acted upon by the logging application. This field contains the + * virtual entity that is the target of the action for example the FQDN of the target virtual entity + * + * @return target Virtual Entity + */ + String getTargetVirtualEntity(); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/package-info.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/package-info.java new file mode 100644 index 0000000..45bddd1 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/info/package-info.java @@ -0,0 +1,28 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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========================================================= + * + */ + +/** + * Captures EELF logging information about various types. + *

+ * The logging information is segregated into various information different types as to their relevance in particular + * cases. + * + * @author Rajiv Singla + */ +package org.onap.dcae.utils.eelf.logger.api.info; diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/AuditLog.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/AuditLog.java new file mode 100644 index 0000000..952176e --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/AuditLog.java @@ -0,0 +1,130 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.log; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; + +/** + * Audit Log captures all log levels supported by audit specifications + * + * @author Rajiv Singla + */ +public interface AuditLog { + + /** + * Logs audit message with provided {@link LogLevelCategory} + * + * @param logLevelCategory log level category + * @param message log message + * @param auditLogSpec audit log spec + * @param optionalLogSpec optional log spec + * @param args argument values for log message interpolation + */ + void log(LogLevelCategory logLevelCategory, String message, AuditLogSpec auditLogSpec, + OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs audit message with provided {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param logLevelCategory log level category + * @param message log message + * @param auditLogSpec audit log spec + * @param args argument values for log message interpolation + */ + void log(LogLevelCategory logLevelCategory, String message, AuditLogSpec auditLogSpec, String... args); + + + /** + * Logs audit message with provided INFO {@link LogLevelCategory} + * + * @param message log message + * @param auditLogSpec audit log spec + * @param args argument values for log message interpolation + */ + void info(String message, AuditLogSpec auditLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs audit message with provided INFO {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param auditLogSpec audit log spec + * @param args argument values for log message interpolation + */ + void info(String message, AuditLogSpec auditLogSpec, String... args); + + + /** + * Logs audit message with provided WARN {@link LogLevelCategory} + * + * @param message log message + * @param auditLogSpec audit log spec + * @param args argument values for log message interpolation + */ + void warn(String message, AuditLogSpec auditLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs audit message with provided WARN {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param auditLogSpec audit log spec + * @param args argument values for log message interpolation + */ + void warn(String message, AuditLogSpec auditLogSpec, String... args); + + /** + * Logs audit message with provided ERROR {@link LogLevelCategory} + * + * @param message log message + * @param auditLogSpec audit log spec + * @param args argument values for log message interpolation + */ + void error(String message, AuditLogSpec auditLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs audit message with provided ERROR {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param auditLogSpec audit log spec + * @param args argument values for log message interpolation + */ + void error(String message, AuditLogSpec auditLogSpec, String... args); + + /** + * Logs audit message with provided FATAL {@link LogLevelCategory} + * + * @param message log message + * @param auditLogSpec audit log spec + * @param args argument values for log message interpolation + */ + void fatal(String message, AuditLogSpec auditLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs audit message with provided FATAL {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param auditLogSpec audit log spec + * @param args argument values for log message interpolation + */ + void fatal(String message, AuditLogSpec auditLogSpec, String... args); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/DebugLog.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/DebugLog.java new file mode 100644 index 0000000..98a0921 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/DebugLog.java @@ -0,0 +1,76 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.log; + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; + +/** + * Debug Log captures all log levels supported by debug specifications. + *

+ * NOTE: DEBUG Log is optional as per EELF Specifications + * + * @author Rajiv Singla + */ +public interface DebugLog { + + /** + * Logs debug message with provided {@link LogLevelCategory} + * + * @param logLevelCategory log level category + * @param message log message + * @param debugLogSpec debug log spec + * @param optionalLogSpec optional log spec + * @param args argument values for log message interpolation + */ + void log(LogLevelCategory logLevelCategory, String message, DebugLogSpec debugLogSpec, + OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs debug message with provided {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param logLevelCategory log level category + * @param message log message + * @param debugLogSpec debug log spec + * @param args argument values for log message interpolation + */ + void log(LogLevelCategory logLevelCategory, String message, DebugLogSpec debugLogSpec, String... args); + + + /** + * Logs debug message with provided DEBUG {@link LogLevelCategory} + * + * @param message log message + * @param debugLogSpec debug log spec + * @param args argument values for log message interpolation + */ + void debug(String message, DebugLogSpec debugLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs debug message with provided DEBUG {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param debugLogSpec debug log spec + * @param args argument values for log message interpolation + */ + void debug(String message, DebugLogSpec debugLogSpec, String... args); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLogFactory.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLogFactory.java new file mode 100644 index 0000000..2cfb2ec --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLogFactory.java @@ -0,0 +1,85 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.log; + + +import org.onap.dcae.utils.eelf.logger.api.noop.NoOpEELFLogger; + +import java.lang.reflect.InvocationTargetException; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.ServiceLoader; +import java.util.WeakHashMap; + +/** + * EELF Log Factory uses {@link ServiceLoader} to load implementations of {@link EELFLogger} in application + * classpath. If no EELF Logging implementations are found - eelf logging is disabled and {@link NoOpEELFLogger} + * is used. + * + * @author Rajiv Singla + */ +public class EELFLogFactory { + + private static final ServiceLoader SERVICE_LOADER = ServiceLoader.load(EELFLogger.class); + private static final Map, EELFLogger> LOGGER_CACHE = new WeakHashMap<>(64); + + private static List loggerImplementations = new LinkedList<>(); + + static { + + for (EELFLogger loggerImplementation : SERVICE_LOADER) { + loggerImplementations.add(loggerImplementation); + } + + if (loggerImplementations.isEmpty()) { + System.err.println( + "EELF LOGGING ERROR: Unable to find any EELF Logger Implementations in the classpath."); + System.err.println("=============EELF LOGGING IS DISABLED================"); + loggerImplementations.add(NoOpEELFLogger.getInstance()); + } + + } + + private EELFLogFactory() { + // private constructor + } + + public static EELFLogger getLogger(Class clazz) { + + if (LOGGER_CACHE.get(clazz) != null) { + return LOGGER_CACHE.get(clazz); + } + + EELFLogger EELFLogger = null; + try { + EELFLogger = loggerImplementations.get(0).getClass().getConstructor(Class.class) + .newInstance(clazz); + return EELFLogger; + + } catch ( + InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + throw new IllegalStateException("Error while Creating EELF Logger", e); + } + + } + + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLogger.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLogger.java new file mode 100644 index 0000000..500d814 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLogger.java @@ -0,0 +1,67 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.log; + +/** + * EELF Logger is main abstraction which applications use to log EELF Compliant log messages + * + * @author Rajiv Singla + */ +public interface EELFLogger { + + /** + * Provides Audit Log + * + * @return Audit log + */ + AuditLog auditLog(); + + + /** + * Provides Metric Log + * + * @return metric log + */ + MetricLog metricLog(); + + /** + * Provides Error Log + * + * @return error log + */ + ErrorLog errorLog(); + + + /** + * Provides Debug Log + * + * @return debug log + */ + DebugLog debugLog(); + + /** + * Provides logging context + * + * @return logging context + */ + EELFLoggerContext loggingContext(); + + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLoggerContext.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLoggerContext.java new file mode 100644 index 0000000..5910da5 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/EELFLoggerContext.java @@ -0,0 +1,56 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.log; + + +import org.onap.dcae.utils.eelf.logger.api.spec.AppLogSpec; + +/** + * EELF Logger Context contains fields are set during application creation time and are fixed for the entire + * duration of the application lifetime + * + * @author Rajiv Singla + */ +public interface EELFLoggerContext { + + /** + * Returns App Log Spec + * + * @return current app log spec + */ + AppLogSpec getAppLogSpec(); + + + /** + * Sets new App Log Spec + * + * @param appLogSpec new app log spec + */ + void setAppLogSpec(AppLogSpec appLogSpec); + + + /** + * Returns true if logging context is already initialized + * + * @return true if logger context is already initialized + */ + boolean isInitialized(); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/ErrorLog.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/ErrorLog.java new file mode 100644 index 0000000..6b27755 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/ErrorLog.java @@ -0,0 +1,93 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.log; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; + +/** + * @author Rajiv Singla + */ +public interface ErrorLog { + + /** + * Logs error message with provided {@link LogLevelCategory} + * + * @param logLevelCategory log level category + * @param message log message + * @param errorLogSpec error log spec + * @param optionalLogSpec optional log spec + * @param args argument values for log message interpolation + */ + void log(LogLevelCategory logLevelCategory, String message, ErrorLogSpec errorLogSpec, + OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs error message with provided {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param logLevelCategory log level category + * @param message log message + * @param errorLogSpec error log spec + * @param args argument values for log message interpolation + */ + void log(LogLevelCategory logLevelCategory, String message, ErrorLogSpec errorLogSpec, String... args); + + + /** + * Logs error message with ERROR {@link LogLevelCategory} + * + * @param message log message + * @param errorLogSpec error log spec + * @param args argument values for log message interpolation + */ + void error(String message, ErrorLogSpec errorLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs error message with ERROR {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param errorLogSpec error log spec + * @param args argument values for log message interpolation + */ + void error(String message, ErrorLogSpec errorLogSpec, String... args); + + + /** + * Logs error message with WARN {@link LogLevelCategory} + * + * @param message log message + * @param errorLogSpec error log spec + * @param args argument values for log message interpolation + */ + void warn(String message, ErrorLogSpec errorLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs error message with WARN {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param errorLogSpec error log spec + * @param args argument values for log message interpolation + */ + void warn(String message, ErrorLogSpec errorLogSpec, String... args); + + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/MetricLog.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/MetricLog.java new file mode 100644 index 0000000..ebc33ca --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/MetricLog.java @@ -0,0 +1,130 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.log; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.spec.MetricLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; + +/** + * Metric Log captures all log levels supported by metric specifications + * + * @author Rajiv Singla + */ +public interface MetricLog { + + /** + * Logs metric message with provided {@link LogLevelCategory} + * + * @param logLevelCategory log level category + * @param message log message + * @param metricLogSpec metric log spec + * @param optionalLogSpec optional log spec + * @param args argument values for log message interpolation + */ + void log(LogLevelCategory logLevelCategory, String message, MetricLogSpec metricLogSpec, + OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs metric message with provided {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param logLevelCategory log level category + * @param message log message + * @param metricLogSpec metric log spec + * @param args argument values for log message interpolation + */ + void log(LogLevelCategory logLevelCategory, String message, MetricLogSpec metricLogSpec, String... args); + + + /** + * Logs metric message with provided INFO {@link LogLevelCategory} + * + * @param message log message + * @param metricLogSpec metric log spec + * @param args argument values for log message interpolation + */ + void info(String message, MetricLogSpec metricLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs metric message with provided INFO {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param metricLogSpec metric log spec + * @param args argument values for log message interpolation + */ + void info(String message, MetricLogSpec metricLogSpec, String... args); + + + /** + * Logs metric message with provided WARN {@link LogLevelCategory} + * + * @param message log message + * @param metricLogSpec metric log spec + * @param args argument values for log message interpolation + */ + void warn(String message, MetricLogSpec metricLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs metric message with provided WARN {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param metricLogSpec metric log spec + * @param args argument values for log message interpolation + */ + void warn(String message, MetricLogSpec metricLogSpec, String... args); + + /** + * Logs metric message with provided ERROR {@link LogLevelCategory} + * + * @param message log message + * @param metricLogSpec metric log spec + * @param args argument values for log message interpolation + */ + void error(String message, MetricLogSpec metricLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs metric message with provided ERROR {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param metricLogSpec metric log spec + * @param args argument values for log message interpolation + */ + void error(String message, MetricLogSpec metricLogSpec, String... args); + + /** + * Logs metric message with provided FATAL {@link LogLevelCategory} + * + * @param message log message + * @param metricLogSpec metric log spec + * @param args argument values for log message interpolation + */ + void fatal(String message, MetricLogSpec metricLogSpec, OptionalLogSpec optionalLogSpec, String... args); + + /** + * Logs metric message with provided FATAL {@link LogLevelCategory} and with default {@link OptionalLogSpec} + * + * @param message log message + * @param metricLogSpec metric log spec + * @param args argument values for log message interpolation + */ + void fatal(String message, MetricLogSpec metricLogSpec, String... args); + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/package-info.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/package-info.java new file mode 100644 index 0000000..e24ccc9 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/log/package-info.java @@ -0,0 +1,23 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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========================================================= + * + */ + +/** + * Contains Logging API contracts for various EELF Logs (e.g. Audit, Metric, Error, Debug etc) + */ +package org.onap.dcae.utils.eelf.logger.api.log; diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpAuditLog.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpAuditLog.java new file mode 100644 index 0000000..6c1c583 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpAuditLog.java @@ -0,0 +1,90 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.noop; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.log.AuditLog; +import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; + +/** + * A no operation implementation of AuditLog + * + * @author Rajiv Singla + */ +public class NoOpAuditLog implements AuditLog { + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final AuditLogSpec auditLogSpec, + final OptionalLogSpec optionalLogSpec, final String... args) { + // no operation + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final AuditLogSpec auditLogSpec, + final String... args) { + // no operation + } + + @Override + public void info(final String message, final AuditLogSpec auditLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void info(final String message, final AuditLogSpec auditLogSpec, final String... args) { + // no operation + } + + @Override + public void warn(final String message, final AuditLogSpec auditLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void warn(final String message, final AuditLogSpec auditLogSpec, final String... args) { + // no operation + } + + @Override + public void error(final String message, final AuditLogSpec auditLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void error(final String message, final AuditLogSpec auditLogSpec, final String... args) { + // no operation + } + + @Override + public void fatal(final String message, final AuditLogSpec auditLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void fatal(final String message, final AuditLogSpec auditLogSpec, final String... args) { + // no operation + } +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpDebugLog.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpDebugLog.java new file mode 100644 index 0000000..dd36b52 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpDebugLog.java @@ -0,0 +1,56 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.noop; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.log.DebugLog; +import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; + +/** + * A no operation implementation of Debug Log + * + * @author Rajiv Singla + */ +public class NoOpDebugLog implements DebugLog { + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final DebugLogSpec debugLogSpec, + final OptionalLogSpec optionalLogSpec, final String... args) { + // no operation + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final DebugLogSpec debugLogSpec, + final String... args) { + // no operation + } + + @Override + public void debug(final String message, final DebugLogSpec debugLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void debug(final String message, final DebugLogSpec debugLogSpec, final String... args) { + // no operation + } +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpEELFLogger.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpEELFLogger.java new file mode 100644 index 0000000..c761ba1 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpEELFLogger.java @@ -0,0 +1,77 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.noop; + + +import org.onap.dcae.utils.eelf.logger.api.log.AuditLog; +import org.onap.dcae.utils.eelf.logger.api.log.DebugLog; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLoggerContext; +import org.onap.dcae.utils.eelf.logger.api.log.ErrorLog; +import org.onap.dcae.utils.eelf.logger.api.log.MetricLog; + +/** + * A no operation implementation of {@link EELFLogger} + * + * @author Rajiv Singla + */ +public class NoOpEELFLogger implements EELFLogger { + + private static final AuditLog NO_OP_AUDIT_LOG = new NoOpAuditLog(); + private static final MetricLog NO_OP_METRIC_LOG = new NoOpMetricLog(); + private static final ErrorLog NO_OP_ERROR_LOG = new NoOpErrorLog(); + private static final DebugLog NO_OP_DEBUG_LOG = new NoOpDebugLog(); + + private static final NoOpEELFLogger NO_OP_EELF_LOGGER = new NoOpEELFLogger(); + + private NoOpEELFLogger() { + // private constructor + } + + public static NoOpEELFLogger getInstance() { + return NO_OP_EELF_LOGGER; + } + + @Override + public AuditLog auditLog() { + return NO_OP_AUDIT_LOG; + } + + @Override + public MetricLog metricLog() { + return NO_OP_METRIC_LOG; + } + + @Override + public ErrorLog errorLog() { + return NO_OP_ERROR_LOG; + } + + @Override + public DebugLog debugLog() { + return NO_OP_DEBUG_LOG; + } + + @Override + public EELFLoggerContext loggingContext() { + return null; + } + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpErrorLog.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpErrorLog.java new file mode 100644 index 0000000..c1b4e13 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpErrorLog.java @@ -0,0 +1,68 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.noop; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.log.ErrorLog; +import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; + +/** + * A no operation implementation of Error Log + * + * @author Rajiv Singla + */ +public class NoOpErrorLog implements ErrorLog { + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final ErrorLogSpec errorLogSpec, + final OptionalLogSpec optionalLogSpec, final String... args) { + // no operation + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final ErrorLogSpec errorLogSpec, + final String... args) { + // no operation + } + + @Override + public void error(final String message, final ErrorLogSpec errorLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void error(final String message, final ErrorLogSpec errorLogSpec, final String... args) { + // no operation + } + + @Override + public void warn(final String message, final ErrorLogSpec errorLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void warn(final String message, final ErrorLogSpec errorLogSpec, final String... args) { + // no operation + } +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpMetricLog.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpMetricLog.java new file mode 100644 index 0000000..1c67862 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/NoOpMetricLog.java @@ -0,0 +1,89 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.noop; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.log.MetricLog; +import org.onap.dcae.utils.eelf.logger.api.spec.MetricLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; + +/** + * A no operation implementation of Metric Log + * + * @author Rajiv Singla + */ +public class NoOpMetricLog implements MetricLog { + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final MetricLogSpec metricLogSpec, + final OptionalLogSpec optionalLogSpec, final String... args) { + // no operation + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final MetricLogSpec metricLogSpec, + final String... args) { + // no operation + } + + @Override + public void info(final String message, final MetricLogSpec metricLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void info(final String message, final MetricLogSpec metricLogSpec, final String... args) { + // no operation + } + + @Override + public void warn(final String message, final MetricLogSpec metricLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void warn(final String message, final MetricLogSpec metricLogSpec, final String... args) { + // no operation + } + + @Override + public void error(final String message, final MetricLogSpec metricLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void error(final String message, final MetricLogSpec metricLogSpec, final String... args) { + // no operation + } + + @Override + public void fatal(final String message, final MetricLogSpec metricLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + // no operation + } + + @Override + public void fatal(final String message, final MetricLogSpec metricLogSpec, final String... args) { + // no operation + } +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/package-info.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/package-info.java new file mode 100644 index 0000000..f7ed917 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/noop/package-info.java @@ -0,0 +1,26 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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========================================================= + * + */ + +/** + * Contains no operation implementation of EELF Logging API. Generally used as a fallback when no EELF Logging + * implementation is detected in the application classpath + * + * @author Rajiv Singla + */ +package org.onap.dcae.utils.eelf.logger.api.noop; diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/AppLogSpec.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/AppLogSpec.java new file mode 100644 index 0000000..83643fb --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/AppLogSpec.java @@ -0,0 +1,32 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.spec; + + +import org.onap.dcae.utils.eelf.logger.api.info.AppLogInfo; + +/** + * App Log spec captures fields which are fixed for the duration of application once its instance is created. They + * should be populated for all specifications regardless of if they are relevant to that specification + * + * @author Rajiv Singla + */ +public interface AppLogSpec extends AppLogInfo { +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/AuditLogSpec.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/AuditLogSpec.java new file mode 100644 index 0000000..46360b1 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/AuditLogSpec.java @@ -0,0 +1,42 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.spec; + + +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.RequestTimingLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ResponseLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ServiceLogInfo; + +/** + * Captures fields required for EELF Audit Log Specification. + * + * @author Rajiv Singla + */ +public interface AuditLogSpec extends + // request id must be preset for all log specifications + RequestIdLogInfo, + // duration related fields + RequestTimingLogInfo, + // app acting as a service fields + ServiceLogInfo, ResponseLogInfo { + + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/DebugLogSpec.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/DebugLogSpec.java new file mode 100644 index 0000000..ac4bd64 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/DebugLogSpec.java @@ -0,0 +1,34 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.spec; + + +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; + +/** + * Captures fields required for EELF Debug Log Specification. + * NOTE: As per specification debug log is optional + * + * @author Rajiv Singla + */ +public interface DebugLogSpec extends + // request id must be preset for all log specifications + RequestIdLogInfo { +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/ErrorLogSpec.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/ErrorLogSpec.java new file mode 100644 index 0000000..455f433 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/ErrorLogSpec.java @@ -0,0 +1,42 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.spec; + + +import org.onap.dcae.utils.eelf.logger.api.info.ErrorLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ServiceLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.TargetServiceLogInfo; + +/** + * Captures fields required for EELF Error Log Specification + * + * @author Rajiv Singla + */ +public interface ErrorLogSpec extends + // request id must be preset for all log specifications + RequestIdLogInfo, + // app acting as a service fields + ServiceLogInfo, + // app calling external service fields + TargetServiceLogInfo, + // error details fields + ErrorLogInfo { +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/MetricLogSpec.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/MetricLogSpec.java new file mode 100644 index 0000000..5b5f698 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/MetricLogSpec.java @@ -0,0 +1,36 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.spec; + + +import org.onap.dcae.utils.eelf.logger.api.info.TargetServiceLogInfo; + +/** + * Captures fields required for EELF Metric Log Specification. + * + * @author Rajiv Singla + */ +public interface MetricLogSpec extends + // Audit log spec + AuditLogSpec, + // App calling external service fields + TargetServiceLogInfo { + +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/OptionalLogSpec.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/OptionalLogSpec.java new file mode 100644 index 0000000..dac08ab --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/OptionalLogSpec.java @@ -0,0 +1,39 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.api.spec; + +import org.onap.dcae.utils.eelf.logger.api.info.CodeLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.CustomFieldsLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.MessageLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.MiscLogInfo; + +/** + * Captures fields which are optional or derived from other fields + * + * @author Rajiv Singla + */ +public interface OptionalLogSpec extends + // message fields are mostly auto generated or can be derived from other fields + MessageLogInfo, + // Code log info can be derived by the underlying logging framework or provided optionally by the app + CodeLogInfo, + // custom and misc log info are mostly optional + CustomFieldsLogInfo, MiscLogInfo { +} diff --git a/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/package-info.java b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/package-info.java new file mode 100644 index 0000000..b4c1df8 --- /dev/null +++ b/eelf-logger/eelf-logger-api/src/main/java/org/onap/dcae/utils/eelf/logger/api/spec/package-info.java @@ -0,0 +1,28 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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========================================================= + * + */ + +/** + * Contains various EELF Logging Specifications. + *

+ * Some specifications are fixed for the whole duration of the + * application, some specification are either optional or derived and some are required for particular EELF Logging + * specification. These logging specification are composed of various logging information in + * {@link org.onap.dcae.utils.eelf.logger.api.info} package + */ +package org.onap.dcae.utils.eelf.logger.api.spec; diff --git a/eelf-logger/eelf-logger-logback-impl/pom.xml b/eelf-logger/eelf-logger-logback-impl/pom.xml new file mode 100644 index 0000000..165d216 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/pom.xml @@ -0,0 +1,62 @@ + + + + + + 4.0.0 + + + org.onap.dcaegen2.utils + eelf-logger + 1.0.0-SNAPSHOT + + + eelf-logger-logback-impl + jar + + + dcaegen2-utils-eelf-logger-logback-impl + Implements EEL Logging Specification using Logback + + + ${project.parent.basedir} + + + + + + + ${project.groupId} + eelf-logger-model + ${project.version} + + + + + ch.qos.logback + logback-classic + + + + + + diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/EELFLoggerDefaults.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/EELFLoggerDefaults.java new file mode 100644 index 0000000..eceaf20 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/EELFLoggerDefaults.java @@ -0,0 +1,105 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogInfo; +import org.onap.dcae.utils.eelf.logger.model.info.AppLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.CustomFieldsLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.ErrorLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.MiscLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.RequestTimingLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.ResponseLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.ServiceLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.TargetServiceLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.OptionalLogSpecImpl; + +import java.util.Date; + +import static org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils.createDefaultAppLogInfo; + + +/** + * This utility class various default implementations for EELF Logger. Users should use these default rather then + * creating their own {@link LogInfo} objects. + * + * @author Rajiv Singla + */ +public class EELFLoggerDefaults { + + private static final String UNKNOWN_FIELD_VALUE = "UNKNOWN"; + + // =============== APP LOG SPEC ======================// + /** + * Provides Default {@link AppLogInfoImpl} + */ + public static final AppLogInfoImpl DEFAULT_APP_LOG_INFO = createDefaultAppLogInfo(); + + + // =============== AUDIT LOG SPEC ===================== // + + private static final String DEFAULT_PARTNER_NAME = + System.getProperty("user.name") != null ? System.getProperty("user.name") : UNKNOWN_FIELD_VALUE; + + public static final ServiceLogInfoImpl DEFAULT_SERVICE_LOG_INFO = + new ServiceLogInfoImpl(UNKNOWN_FIELD_VALUE, DEFAULT_PARTNER_NAME, ""); + + + public static final RequestTimingLogInfoImpl DEFAULT_REQUEST_TIMING_LOG_INFO = + new RequestTimingLogInfoImpl(new Date(), new Date(), null); + + + public static final ResponseLogInfoImpl DEFAULT_RESPONSE_LOG_INFO = + new ResponseLogInfoImpl(900, "UNDEFINED"); + + + // =============== METRIC LOG SPEC ===================== // + + public static final TargetServiceLogInfoImpl DEFAULT_TARGET_SERVICE_LOG_INFO = + new TargetServiceLogInfoImpl(UNKNOWN_FIELD_VALUE, UNKNOWN_FIELD_VALUE, UNKNOWN_FIELD_VALUE); + + // =============== ERROR LOG SPEC ===================== // + + public static final ErrorLogInfoImpl DEFAULT_ERROR_LOG_INFO = + new ErrorLogInfoImpl(900, "UNDEFINED ERROR"); + + + // ============= OPTIONAL LOG SPEC =================== // + + /** + * Provides Default {@link CustomFieldsLogInfoImpl} + */ + public static final CustomFieldsLogInfoImpl DEFAULT_CUSTOM_FIELDS_LOG_INFO = + new CustomFieldsLogInfoImpl("", "", "", ""); + + /** + * Provides Default {@link MiscLogInfoImpl} + */ + public static final MiscLogInfoImpl DEFAULT_MISC_LOG_INFO = new MiscLogInfoImpl("", ""); + + + /** + * Provides Default {@link OptionalLogSpecImpl} + */ + public static final OptionalLogSpecImpl DEFAULT_OPTIONAL_LOG_SPEC = new OptionalLogSpecImpl(null, null, + DEFAULT_CUSTOM_FIELDS_LOG_INFO, DEFAULT_MISC_LOG_INFO); + + +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/filter/MarkerFilter.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/filter/MarkerFilter.java new file mode 100644 index 0000000..a664190 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/filter/MarkerFilter.java @@ -0,0 +1,71 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.filter; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.filter.AbstractMatcherFilter; +import ch.qos.logback.core.spi.FilterReply; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; + +import java.util.HashSet; +import java.util.Set; + +/** + * Logback Marker filter + * + * @author Rajiv Singla + */ +public class MarkerFilter extends AbstractMatcherFilter { + + private String markersString; + private Set markersToAccept = new HashSet<>(); + + @Override + public FilterReply decide(final ILoggingEvent event) { + + if (!isStarted()) { + return FilterReply.NEUTRAL; + } + + if (markersToAccept.contains(event.getMarker())) { + return onMatch; + } else { + return onMismatch; + } + } + + public void setMarkers(String markersString) { + this.markersString = markersString; + } + + + public void start() { + + if (markersString != null && markersString.trim().split(",").length > 0) { + + final String[] markerStrings = markersString.trim().split(","); + for (String markerString : markerStrings) { + markersToAccept.add(MarkerFactory.getMarker(markerString.trim())); + } + super.start(); + } + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/AuditLogLayout.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/AuditLogLayout.java new file mode 100644 index 0000000..5d848ac --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/AuditLogLayout.java @@ -0,0 +1,81 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.layout; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.LayoutBase; +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.spec.AppLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils; + + +/** + * Audit log layout generates log messages as per EELF Audit Log Specifications + * + * @author Rajiv Singla + */ +public class AuditLogLayout extends LayoutBase { + + @Override + public String doLayout(final ILoggingEvent event) { + + final AppLogSpec appLogSpec = LogUtils.getAppLogSpec(); + final LogLevelCategory logLevelCategory = LogUtils.getLogLevelCategory(); + final Class loggerClass = LogUtils.getLoggerClass(); + final OptionalLogSpec optionalLogSpec = LogUtils.getOptionalLogSpec(loggerClass, logLevelCategory); + final AuditLogSpec auditLogSpec = LogUtils.getAuditLogSpec(); + + final String beginTimestamp = LogUtils.formatDate(auditLogSpec.getBeginTimestamp()); + final String endTimestamp = LogUtils.formatDate(auditLogSpec.getEndTimestamp()); + + final String[] auditLogValues = { + beginTimestamp, + endTimestamp, + auditLogSpec.getRequestId(), + appLogSpec.getServiceInstanceID(), + event.getThreadName(), + appLogSpec.getVirtualServerName(), + auditLogSpec.getServiceName(), + auditLogSpec.getPartnerName(), + optionalLogSpec.getStatusCode().name(), + auditLogSpec.getResponseCode().toString(), + auditLogSpec.getResponseDescription(), + appLogSpec.getInstanceUUID(), + logLevelCategory != null ? logLevelCategory.name() : "", + optionalLogSpec.getAlertSeverity().getSeverityCode(), + appLogSpec.getServerIPAddress(), + auditLogSpec.getElapsedTime().toString(), + appLogSpec.getServerFQDN(), + auditLogSpec.getClientIPAddress(), + optionalLogSpec.getClassName(), + optionalLogSpec.getUnused(), + optionalLogSpec.getProcessId(), + optionalLogSpec.getCustomField1(), + optionalLogSpec.getCustomField2(), + optionalLogSpec.getCustomField3(), + optionalLogSpec.getCustomField4(), + event.getFormattedMessage() + }; + + return LogUtils.createLogMessageString(auditLogValues); + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/ConsoleLayout.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/ConsoleLayout.java new file mode 100644 index 0000000..589d863 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/ConsoleLayout.java @@ -0,0 +1,56 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.layout; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.LayoutBase; +import org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils; +import org.slf4j.Marker; + +/** + * Console layout is used to log messages on the console for debugging purposes. + * + * @author Rajiv Singla + */ +public class ConsoleLayout extends LayoutBase { + + private static final MetricLogLayout METRIC_LOG_LAYOUT = new MetricLogLayout(); + private static final AuditLogLayout AUDIT_LOG_LAYOUT = new AuditLogLayout(); + private static final ErrorLogLayout ERROR_LOG_LAYOUT = new ErrorLogLayout(); + private static final DebugLogLayout DEBUG_LOG_LAYOUT = new DebugLogLayout(); + + @Override + public String doLayout(final ILoggingEvent event) { + + final Marker eventMarker = event.getMarker(); + + if (eventMarker.equals(LogUtils.AUDIT_LOG_MARKER)) { + return AUDIT_LOG_LAYOUT.doLayout(event); + } else if (eventMarker.equals(LogUtils.METRIC_LOG_MARKER)) { + return METRIC_LOG_LAYOUT.doLayout(event); + } else if (eventMarker.equals(LogUtils.ERROR_LOG_MARKER)) { + return ERROR_LOG_LAYOUT.doLayout(event); + } else if (eventMarker.equals(LogUtils.DEBUG_LOG_MARKER)) { + return DEBUG_LOG_LAYOUT.doLayout(event); + } + + return "Console Layout not defined for Marker: " + eventMarker; + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/DebugLogLayout.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/DebugLogLayout.java new file mode 100644 index 0000000..e7b1cd4 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/DebugLogLayout.java @@ -0,0 +1,54 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.layout; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.LayoutBase; +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils; + + +/** + * @author Rajiv Singla + */ +public class DebugLogLayout extends LayoutBase { + + @Override + public String doLayout(final ILoggingEvent event) { + + final LogLevelCategory logLevelCategory = LogUtils.getLogLevelCategory(); + final Class loggerClass = LogUtils.getLoggerClass(); + final OptionalLogSpec optionalLogSpec = LogUtils.getOptionalLogSpec(loggerClass, logLevelCategory); + + final DebugLogSpec debugLogSpec = LogUtils.getDebugLogSpec(); + + final String creationTimestamp = LogUtils.formatDate(optionalLogSpec.getCreationTimestamp()); + + final String[] debugLogValues = { + creationTimestamp, + debugLogSpec.getRequestId(), + event.getFormattedMessage() + }; + + return LogUtils.createLogMessageString(debugLogValues); + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/ErrorLogLayout.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/ErrorLogLayout.java new file mode 100644 index 0000000..4eefe36 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/ErrorLogLayout.java @@ -0,0 +1,64 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.layout; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.LayoutBase; +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils; + + +/** + * Error Log Layout generates log messages as per EELF Error Log Specifications + * + * @author Rajiv Singla + */ +public class ErrorLogLayout extends LayoutBase { + + @Override + public String doLayout(final ILoggingEvent event) { + + final LogLevelCategory logLevelCategory = LogUtils.getLogLevelCategory(); + final Class loggerClass = LogUtils.getLoggerClass(); + final OptionalLogSpec optionalLogSpec = LogUtils.getOptionalLogSpec(loggerClass, logLevelCategory); + + final ErrorLogSpec errorLogSpec = LogUtils.getErrorLogSpec(); + + final String creationTimestamp = LogUtils.formatDate(optionalLogSpec.getCreationTimestamp()); + + final String[] errorLogValues = { + creationTimestamp, + errorLogSpec.getRequestId(), + event.getThreadName(), + errorLogSpec.getServiceName(), + errorLogSpec.getPartnerName(), + errorLogSpec.getTargetEntity(), + errorLogSpec.getTargetServiceName(), + logLevelCategory != null ? logLevelCategory.name() : "", + errorLogSpec.getErrorCode() != null ? errorLogSpec.getErrorCode().toString() : "", + errorLogSpec.getErrorDescription(), + event.getFormattedMessage() + }; + + return LogUtils.createLogMessageString(errorLogValues); + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/MetricLogLayout.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/MetricLogLayout.java new file mode 100644 index 0000000..509ff8f --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/layout/MetricLogLayout.java @@ -0,0 +1,83 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.layout; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.LayoutBase; +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.spec.AppLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.MetricLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils; + +/** + * Metric Log Layout generates log messages as per EELF Metric Log Specifications + * + * @author Rajiv Singla + */ +public class MetricLogLayout extends LayoutBase { + + @Override + public String doLayout(final ILoggingEvent event) { + + final AppLogSpec appLogSpec = LogUtils.getAppLogSpec(); + final LogLevelCategory logLevelCategory = LogUtils.getLogLevelCategory(); + final Class loggerClass = LogUtils.getLoggerClass(); + final OptionalLogSpec optionalLogSpec = LogUtils.getOptionalLogSpec(loggerClass, logLevelCategory); + final MetricLogSpec metricLogSpec = LogUtils.getMetricLogSpec(); + + final String beginTimestamp = LogUtils.formatDate(metricLogSpec.getBeginTimestamp()); + final String endTimestamp = LogUtils.formatDate(metricLogSpec.getEndTimestamp()); + + final String[] metricLogValues = { + beginTimestamp, + endTimestamp, + metricLogSpec.getRequestId(), + appLogSpec.getServiceInstanceID(), + event.getThreadName(), + appLogSpec.getVirtualServerName(), + metricLogSpec.getServiceName(), + metricLogSpec.getPartnerName(), + metricLogSpec.getTargetEntity(), + metricLogSpec.getTargetServiceName(), + optionalLogSpec.getStatusCode().name(), + metricLogSpec.getResponseCode().toString(), + metricLogSpec.getResponseDescription(), + appLogSpec.getInstanceUUID(), + logLevelCategory != null ? logLevelCategory.name() : "", + optionalLogSpec.getAlertSeverity().getSeverityCode(), + appLogSpec.getServerIPAddress(), + metricLogSpec.getElapsedTime().toString(), + appLogSpec.getServerFQDN(), + metricLogSpec.getClientIPAddress(), + optionalLogSpec.getClassName(), + optionalLogSpec.getUnused(), + optionalLogSpec.getProcessId(), + metricLogSpec.getTargetVirtualEntity(), + optionalLogSpec.getCustomField1(), + optionalLogSpec.getCustomField2(), + optionalLogSpec.getCustomField3(), + optionalLogSpec.getCustomField4(), + event.getFormattedMessage() + }; + + return LogUtils.createLogMessageString(metricLogValues); + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/listener/LogbackStartupListener.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/listener/LogbackStartupListener.java new file mode 100644 index 0000000..b02c471 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/listener/LogbackStartupListener.java @@ -0,0 +1,128 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.listener; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.classic.spi.LoggerContextListener; +import ch.qos.logback.core.Context; +import ch.qos.logback.core.spi.ContextAwareBase; +import ch.qos.logback.core.spi.LifeCycle; +import ch.qos.logback.core.status.InfoStatus; +import ch.qos.logback.core.status.WarnStatus; +import org.onap.dcae.utils.eelf.logger.api.info.AppLogInfo; +import org.onap.dcae.utils.eelf.logger.model.spec.AppLogSpecImpl; + + +import java.io.File; + +import static org.onap.dcae.utils.eelf.logger.logback.EELFLoggerDefaults.DEFAULT_APP_LOG_INFO; +import static org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils.APP_LOG_SPEC_KEY; +import static org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils.CUSTOM_MDC_MAP; + + +/** + * Logback Startup Listener is used to inject {@link AppLogInfo} + * + * @author Rajiv Singla + */ +public class LogbackStartupListener extends ContextAwareBase implements LoggerContextListener, LifeCycle { + + private static final String APP_LOG_INFO_KEY_IN_CONTEXT = "APP_LOG_INFO"; + private static final String CONTEXT_COMPONENT_NAME_PROPERTY_KEY = "componentName"; + private static final String CONTEXT_MODIFY_WINDOWS_LOG_PATH_PROPERTY_KEY = "modifyLogPathInWindows"; + private static final String CONTEXT_LOG_DIRECTORY_PROPERTY_KEY = "logDirectory"; + private static final String CONTEXT_DEBUG_LOG_DIRECTORY_PROPERTY_KEY = "debugLogDirectory"; + private static final String CONTEXT_APPEND_DIRECTORY_PROPERTY_KEY = "appendDirectory"; + + private boolean started = false; + + @Override + public boolean isResetResistant() { + return true; + } + + @Override + public void onStart(final LoggerContext context) { + + } + + @Override + public void onReset(final LoggerContext context) { + + } + + @Override + public void onStop(final LoggerContext context) { + + } + + @Override + public void onLevelChange(final Logger logger, final Level level) { + + } + + @Override + public void start() { + if (started) { + return; + } + + Context context = getContext(); + + CUSTOM_MDC_MAP.put(APP_LOG_SPEC_KEY, new AppLogSpecImpl(DEFAULT_APP_LOG_INFO)); + context.putObject(APP_LOG_INFO_KEY_IN_CONTEXT, DEFAULT_APP_LOG_INFO); + context.getStatusManager().add(new InfoStatus("Initialized APP LOG INFO", DEFAULT_APP_LOG_INFO)); + + // if Component name is not set derive from jar file name + if (context.getProperty(CONTEXT_COMPONENT_NAME_PROPERTY_KEY) == null) { + final String appName = + new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getName(); + context.putProperty(CONTEXT_COMPONENT_NAME_PROPERTY_KEY, appName); + context.getStatusManager().add(new WarnStatus( + "No componentName Property found. Deriving it from jar name", appName)); + } + + // if modify windows log path is enabled - then append target before log directories + if (context.getProperty(CONTEXT_MODIFY_WINDOWS_LOG_PATH_PROPERTY_KEY).equalsIgnoreCase("true")) { + final String os = System.getProperty("os.name"); + if (os != null && os.startsWith("Windows")) { + final String logDirectory = context.getProperty(CONTEXT_LOG_DIRECTORY_PROPERTY_KEY); + final String debugLogDirectory = context.getProperty(CONTEXT_DEBUG_LOG_DIRECTORY_PROPERTY_KEY); + final String appendDir = context.getProperty(CONTEXT_APPEND_DIRECTORY_PROPERTY_KEY); + context.putProperty(CONTEXT_LOG_DIRECTORY_PROPERTY_KEY, appendDir + "/" + logDirectory); + context.putProperty(CONTEXT_DEBUG_LOG_DIRECTORY_PROPERTY_KEY, appendDir + "/" + debugLogDirectory); + } + } + + started = true; + } + + @Override + public void stop() { + + } + + @Override + public boolean isStarted() { + return started; + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/AuditLogImpl.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/AuditLogImpl.java new file mode 100644 index 0000000..947b4c2 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/AuditLogImpl.java @@ -0,0 +1,119 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.log; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.log.AuditLog; +import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils; +import org.slf4j.Logger; + + +/** + * Audit Log Logback Implementation + * + * @author Rajiv Singla + */ +public class AuditLogImpl implements AuditLog { + + private final Logger logger; + private final Class clazz; + + public AuditLogImpl(final Logger logger, final Class clazz) { + this.logger = logger; + this.clazz = clazz; + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final AuditLogSpec + auditLogSpec, final OptionalLogSpec optionalLogSpec, final String... args) { + // if audit log spec or log level category is null throw an exception + if (auditLogSpec == null || logLevelCategory == null) { + throw new IllegalArgumentException("Audit Log Spec and Log level category must not be null"); + } + // required fields + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.LOG_LEVEL_CATEGORY_KEY, logLevelCategory); + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.AUDIT_LOG_SPEC_KEY, auditLogSpec); + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.LOGGER_CLASS_KEY, clazz); + // optional fields + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.OPTIONAL_LOG_SPEC_KEY, optionalLogSpec); + + // log with normalized log level category + LogUtils.logWithLogLevel(logLevelCategory, logger, LogUtils.AUDIT_LOG_MARKER, message, args); + + // clean up + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.LOG_LEVEL_CATEGORY_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.AUDIT_LOG_SPEC_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.LOGGER_CLASS_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.OPTIONAL_LOG_SPEC_KEY); + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final AuditLogSpec auditLogSpec, + final String... args) { + log(logLevelCategory, message, auditLogSpec, null, args); + } + + @Override + public void info(final String message, final AuditLogSpec auditLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.INFO, message, auditLogSpec, optionalLogSpec, args); + } + + @Override + public void info(final String message, final AuditLogSpec auditLogSpec, final String... args) { + info(message, auditLogSpec, null, args); + } + + @Override + public void warn(final String message, final AuditLogSpec auditLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.WARN, message, auditLogSpec, optionalLogSpec, args); + } + + @Override + public void warn(final String message, final AuditLogSpec auditLogSpec, final String... args) { + warn(message, auditLogSpec, null, args); + } + + @Override + public void error(final String message, final AuditLogSpec auditLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.ERROR, message, auditLogSpec, optionalLogSpec, args); + } + + @Override + public void error(final String message, final AuditLogSpec auditLogSpec, final String... args) { + error(message, auditLogSpec, null, args); + } + + @Override + public void fatal(final String message, final AuditLogSpec auditLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.FATAL, message, auditLogSpec, optionalLogSpec, args); + } + + @Override + public void fatal(final String message, final AuditLogSpec auditLogSpec, final String... args) { + fatal(message, auditLogSpec, null, args); + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/DebugLogImpl.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/DebugLogImpl.java new file mode 100644 index 0000000..1e17f3b --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/DebugLogImpl.java @@ -0,0 +1,88 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.log; + + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.log.DebugLog; +import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils; +import org.slf4j.Logger; + + +/** + * Debug Log Logback Implementation + * + * @author Rajiv Singla + */ +public class DebugLogImpl implements DebugLog { + + private final Logger logger; + private final Class clazz; + + public DebugLogImpl(final Logger logger, final Class clazz) { + this.logger = logger; + this.clazz = clazz; + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final DebugLogSpec debugLogSpec, + final OptionalLogSpec optionalLogSpec, final String... args) { + + // if log level category is null throw an exception + if (logLevelCategory == null) { + throw new IllegalArgumentException("Log level category must not be null"); + } + + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.LOG_LEVEL_CATEGORY_KEY, logLevelCategory); + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.DEBUG_LOG_SPEC_KEY, debugLogSpec); + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.LOGGER_CLASS_KEY, clazz); + // optional fields + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.OPTIONAL_LOG_SPEC_KEY, optionalLogSpec); + + // log with normalized log level category + LogUtils.logWithLogLevel(logLevelCategory, logger, LogUtils.DEBUG_LOG_MARKER, message, args); + + // clean up + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.LOG_LEVEL_CATEGORY_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.DEBUG_LOG_SPEC_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.LOGGER_CLASS_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.OPTIONAL_LOG_SPEC_KEY); + + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final DebugLogSpec debugLogSpec, + final String... args) { + log(logLevelCategory, message, debugLogSpec, null, args); + } + + @Override + public void debug(final String message, final DebugLogSpec debugLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.DEBUG, message, debugLogSpec, optionalLogSpec, args); + } + + @Override + public void debug(final String message, final DebugLogSpec debugLogSpec, final String... args) { + debug(message, debugLogSpec, null, args); + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/EELFLoggerContextImpl.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/EELFLoggerContextImpl.java new file mode 100644 index 0000000..e5be1d8 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/EELFLoggerContextImpl.java @@ -0,0 +1,57 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.log; + +import org.onap.dcae.utils.eelf.logger.api.log.EELFLoggerContext; +import org.onap.dcae.utils.eelf.logger.api.spec.AppLogSpec; +import org.onap.dcae.utils.eelf.logger.model.spec.AppLogSpecImpl; + +import static org.onap.dcae.utils.eelf.logger.logback.EELFLoggerDefaults.DEFAULT_APP_LOG_INFO; +import static org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils.APP_LOG_SPEC_KEY; +import static org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils.CUSTOM_MDC_MAP; + + +/** + * Default EELF Logger Context which contains EELF Specs which are usually constant for entire life cycle of the + * application + * + * @author Rajiv Singla + */ +public class EELFLoggerContextImpl implements EELFLoggerContext { + + @Override + public AppLogSpec getAppLogSpec() { + return CUSTOM_MDC_MAP.get(APP_LOG_SPEC_KEY) == null ? null : (AppLogSpec) CUSTOM_MDC_MAP.get(APP_LOG_SPEC_KEY); + } + + @Override + public void setAppLogSpec(final AppLogSpec appLogSpec) { + if (appLogSpec == null) { + CUSTOM_MDC_MAP.put(APP_LOG_SPEC_KEY, new AppLogSpecImpl(DEFAULT_APP_LOG_INFO)); + } else { + CUSTOM_MDC_MAP.put(APP_LOG_SPEC_KEY, appLogSpec); + } + } + + @Override + public boolean isInitialized() { + return CUSTOM_MDC_MAP.get(APP_LOG_SPEC_KEY) == null; + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/EELFLoggerImpl.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/EELFLoggerImpl.java new file mode 100644 index 0000000..3f1e716 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/EELFLoggerImpl.java @@ -0,0 +1,81 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.log; + + +import org.onap.dcae.utils.eelf.logger.api.log.AuditLog; +import org.onap.dcae.utils.eelf.logger.api.log.DebugLog; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLoggerContext; +import org.onap.dcae.utils.eelf.logger.api.log.ErrorLog; +import org.onap.dcae.utils.eelf.logger.api.log.MetricLog; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * EELF Logger Logback Implementation + * + * @author Rajiv Singla + */ +public class EELFLoggerImpl implements EELFLogger { + + private Logger logger; + private Class clazz; + + public EELFLoggerImpl() { + // no arg constructor required for Service Loader discovery + } + + public EELFLoggerImpl(final Class clazz) { + logger = LoggerFactory.getLogger(clazz); + this.clazz = clazz; + } + + + @Override + public AuditLog auditLog() { + return new AuditLogImpl(logger, clazz); + } + + @Override + public MetricLog metricLog() { + return new MetricLogImpl(logger, clazz); + } + + @Override + public ErrorLog errorLog() { + return new ErrorLogImpl(logger, clazz); + } + + @Override + public DebugLog debugLog() { + return new DebugLogImpl(logger, clazz); + } + + @Override + public EELFLoggerContext loggingContext() { + return new EELFLoggerContextImpl(); + } + + @Override + public String toString() { + return "EELF LOGBACK IMP"; + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/ErrorLogImpl.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/ErrorLogImpl.java new file mode 100644 index 0000000..5d8f272 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/ErrorLogImpl.java @@ -0,0 +1,98 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.log; + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.log.ErrorLog; +import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils; +import org.slf4j.Logger; + + +/** + * Error Log Logback Implementation + * + * @author Rajiv Singla + */ +public class ErrorLogImpl implements ErrorLog { + + private final Logger logger; + private final Class clazz; + + public ErrorLogImpl(final Logger logger, final Class clazz) { + this.logger = logger; + this.clazz = clazz; + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final ErrorLogSpec errorLogSpec, + final OptionalLogSpec optionalLogSpec, final String... args) { + + // if error log spec or log level category is null throw an exception + if (errorLogSpec == null || logLevelCategory == null) { + throw new IllegalArgumentException("Error Log Spec and Log level category must not be null"); + } + + // required fields + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.LOG_LEVEL_CATEGORY_KEY, logLevelCategory); + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.ERROR_LOG_SPEC_KEY, errorLogSpec); + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.LOGGER_CLASS_KEY, clazz); + // optional fields + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.OPTIONAL_LOG_SPEC_KEY, optionalLogSpec); + + // log with normalized log level category + LogUtils.logWithLogLevel(logLevelCategory, logger, LogUtils.ERROR_LOG_MARKER, message, args); + + // clean up + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.LOG_LEVEL_CATEGORY_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.ERROR_LOG_SPEC_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.LOGGER_CLASS_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.OPTIONAL_LOG_SPEC_KEY); + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final ErrorLogSpec errorLogSpec, + final String... args) { + log(logLevelCategory, message, errorLogSpec, null, args); + } + + @Override + public void error(final String message, final ErrorLogSpec errorLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.ERROR, message, errorLogSpec, null, args); + } + + @Override + public void error(final String message, final ErrorLogSpec errorLogSpec, final String... args) { + error(message, errorLogSpec, null, args); + } + + @Override + public void warn(final String message, final ErrorLogSpec errorLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.WARN, message, errorLogSpec, null, args); + } + + @Override + public void warn(final String message, final ErrorLogSpec errorLogSpec, final String... args) { + warn(message, errorLogSpec, null, args); + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/MetricLogImpl.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/MetricLogImpl.java new file mode 100644 index 0000000..5857835 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/log/MetricLogImpl.java @@ -0,0 +1,120 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.log; + +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.log.MetricLog; +import org.onap.dcae.utils.eelf.logger.api.spec.MetricLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils; +import org.slf4j.Logger; + +/** + * Metric Log Logback Implementation + * + * @author Rajiv Singla + */ +public class MetricLogImpl implements MetricLog { + + private final Logger logger; + private final Class clazz; + + public MetricLogImpl(final Logger logger, final Class clazz) { + this.logger = logger; + this.clazz = clazz; + } + + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final MetricLogSpec metricLogSpec, + final OptionalLogSpec optionalLogSpec, final String... args) { + + // if metric log spec or log level category is null throw an exception + if (metricLogSpec == null || logLevelCategory == null) { + throw new IllegalArgumentException("Metric Log Spec and Log level category must not be null"); + } + + // required fields + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.LOG_LEVEL_CATEGORY_KEY, logLevelCategory); + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.METRIC_LOG_SPEC_KEY, metricLogSpec); + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.LOGGER_CLASS_KEY, clazz); + // optional fields + LogUtils.CUSTOM_MDC_MAP.put(LogUtils.OPTIONAL_LOG_SPEC_KEY, optionalLogSpec); + + // log with normalized log level category + LogUtils.logWithLogLevel(logLevelCategory, logger, LogUtils.METRIC_LOG_MARKER, message, args); + + // clean up + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.LOG_LEVEL_CATEGORY_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.METRIC_LOG_SPEC_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.LOGGER_CLASS_KEY); + LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.OPTIONAL_LOG_SPEC_KEY); + } + + @Override + public void log(final LogLevelCategory logLevelCategory, final String message, final MetricLogSpec metricLogSpec, + final String... args) { + log(logLevelCategory, message, metricLogSpec, null, args); + } + + @Override + public void info(final String message, final MetricLogSpec metricLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.INFO, message, metricLogSpec, optionalLogSpec, args); + } + + @Override + public void info(final String message, final MetricLogSpec metricLogSpec, final String... args) { + log(LogLevelCategory.INFO, message, metricLogSpec, args); + } + + @Override + public void warn(final String message, final MetricLogSpec metricLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.WARN, message, metricLogSpec, optionalLogSpec, args); + } + + @Override + public void warn(final String message, final MetricLogSpec metricLogSpec, final String... args) { + warn(message, metricLogSpec, null, args); + } + + @Override + public void error(final String message, final MetricLogSpec metricLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.ERROR, message, metricLogSpec, optionalLogSpec, args); + } + + @Override + public void error(final String message, final MetricLogSpec metricLogSpec, final String... args) { + error(message, metricLogSpec, null, args); + } + + @Override + public void fatal(final String message, final MetricLogSpec metricLogSpec, final OptionalLogSpec optionalLogSpec, + final String... args) { + log(LogLevelCategory.FATAL, message, metricLogSpec, optionalLogSpec, args); + } + + @Override + public void fatal(final String message, final MetricLogSpec metricLogSpec, final String... args) { + fatal(message, metricLogSpec, null, args); + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/CompositePropertyResolver.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/CompositePropertyResolver.java new file mode 100644 index 0000000..e5f1bc1 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/CompositePropertyResolver.java @@ -0,0 +1,53 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.resolver; + +import java.util.Arrays; +import java.util.List; + +/** + * A composite property resolver can look under different resolvers in order of given property resolvers + * + * @author Rajiv Singla + */ +public class CompositePropertyResolver implements PropertyResolver { + + private static final long serialVersionUID = 1L; + + private final List propertyResolvers; + + public CompositePropertyResolver(PropertyResolver... propertyResolvers) { + this.propertyResolvers = Arrays.asList(propertyResolvers); + } + + @Override + public String resolve(final List propertyNames) { + // resolver property in given resolvers in the same order they are defined + for (PropertyResolver propertyResolver : propertyResolvers) { + final String propertyValue = propertyResolver.resolve(propertyNames); + if (propertyValue != null) { + return propertyValue; + } + } + + return null; + } + +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/EnvironmentPropertyResolver.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/EnvironmentPropertyResolver.java new file mode 100644 index 0000000..8f3d59f --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/EnvironmentPropertyResolver.java @@ -0,0 +1,46 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.resolver; + +import java.util.List; + +/** + * Looks up Property values inside HOST environment variables + * + * @author Rajiv Singla + */ +public class EnvironmentPropertyResolver implements PropertyResolver { + + private static final long serialVersionUID = 1L; + + @Override + public String resolve(final List propertyNames) { + + // check if system environment variables have property names set + for (final String propertyName : propertyNames) { + final String propertyValue = System.getenv(propertyName); + if (propertyValue != null) { + return propertyValue; + } + } + + return null; + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/PropertyResolver.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/PropertyResolver.java new file mode 100644 index 0000000..758de61 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/PropertyResolver.java @@ -0,0 +1,41 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.resolver; + +import java.io.Serializable; +import java.util.List; + +/** + * A resolver is used to resolve properties + * + * @author Rajiv Singla + */ +public interface PropertyResolver extends Serializable { + + /** + * Returns resolved property value + * + * @param propertyNames names under which property can be found + * + * @return property value + */ + String resolve(List propertyNames); + +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/SystemPropertyResolver.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/SystemPropertyResolver.java new file mode 100644 index 0000000..674b00b --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/resolver/SystemPropertyResolver.java @@ -0,0 +1,59 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.resolver; + +import java.util.List; +import java.util.Map; +import java.util.Properties; + +/** + * Resolve System Properties passed in by -DpropertyName=propertyValue when invoking + * via java command line arguments + * + * @author Rajiv Singla + */ +public class SystemPropertyResolver implements PropertyResolver { + + private static final long serialVersionUID = 1L; + + @Override + public String resolve(final List propertyNames) { + + // Get all system Properties + final Properties systemProperties = System.getProperties(); + + for (Map.Entry systemEntries : systemProperties.entrySet()) { + + if (systemEntries.getKey() instanceof String) { + final String systemKey = (String) systemEntries.getKey(); + + // if system properties contain any of the property names - ignoring case then return its value + for (String propertyName : propertyNames) { + if (propertyName.equalsIgnoreCase(systemKey)) { + return (String) systemEntries.getValue(); + } + } + + } + } + + return null; + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/utils/LogUtils.java b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/utils/LogUtils.java new file mode 100644 index 0000000..f5c558b --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/java/org/onap/dcae/utils/eelf/logger/logback/utils/LogUtils.java @@ -0,0 +1,590 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.utils; + +import ch.qos.logback.core.CoreConstants; +import org.onap.dcae.utils.eelf.logger.api.info.AppLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory; +import org.onap.dcae.utils.eelf.logger.api.info.NagiosAlertLevel; +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.RequestStatusCode; +import org.onap.dcae.utils.eelf.logger.api.spec.AppLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.MetricLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.EELFLoggerDefaults; +import org.onap.dcae.utils.eelf.logger.logback.resolver.CompositePropertyResolver; +import org.onap.dcae.utils.eelf.logger.logback.resolver.EnvironmentPropertyResolver; +import org.onap.dcae.utils.eelf.logger.logback.resolver.SystemPropertyResolver; +import org.onap.dcae.utils.eelf.logger.model.info.AppLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.CodeLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.MessageLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.RequestIdLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.RequestTimingLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.AppLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.AuditLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.DebugLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.ErrorLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.MetricLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.OptionalLogSpecImpl; +import org.slf4j.Logger; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TimeZone; +import java.util.UUID; + + + +/** + * Contains various logging utility methods + * + * @author Rajiv Singla + */ +public abstract class LogUtils { + + private static final String LOG_MESSAGE_DELIMITER = "|"; + private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; + private static final String DATE_TIMEZONE = "UTC"; + // property resolver which looks up system property and the environment properties + private static final CompositePropertyResolver COMPOSITE_PROPERTY_RESOLVER = + new CompositePropertyResolver(new SystemPropertyResolver(), new EnvironmentPropertyResolver()); + + // Custom MDC Map Keys + public static final String APP_LOG_SPEC_KEY = "APP_LOG_SPEC"; + public static final String AUDIT_LOG_SPEC_KEY = "AUDIT_LOG_SPEC"; + public static final String METRIC_LOG_SPEC_KEY = "METRIC_LOG_SPEC"; + public static final String ERROR_LOG_SPEC_KEY = "ERROR_LOG_SPEC"; + public static final String DEBUG_LOG_SPEC_KEY = "DEBUG_LOG_SPEC"; + public static final String OPTIONAL_LOG_SPEC_KEY = "OPTIONAL_LOG_SPEC"; + public static final String LOG_LEVEL_CATEGORY_KEY = "LOG_LEVEL_CATEGORY"; + public static final String LOGGER_CLASS_KEY = "LOGGER_CLASS_KEY"; + + // markers + public static final Marker AUDIT_LOG_MARKER = MarkerFactory.getMarker("AUDIT_LOG"); + public static final Marker METRIC_LOG_MARKER = MarkerFactory.getMarker("METRIC_LOG"); + public static final Marker ERROR_LOG_MARKER = MarkerFactory.getMarker("ERROR_LOG"); + public static final Marker DEBUG_LOG_MARKER = MarkerFactory.getMarker("DEBUG_LOG"); + + + public static final Map CUSTOM_MDC_MAP = new ThreadLocal>() { + @Override + protected Map initialValue() { + return new HashMap<>(); + } + }.get(); + + public static final ThreadLocal SIMPLE_DATE_FORMAT = new ThreadLocal() { + @Override + protected SimpleDateFormat initialValue() { + final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT); + simpleDateFormat.setTimeZone(TimeZone.getTimeZone(DATE_TIMEZONE)); + return simpleDateFormat; + } + }; + + + private LogUtils() { + // private constructor + } + + + /** + * Logs eomp message with normalized log level category + * + * @param logLevelCategory ecomp log level category + * @param logger logback logger + * @param marker logback marker + * @param message log message + * @param args log message arguments for interpolation + */ + public static void logWithLogLevel(final LogLevelCategory logLevelCategory, + final Logger logger, final Marker marker, + final String message, final String... args) { + switch (logLevelCategory) { + case DEBUG: + logger.debug(marker, message, args); + break; + case INFO: + logger.info(marker, message, args); + break; + case WARN: + logger.warn(marker, message, args); + break; + default: + // fatal log level is treated as error also as logback does not have fatal level + logger.error(marker, message, args); + } + } + + + /** + * Returns value for {@link AppLogSpec}. If no {@link AppLogSpec} is defined a default app log spec is passed + * + * @return app log spec + */ + public static AppLogSpec getAppLogSpec() { + final AppLogSpec appLogSpec = getCustomMapValue(APP_LOG_SPEC_KEY, AppLogSpec.class); + return appLogSpec == null ? new AppLogSpecImpl(EELFLoggerDefaults.DEFAULT_APP_LOG_INFO) : appLogSpec; + } + + /** + * Populate default values of {@link OptionalLogSpec} if not present + * + * @param loggerClass logger class + * @param logLevelCategory log level category + * + * @return optional log spec with default values if not present + */ + public static OptionalLogSpec getOptionalLogSpec(final Class loggerClass, final LogLevelCategory + logLevelCategory) { + + OptionalLogSpecImpl optionalLogSpec = + getCustomMapValue(OPTIONAL_LOG_SPEC_KEY, OptionalLogSpecImpl.class); + + if (optionalLogSpec != null) { + // if message log info is empty populate default values + if (optionalLogSpec.getMessageLogInfo() == null || + optionalLogSpec.getCreationTimestamp() == null && optionalLogSpec.getAlertSeverity() == null && + optionalLogSpec.getStatusCode() == null) { + optionalLogSpec = optionalLogSpec.withMessageLogInfo(createDefaultMessageLogInfo(logLevelCategory)); + } + // if code log info is empty populate default values + if (optionalLogSpec.getCodeLogInfo() == null || + optionalLogSpec.getClassName() == null && optionalLogSpec.getThreadId() == null) { + optionalLogSpec = optionalLogSpec.withCodeLogInfo(createDefaultCodeLogInfo(loggerClass)); + } + // if custom fields log info is empty populate default values + if (optionalLogSpec.getCustomFieldsLogInfo() == null) { + optionalLogSpec = + optionalLogSpec.withCustomFieldsLogInfo(EELFLoggerDefaults.DEFAULT_CUSTOM_FIELDS_LOG_INFO); + } + // if misc fields log info is empty populate default values + if (optionalLogSpec.getMiscLogInfo() == null) { + optionalLogSpec = optionalLogSpec.withMiscLogInfo(EELFLoggerDefaults.DEFAULT_MISC_LOG_INFO); + } + } else { + // optional log spec is null so create new optional log spec + optionalLogSpec = createDefaultOptionalLogSpec(loggerClass, logLevelCategory); + } + + return optionalLogSpec; + } + + + /** + * Formats given date in ISO 8601 format + * + * @param date Date object + * + * @return formatted date string + */ + public static String formatDate(final Date date) { + if (date == null) { + return ""; + } + return SIMPLE_DATE_FORMAT.get().format(date); + } + + /** + * Creates log message string + * + * @param logValues log message values + * + * @return log message string + */ + public static String createLogMessageString(final String[] logValues) { + final StringBuffer stringBuffer = new StringBuffer(512); + for (int i = 0; i < logValues.length; i++) { + final String logValue = logValues[i]; + stringBuffer.append(logValue != null ? logValue : ""); + if (i != logValues.length - 1) { + stringBuffer.append(LOG_MESSAGE_DELIMITER); + } + } + stringBuffer.append(CoreConstants.LINE_SEPARATOR); + return stringBuffer.toString(); + } + + /** + * Gets custom MDC value from Custom MDC Map for give key. Returns null if no value can be found + * + * @param key MDC Map key + * @param clazz expected value class type + * @param class type + * + * @return value inside Custom MDC Map + */ + private static T getCustomMapValue(final String key, final Class clazz) { + final Object value = CUSTOM_MDC_MAP.get(key); + if (value != null) { + return clazz.cast(value); + } + return null; + } + + + /** + * Get current Metric log spec from the custom MDC map and populates default values if not present + * + * @return Metric log spec + */ + public static MetricLogSpec getMetricLogSpec() { + MetricLogSpecImpl metricLogSpec = getCustomMapValue(METRIC_LOG_SPEC_KEY, MetricLogSpecImpl.class); + + if (metricLogSpec != null) { + if (metricLogSpec.getRequestIdLogInfo() == null || metricLogSpec.getRequestId() == null) { + metricLogSpec = metricLogSpec.withRequestIdLogInfo(createNewRequestIdLogInfo()); + } + if (metricLogSpec.getServiceLogInfo() == null) { + metricLogSpec = metricLogSpec.withServiceLogInfo(EELFLoggerDefaults.DEFAULT_SERVICE_LOG_INFO); + } + if (metricLogSpec.getRequestTimingLogInfo() == null || metricLogSpec.getBeginTimestamp() == null || + metricLogSpec.getEndTimestamp() == null) { + metricLogSpec = + metricLogSpec.withRequestTimingLogInfo(EELFLoggerDefaults.DEFAULT_REQUEST_TIMING_LOG_INFO); + } + if (metricLogSpec.getResponseLogInfo() == null) { + metricLogSpec = metricLogSpec.withResponseLogInfo(EELFLoggerDefaults.DEFAULT_RESPONSE_LOG_INFO); + } + final Date beginTimestamp = metricLogSpec.getBeginTimestamp(); + final Date endTimestamp = metricLogSpec.getEndTimestamp(); + final Long elapsedTime = metricLogSpec.getElapsedTime(); + if (endTimestamp != null && beginTimestamp != null && elapsedTime == null) { + final RequestTimingLogInfoImpl requestTimingLogInfo = + new RequestTimingLogInfoImpl(beginTimestamp, endTimestamp, + endTimestamp.getTime() - beginTimestamp.getTime()); + metricLogSpec = metricLogSpec.withRequestTimingLogInfo(requestTimingLogInfo); + } + if (metricLogSpec.getTargetServiceLogInfo() == null) { + metricLogSpec = + metricLogSpec.withTargetServiceLogInfo(EELFLoggerDefaults.DEFAULT_TARGET_SERVICE_LOG_INFO); + } + } else { + throw new IllegalArgumentException("Metric Log Spec must not be null"); + } + + return metricLogSpec; + } + + /** + * Get current Debug log spec from the custom MDC map and populates default values if not present + * + * @return Debug log spec + */ + public static DebugLogSpec getDebugLogSpec() { + final DebugLogSpecImpl debugLogSpec = getCustomMapValue(DEBUG_LOG_SPEC_KEY, DebugLogSpecImpl.class); + if (debugLogSpec == null || debugLogSpec.getRequestIdLogInfo() == null || debugLogSpec.getRequestId() == null) { + return new DebugLogSpecImpl(createNewRequestIdLogInfo()); + } + return debugLogSpec; + } + + /** + * Get current Error log spec from the custom MDC map and populates default values if not present + * + * @return Error log spec + */ + public static ErrorLogSpec getErrorLogSpec() { + ErrorLogSpecImpl errorLogSpec = getCustomMapValue(ERROR_LOG_SPEC_KEY, ErrorLogSpecImpl.class); + if (errorLogSpec != null) { + + if (errorLogSpec.getRequestIdLogInfo() == null || errorLogSpec.getRequestId() == null) { + errorLogSpec = errorLogSpec.withRequestIdLogInfo(createNewRequestIdLogInfo()); + } + if (errorLogSpec.getServiceLogInfo() == null) { + errorLogSpec = errorLogSpec.withServiceLogInfo(EELFLoggerDefaults.DEFAULT_SERVICE_LOG_INFO); + } + if (errorLogSpec.getTargetServiceLogInfo() == null) { + errorLogSpec = + errorLogSpec.withTargetServiceLogInfo(EELFLoggerDefaults.DEFAULT_TARGET_SERVICE_LOG_INFO); + } + if (errorLogSpec.getErrorLogInfo() == null) { + errorLogSpec = errorLogSpec.withErrorLogInfo(EELFLoggerDefaults.DEFAULT_ERROR_LOG_INFO); + } + + } else { + throw new IllegalArgumentException("Error Log Spec cannot be null"); + } + return errorLogSpec; + } + + + /** + * Get current Audit log spec from the custom MDC map and populates default values if not present + * + * @return Audit log spec + */ + public static AuditLogSpec getAuditLogSpec() { + AuditLogSpecImpl auditLogSpec = getCustomMapValue(AUDIT_LOG_SPEC_KEY, AuditLogSpecImpl.class); + if (auditLogSpec != null) { + if (auditLogSpec.getServiceLogInfo() == null) { + auditLogSpec = auditLogSpec.withServiceLogInfo(EELFLoggerDefaults.DEFAULT_SERVICE_LOG_INFO); + } + if (auditLogSpec.getRequestIdLogInfo() == null || auditLogSpec.getRequestId() == null) { + auditLogSpec = auditLogSpec.withRequestIdLogInfo(createNewRequestIdLogInfo()); + } + if (auditLogSpec.getResponseLogInfo() == null) { + auditLogSpec = auditLogSpec.withResponseLogInfo(EELFLoggerDefaults.DEFAULT_RESPONSE_LOG_INFO); + } + + if (auditLogSpec.getRequestTimingLogInfo() == null || auditLogSpec.getBeginTimestamp() == null || + auditLogSpec.getEndTimestamp() == null) { + auditLogSpec = + auditLogSpec.withRequestTimingLogInfo(EELFLoggerDefaults.DEFAULT_REQUEST_TIMING_LOG_INFO); + } + final Date beginTimestamp = auditLogSpec.getBeginTimestamp(); + final Date endTimestamp = auditLogSpec.getEndTimestamp(); + final Long elapsedTime = auditLogSpec.getElapsedTime(); + if (endTimestamp != null && beginTimestamp != null && elapsedTime == null) { + final RequestTimingLogInfoImpl requestTimingLogInfo = + new RequestTimingLogInfoImpl(beginTimestamp, endTimestamp, + endTimestamp.getTime() - beginTimestamp.getTime()); + auditLogSpec = auditLogSpec.withRequestTimingLogInfo(requestTimingLogInfo); + } + + } else { + throw new IllegalArgumentException("Audit Log Spec cannot be null"); + } + + return auditLogSpec; + } + + + private static RequestIdLogInfo createNewRequestIdLogInfo() { + return new RequestIdLogInfoImpl(UUID.randomUUID().toString()); + } + + /** + * Return Log Level Category from MDC Map + * + * @return log level category + */ + public static Class getLoggerClass() { + final Class loggerClass = getCustomMapValue(LOGGER_CLASS_KEY, Class.class); + // logger class must always be non null + if (loggerClass != null) { + return loggerClass; + } + return LogUtils.class.getClass(); + } + + + /** + * Return Log Level Category from MDC Map + * + * @return log level category + */ + public static LogLevelCategory getLogLevelCategory() { + final LogLevelCategory logLevelCategory = getCustomMapValue(LOG_LEVEL_CATEGORY_KEY, LogLevelCategory.class); + if (logLevelCategory != null) { + return logLevelCategory; + } + return LogLevelCategory.ERROR; + } + + /** + * Creates Default Optional Log spec + * + * @param loggerClass logger class name + * @param logLevelCategory Log leve category + * + * @return default optional log spec + */ + private static OptionalLogSpecImpl createDefaultOptionalLogSpec(final Class loggerClass, + final LogLevelCategory logLevelCategory) { + return new OptionalLogSpecImpl(createDefaultMessageLogInfo(logLevelCategory), + createDefaultCodeLogInfo(loggerClass), EELFLoggerDefaults.DEFAULT_CUSTOM_FIELDS_LOG_INFO, + EELFLoggerDefaults.DEFAULT_MISC_LOG_INFO); + } + + + /** + * Creates Default Code Log Info + * + * @param loggerClass logger class name + * + * @return default code log info + */ + private static CodeLogInfoImpl createDefaultCodeLogInfo(final Class loggerClass) { + // thread id can be extracted from the framework + return new CodeLogInfoImpl(null, loggerClass != null ? loggerClass.getName() : ""); + } + + + /** + * Creates Default Message Log Info + * + * @param logLevelCategory Log leve category + * + * @return default message log info + */ + private static MessageLogInfoImpl createDefaultMessageLogInfo(final LogLevelCategory logLevelCategory) { + return new MessageLogInfoImpl(new Date(), + getStatusCode(logLevelCategory), + getNagiosAlertLevel(logLevelCategory)); + } + + + /** + * Creates Default App Log Spec + * + * @return default APP log Spec + */ + public static AppLogInfoImpl createDefaultAppLogInfo() { + final String serviceInstanceId = + resolveProperty(null, AppLogInfo.Defaults.DEFAULT_SERVICE_INSTANCE_ID, + "SERVICE_NAME", "ServiceInstanceId", "SERVICE_INSTANCE_ID"); + final String instanceUUID = + resolveProperty(null, AppLogInfo.Defaults.DEFAULT_INSTANCE_UUID, + "InstanceUUID", "INSTANCE_UUID"); + final String virtualServerName = + resolveProperty(null, AppLogInfo.Defaults.DEFAULT_VIRTUAL_SERVER_NAME, + "VirtualServerName", "VIRTUAL_SERVER_NAME"); + final String serverIPAddress = getHostIPAddress() != null ? + getHostIPAddress() : AppLogInfo.Defaults.DEFAULT_SERVER_IP_ADDRESS; + final String serverFQDN = getHostName() != null ? getHostName() : AppLogInfo.Defaults.DEFAULT_SERVER_FQDN; + return new AppLogInfoImpl(serviceInstanceId, instanceUUID, virtualServerName, serverIPAddress, serverFQDN); + } + + + /** + * Returns status code based on log level category + * + * @param logLevelCategory log level category + * + * @return request status code as string based on log level category + */ + private static RequestStatusCode getStatusCode(final LogLevelCategory logLevelCategory) { + if (logLevelCategory == LogLevelCategory.DEBUG || logLevelCategory == LogLevelCategory.INFO || + logLevelCategory == LogLevelCategory.WARN) { + return RequestStatusCode.COMPLETE; + } else { + return RequestStatusCode.ERROR; + } + } + + /** + * Returns nagios Alert level based on log level category + * + * @param logLevelCategory log level category + * + * @return nagios alert level + */ + private static NagiosAlertLevel getNagiosAlertLevel(final LogLevelCategory logLevelCategory) { + switch (logLevelCategory) { + case DEBUG: + return NagiosAlertLevel.OK; + case INFO: + return NagiosAlertLevel.OK; + case WARN: + return NagiosAlertLevel.WARNING; + case ERROR: + return NagiosAlertLevel.CRITICAL; + case FATAL: + return NagiosAlertLevel.CRITICAL; + default: + return NagiosAlertLevel.UNKNOWN; + } + } + + /** + * Resolves property value if not present + * + * @param userPassedValue user passed property value + * @param defaultValue default value if no value is found after resolving the property + * @param propertyNames property names + * + * @return resolved property value + */ + private static String resolveProperty( + final String userPassedValue, final String defaultValue, final String... propertyNames) { + // if user passed is present return that value + if (userPassedValue != null) { + return userPassedValue; + } + // resolve it using composite resolver + final String resolveProperty = resolveProperty(Arrays.asList(propertyNames)); + return resolveProperty != null ? resolveProperty : defaultValue; + } + + /** + * Resolves property values in different places + * + * @param propertyNames property Names + * + * @return property Value + */ + private static String resolveProperty(final List propertyNames) { + return COMPOSITE_PROPERTY_RESOLVER.resolve(propertyNames); + } + + + /** + * Determine host IP Address + * + * @return host ip address + */ + private static String getHostIPAddress() { + final InetAddress inetAddress = getInetAddress(); + if (inetAddress != null) { + return inetAddress.getHostAddress(); + } + return null; + } + + /** + * Determines fully qualified host name + * + * @return fully qualified host name + */ + private static String getHostName() { + final InetAddress inetAddress = getInetAddress(); + if (inetAddress != null) { + return inetAddress.getCanonicalHostName(); + } + return null; + } + + /** + * Fetches Inet Address + * + * @return Inet Address + */ + private static InetAddress getInetAddress() { + try { + return InetAddress.getLocalHost(); + } catch (UnknownHostException e) { + return null; + } + } + + +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/resources/META-INF/services/org.onap.dcae.utils.eelf.logger.api.log.EELFLogger b/eelf-logger/eelf-logger-logback-impl/src/main/resources/META-INF/services/org.onap.dcae.utils.eelf.logger.api.log.EELFLogger new file mode 100644 index 0000000..d7d5c71 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/resources/META-INF/services/org.onap.dcae.utils.eelf.logger.api.log.EELFLogger @@ -0,0 +1,20 @@ +# +# ================================================================================ +# Copyright (c) 2018 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========================================================= +# +# + +org.onap.dcae.utils.eelf.logger.logback.log.EELFLoggerImpl diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-async-appenders.xml b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-async-appenders.xml new file mode 100644 index 0000000..e2e93e4 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-async-appenders.xml @@ -0,0 +1,55 @@ + + + + + + + + ${queueSize} + ${maxFlushTime} + + + + + ${queueSize} + ${maxFlushTime} + + + + + ${queueSize} + ${maxFlushTime} + + + + + ${queueSize} + ${maxFlushTime} + + + + + + diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-defaults.xml b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-defaults.xml new file mode 100644 index 0000000..f9bb078 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-defaults.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-logback.xml b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-logback.xml new file mode 100644 index 0000000..7e08eb2 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-logback.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-optional-appenders.xml b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-optional-appenders.xml new file mode 100644 index 0000000..fb7ec7f --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-optional-appenders.xml @@ -0,0 +1,68 @@ + + + + + + + + + DEBUG_LOG + ACCEPT + DENY + + + ${debugLogDirectory}/${debugLogName}.log + + + ${logDirectory}/${debugLogName}.%i.log.zip + ${minFileIndex} + ${maxFileIndex} + + + + ${maxFileSize} + + + + + + + + + + + + + + METRIC_LOG,AUDIT_LOG,ERROR_LOG,DEBUG_LOG + ACCEPT + DENY + + + + + + + + diff --git a/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-required-appenders.xml b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-required-appenders.xml new file mode 100644 index 0000000..72f1a5d --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/main/resources/eelf-required-appenders.xml @@ -0,0 +1,112 @@ + + + + + + + + + AUDIT_LOG + ACCEPT + DENY + + + ${logDirectory}/${auditLogName}.log + + + ${logDirectory}/${auditLogName}.%i.log.zip + ${minFileIndex} + ${maxFileIndex} + + + + ${maxFileSize} + + + + + + + + + + + + + + METRIC_LOG + ACCEPT + DENY + + + ${logDirectory}/${metricLogName}.log + + + ${logDirectory}/${metricLogName}.%i.log.zip + ${minFileIndex} + ${maxFileIndex} + + + + ${maxFileSize} + + + + + + + + + + + + + + ERROR_LOG + ACCEPT + DENY + + + ${logDirectory}/${errorLogName}.log + + + ${logDirectory}/${errorLogName}.%i.log.zip + ${minFileIndex} + ${maxFileIndex} + + + + ${maxFileSize} + + + + + + + + + + diff --git a/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/BaseLogbackUnitTest.java b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/BaseLogbackUnitTest.java new file mode 100644 index 0000000..fda4355 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/BaseLogbackUnitTest.java @@ -0,0 +1,157 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback; + + +import org.onap.dcae.utils.eelf.logger.api.info.CodeLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.CustomFieldsLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ErrorLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.MessageLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.MiscLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.NagiosAlertLevel; +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.RequestStatusCode; +import org.onap.dcae.utils.eelf.logger.api.info.RequestTimingLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ResponseLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ServiceLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.TargetServiceLogInfo; +import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.MetricLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; +import org.onap.dcae.utils.eelf.logger.model.info.CodeLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.CustomFieldsLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.ErrorLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.MessageLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.MiscLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.RequestIdLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.RequestTimingLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.ResponseLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.ServiceLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.TargetServiceLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.AuditLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.DebugLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.ErrorLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.MetricLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.OptionalLogSpecImpl; + +import java.util.Date; + +/** + * Base Logback Unit Test. + * + * @author Rajiv Singla + */ +public abstract class BaseLogbackUnitTest { + + protected static final String TEST_SERVICE_INSTANCE_ID = "testServiceInstanceID"; + protected static final String TEST_INSTANCE_UUID = ""; + + static { + System.setProperty("ServiceInstanceId", TEST_SERVICE_INSTANCE_ID); + System.setProperty("InstanceUUID", TEST_INSTANCE_UUID); + } + + protected static final String TEST_REQUEST_ID = "403cdad8-4de7-450d-b441-561001decdd6"; + protected static final String TEST_SERVICE_NAME = "testServiceName"; + protected static final String TEST_PARTNER_NAME = "testPartnerName"; + protected static final String TEST_CLIENT_IP_ADDRESS = ""; + + protected static final Date START_DATE = new Date(); + protected static final Date END_DATE = new Date(new Date().getTime() + 30_000); + protected static final Long ELAPSED_TIME = END_DATE.getTime() - START_DATE.getTime(); + + protected static final Integer RESPONSE_CODE = 200; + protected static final String RESPONSE_DESCRIPTION = "TEST RESPONSE DESCRIPTION"; + + protected static final String TEST_TARGET_ENTITY = "testTargetEntity"; + protected static final String TEST_TARGET_SERVICE_NAME = "testTargetServiceName"; + protected static final String TEST_TARGET_VIRTUAL_ENTITY = "testTargetVirtualEntity"; + + + protected static final String TEST_THREAD_ID = "testThreadId"; + protected static final String TEST_CLASS_NAME = "testClassName"; + + protected static final String TEST_CUSTOM_FIELD1 = "testCustomField1"; + protected static final String TEST_CUSTOM_FIELD2 = "testCustomField2"; + protected static final String TEST_CUSTOM_FIELD3 = "testCustomField3"; + protected static final String TEST_CUSTOM_FIELD4 = "testCustomField4"; + + protected static final String TEST_PROCESS_KEY = "testProcessId"; + + protected static final Integer TEST_ERROR_CODE = 500; + protected static final String TEST_ERROR_CODE_DESCRIPTION = "TEST ERROR CODE DESCRIPTION"; + + + protected static RequestIdLogInfo getTestRequestIdLogInfo() { + return new RequestIdLogInfoImpl(TEST_REQUEST_ID); + } + + protected static ServiceLogInfo getTestServiceLogInfo() { + return new ServiceLogInfoImpl(TEST_SERVICE_NAME, TEST_PARTNER_NAME, TEST_CLIENT_IP_ADDRESS); + } + + protected static RequestTimingLogInfo getTestRequestTimingInfo() { + return new RequestTimingLogInfoImpl(START_DATE, END_DATE, ELAPSED_TIME); + } + + protected static ResponseLogInfo getTestResponseLogInfo() { + return new ResponseLogInfoImpl(RESPONSE_CODE, RESPONSE_DESCRIPTION); + } + + protected static AuditLogSpec getTestAuditLogSpec() { + return new AuditLogSpecImpl(getTestRequestIdLogInfo(), getTestServiceLogInfo(), + getTestRequestTimingInfo(), getTestResponseLogInfo()); + } + + protected static DebugLogSpec getTestDebugLogSpec() { + return new DebugLogSpecImpl(getTestRequestIdLogInfo()); + } + + protected static TargetServiceLogInfo getTestTargetServiceLogInfo() { + return new TargetServiceLogInfoImpl(TEST_TARGET_ENTITY, TEST_TARGET_SERVICE_NAME, TEST_TARGET_VIRTUAL_ENTITY); + } + + protected static MetricLogSpec getTestMetricLogSpec() { + return new MetricLogSpecImpl(getTestRequestIdLogInfo(), getTestServiceLogInfo(), + getTestRequestTimingInfo(), getTestResponseLogInfo(), getTestTargetServiceLogInfo()); + } + + protected static ErrorLogInfo getTestErrorLogInfo() { + return new ErrorLogInfoImpl(TEST_ERROR_CODE, TEST_ERROR_CODE_DESCRIPTION); + } + + protected static ErrorLogSpec getTestErrorLogSpec() { + return new ErrorLogSpecImpl(getTestRequestIdLogInfo(), getTestServiceLogInfo(), getTestTargetServiceLogInfo() + , getTestErrorLogInfo()); + } + + protected static OptionalLogSpec getTestOptionalLogSpec() { + final MessageLogInfo messageLogInfo = new MessageLogInfoImpl(new Date(), RequestStatusCode.COMPLETE, + NagiosAlertLevel.OK); + final CodeLogInfo codeLogInfo = new CodeLogInfoImpl(TEST_THREAD_ID, TEST_CLASS_NAME); + final CustomFieldsLogInfo customFieldsLogInfo = new CustomFieldsLogInfoImpl(TEST_CUSTOM_FIELD1, + TEST_CUSTOM_FIELD2, TEST_CUSTOM_FIELD3, TEST_CUSTOM_FIELD4); + final MiscLogInfo miscLogInfo = new MiscLogInfoImpl(TEST_PROCESS_KEY, ""); + return new OptionalLogSpecImpl(messageLogInfo, codeLogInfo, customFieldsLogInfo, miscLogInfo); + } + +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/AuditLogImplTest.java b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/AuditLogImplTest.java new file mode 100644 index 0000000..02b377a --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/AuditLogImplTest.java @@ -0,0 +1,66 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.log; + +import org.junit.Test; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger; +import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.BaseLogbackUnitTest; +import org.onap.dcae.utils.eelf.logger.logback.EELFLoggerDefaults; +import org.onap.dcae.utils.eelf.logger.model.spec.AuditLogSpecImpl; + +/** + * Tests for Audit log implementations. + * + * @author Rajiv Singla + */ +public class AuditLogImplTest extends BaseLogbackUnitTest { + + private static final EELFLogger LOG = EELFLogFactory.getLogger(AuditLogImplTest.class); + + @Test + public void auditLoggerTest() throws Exception { + + LOG.auditLog().info("Test Audit info message: {}", + getTestAuditLogSpec(), getTestOptionalLogSpec(), "infoArg"); + + final AuditLogSpec emptyAuditLog = new AuditLogSpecImpl(null, null, + null, null); + + LOG.auditLog().info("Test Empty Audit info message.", emptyAuditLog, + EELFLoggerDefaults.DEFAULT_OPTIONAL_LOG_SPEC); + + } + + + @Test + public void auditLoggerTestWithWarnLogLevel() throws Exception { + LOG.auditLog().warn("Test Audit warn message: {}", + getTestAuditLogSpec(), getTestOptionalLogSpec(), "warnArg"); + } + + @Test + public void auditLoggerTestWithErrorLogLevel() throws Exception { + LOG.auditLog().error("Test Audit error message: {}", + getTestAuditLogSpec(), getTestOptionalLogSpec(), "errorArg"); + + } +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/DebugLogImplTest.java b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/DebugLogImplTest.java new file mode 100644 index 0000000..76d41f9 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/DebugLogImplTest.java @@ -0,0 +1,53 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.log; + +import org.junit.Test; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger; +import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.BaseLogbackUnitTest; +import org.onap.dcae.utils.eelf.logger.logback.EELFLoggerDefaults; +import org.onap.dcae.utils.eelf.logger.model.spec.DebugLogSpecImpl; + + +/** + * Test for Debug log implementation. + * + * @author Rajiv Singla + */ +public class DebugLogImplTest extends BaseLogbackUnitTest { + + private static final EELFLogger LOG = EELFLogFactory.getLogger(DebugLogImplTest.class); + + @Test + public void debugLoggerTest() throws Exception { + + LOG.debugLog().debug("Test DebugLog debug message: {}", + getTestDebugLogSpec(), getTestOptionalLogSpec(), "debugArg"); + + final DebugLogSpec emptyDebugLog = new DebugLogSpecImpl(null); + + LOG.debugLog().debug("Test Empty DebugLog debug message.", emptyDebugLog, + EELFLoggerDefaults.DEFAULT_OPTIONAL_LOG_SPEC); + + } + +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/ErrorLogImplTest.java b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/ErrorLogImplTest.java new file mode 100644 index 0000000..0b96be5 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/ErrorLogImplTest.java @@ -0,0 +1,61 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.log; + +import org.junit.Test; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger; +import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.BaseLogbackUnitTest; +import org.onap.dcae.utils.eelf.logger.logback.EELFLoggerDefaults; +import org.onap.dcae.utils.eelf.logger.model.spec.ErrorLogSpecImpl; + + +/** + * Tests for Error Log implementation. + * + * @author Rajiv Singla + */ +public class ErrorLogImplTest extends BaseLogbackUnitTest { + + private static final EELFLogger LOG = EELFLogFactory.getLogger(ErrorLogImplTest.class); + + @Test + public void errorLoggerTest() throws Exception { + LOG.errorLog().error("Test ErrorLog error message: {}", + getTestErrorLogSpec(), getTestOptionalLogSpec(), "errorArg"); + + final ErrorLogSpec emptyErrorLog = new ErrorLogSpecImpl(null, null, + null, null); + + LOG.errorLog().error("Test Empty ErrorLog error message", emptyErrorLog, + EELFLoggerDefaults.DEFAULT_OPTIONAL_LOG_SPEC); + + } + + @Test + public void errorLoggerTestWithWarnLogLevel() throws Exception { + LOG.errorLog().warn("Test errorLog warn message: {}", getTestErrorLogSpec(), getTestOptionalLogSpec(), + "warnArg"); + + } + + +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/MetricLogImplTest.java b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/MetricLogImplTest.java new file mode 100644 index 0000000..8df1e9c --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/MetricLogImplTest.java @@ -0,0 +1,67 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.log; + +import org.junit.Test; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger; +import org.onap.dcae.utils.eelf.logger.api.spec.MetricLogSpec; +import org.onap.dcae.utils.eelf.logger.logback.BaseLogbackUnitTest; +import org.onap.dcae.utils.eelf.logger.logback.EELFLoggerDefaults; +import org.onap.dcae.utils.eelf.logger.model.spec.MetricLogSpecImpl; + + +/** + * Tests for Metric Log implementation. + * + * @author Rajiv Singla + */ +public class MetricLogImplTest extends BaseLogbackUnitTest { + + private static final EELFLogger LOG = EELFLogFactory.getLogger(MetricLogImplTest.class); + + @Test + public void metricLoggerTest() throws Exception { + + LOG.metricLog().info("test Metric info message: {}", getTestMetricLogSpec(), getTestOptionalLogSpec(), + "infoArg"); + + final MetricLogSpec emptyMetricLog = new MetricLogSpecImpl(null, null, null, null, null); + + LOG.metricLog().info("Test Empty Metric info message", emptyMetricLog, + EELFLoggerDefaults.DEFAULT_OPTIONAL_LOG_SPEC); + } + + @Test + public void metricLoggerTestWithWarnLogLevel() throws Exception { + LOG.metricLog().warn("test Metric warn message: {}", getTestMetricLogSpec(), getTestOptionalLogSpec(), + "warnArg"); + + } + + @Test + public void metricLoggerTestWithErrorLogLevel() throws Exception { + LOG.metricLog().warn("test Metric error message: {}", getTestMetricLogSpec(), getTestOptionalLogSpec(), + "errorArg"); + + + } + +} diff --git a/eelf-logger/eelf-logger-logback-impl/src/test/resources/logback.xml b/eelf-logger/eelf-logger-logback-impl/src/test/resources/logback.xml new file mode 100644 index 0000000..b1cffd6 --- /dev/null +++ b/eelf-logger/eelf-logger-logback-impl/src/test/resources/logback.xml @@ -0,0 +1,41 @@ + + + + + + ${componentName} + + + + + + + + + + + + + + + + + + diff --git a/eelf-logger/eelf-logger-model/pom.xml b/eelf-logger/eelf-logger-model/pom.xml new file mode 100644 index 0000000..86f269a --- /dev/null +++ b/eelf-logger/eelf-logger-model/pom.xml @@ -0,0 +1,77 @@ + + + + + + 4.0.0 + + + org.onap.dcaegen2.utils + eelf-logger + 1.0.0-SNAPSHOT + + + eelf-logger-model + jar + + + + dcaegen2-utils-eelf-logger-model + Contains immutable model objects for various EELF Logger interfaces + + + ${project.parent.basedir} + + **/model/** + + + + + + + + ${project.groupId} + eelf-logger-api + ${project.version} + + + + + org.projectlombok + lombok + + + + + + ${project.build.directory}/generated-sources/delombok + + + org.projectlombok + lombok-maven-plugin + + + + + + + diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/AppLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/AppLogInfoImpl.java new file mode 100644 index 0000000..689915c --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/AppLogInfoImpl.java @@ -0,0 +1,53 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.AppLogInfo; + +/** + * Concrete model implementation for {@link AppLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class AppLogInfoImpl implements AppLogInfo { + + private static final long serialVersionUID = 1L; + + private String serviceInstanceID; + + private String instanceUUID; + + private String virtualServerName; + + private String serverIPAddress; + + private String serverFQDN; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/CodeLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/CodeLogInfoImpl.java new file mode 100644 index 0000000..7f5eb2f --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/CodeLogInfoImpl.java @@ -0,0 +1,48 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.CodeLogInfo; + +/** + * Concrete model implementation for {@link CodeLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class CodeLogInfoImpl implements CodeLogInfo { + + private static final long serialVersionUID = 1L; + + private String threadId; + + private String className; + + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/CustomFieldsLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/CustomFieldsLogInfoImpl.java new file mode 100644 index 0000000..151900d --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/CustomFieldsLogInfoImpl.java @@ -0,0 +1,51 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.CustomFieldsLogInfo; + +/** + * Concrete model implementation for {@link CustomFieldsLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class CustomFieldsLogInfoImpl implements CustomFieldsLogInfo { + + private static final long serialVersionUID = 1L; + + private String customField1; + + private String customField2; + + private String customField3; + + private String customField4; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ErrorLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ErrorLogInfoImpl.java new file mode 100644 index 0000000..18c2e95 --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ErrorLogInfoImpl.java @@ -0,0 +1,47 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.ErrorLogInfo; + +/** + * Concrete model implementation for {@link ErrorLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class ErrorLogInfoImpl implements ErrorLogInfo { + + private static final long serialVersionUID = 1L; + + private Integer errorCode; + + private String errorDescription; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/MessageLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/MessageLogInfoImpl.java new file mode 100644 index 0000000..65e722a --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/MessageLogInfoImpl.java @@ -0,0 +1,54 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.MessageLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.NagiosAlertLevel; +import org.onap.dcae.utils.eelf.logger.api.info.RequestStatusCode; + + +import java.util.Date; + +/** + * Concrete model implementation for {@link MessageLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class MessageLogInfoImpl implements MessageLogInfo { + + private static final long serialVersionUID = 1L; + + private Date creationTimestamp; + + private RequestStatusCode statusCode; + + private NagiosAlertLevel alertSeverity; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/MiscLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/MiscLogInfoImpl.java new file mode 100644 index 0000000..f7e648b --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/MiscLogInfoImpl.java @@ -0,0 +1,47 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.MiscLogInfo; + +/** + * Concrete model implementation for {@link MiscLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class MiscLogInfoImpl implements MiscLogInfo { + + private static final long serialVersionUID = 1L; + + private String processId; + + private String unused; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/RequestIdLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/RequestIdLogInfoImpl.java new file mode 100644 index 0000000..af939c4 --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/RequestIdLogInfoImpl.java @@ -0,0 +1,45 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; + +/** + * Concrete model implementation for {@link RequestIdLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class RequestIdLogInfoImpl implements RequestIdLogInfo { + + private static final long serialVersionUID = 1L; + + private String requestId; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/RequestTimingLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/RequestTimingLogInfoImpl.java new file mode 100644 index 0000000..19d860b --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/RequestTimingLogInfoImpl.java @@ -0,0 +1,51 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.RequestTimingLogInfo; + +import java.util.Date; + +/** + * Concrete model implementation for {@link RequestTimingLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class RequestTimingLogInfoImpl implements RequestTimingLogInfo { + + private static final long serialVersionUID = 1L; + + private Date beginTimestamp; + + private Date endTimestamp; + + private Long elapsedTime; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ResponseLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ResponseLogInfoImpl.java new file mode 100644 index 0000000..1f0bfbf --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ResponseLogInfoImpl.java @@ -0,0 +1,47 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.ResponseLogInfo; + +/** + * Concrete model implementation for {@link ResponseLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class ResponseLogInfoImpl implements ResponseLogInfo { + + private static final long serialVersionUID = 1L; + + private Integer responseCode; + + private String responseDescription; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ServiceLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ServiceLogInfoImpl.java new file mode 100644 index 0000000..68d1f41 --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/ServiceLogInfoImpl.java @@ -0,0 +1,49 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.ServiceLogInfo; + +/** + * Concrete model implementation for {@link ServiceLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class ServiceLogInfoImpl implements ServiceLogInfo { + + private static final long serialVersionUID = 1L; + + private String serviceName; + + private String partnerName; + + private String clientIPAddress; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/TargetServiceLogInfoImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/TargetServiceLogInfoImpl.java new file mode 100644 index 0000000..4a41e73 --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/TargetServiceLogInfoImpl.java @@ -0,0 +1,48 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.model.info; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.TargetServiceLogInfo; + +/** + * Concrete model implementation for {@link TargetServiceLogInfo} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class TargetServiceLogInfoImpl implements TargetServiceLogInfo { + + private static final long serialVersionUID = 1L; + + private String targetEntity; + + private String targetServiceName; + + private String targetVirtualEntity; +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/package-info.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/package-info.java new file mode 100644 index 0000000..ce0966e --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/info/package-info.java @@ -0,0 +1,23 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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========================================================= + * + */ + +/** + * Contains immutable implementations for EELF Logging Information interfaces + */ +package org.onap.dcae.utils.eelf.logger.model.info; diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/AppLogSpecImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/AppLogSpecImpl.java new file mode 100644 index 0000000..d1e40ad --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/AppLogSpecImpl.java @@ -0,0 +1,47 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.model.spec; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Delegate; +import org.onap.dcae.utils.eelf.logger.api.info.AppLogInfo; +import org.onap.dcae.utils.eelf.logger.api.spec.AppLogSpec; + + +/** + * Concrete model implementation for {@link AppLogSpec} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +public class AppLogSpecImpl implements AppLogSpec { + + private static final long serialVersionUID = 1L; + + @Delegate(types = AppLogSpec.class) + private AppLogInfo appLogInfo; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/AuditLogSpecImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/AuditLogSpecImpl.java new file mode 100644 index 0000000..c217595 --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/AuditLogSpecImpl.java @@ -0,0 +1,61 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.model.spec; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Delegate; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.RequestTimingLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ResponseLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ServiceLogInfo; +import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec; + + +/** + * Concrete model implementation for {@link AuditLogSpec} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class AuditLogSpecImpl implements AuditLogSpec { + + private static final long serialVersionUID = 1L; + + @Delegate(types = RequestIdLogInfo.class) + private RequestIdLogInfo requestIdLogInfo; + + @Delegate(types = ServiceLogInfo.class) + private ServiceLogInfo serviceLogInfo; + + @Delegate(types = RequestTimingLogInfo.class) + private RequestTimingLogInfo requestTimingLogInfo; + + @Delegate(types = ResponseLogInfo.class) + private ResponseLogInfo responseLogInfo; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/DebugLogSpecImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/DebugLogSpecImpl.java new file mode 100644 index 0000000..53a1070 --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/DebugLogSpecImpl.java @@ -0,0 +1,48 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.model.spec; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Delegate; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; +import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec; + + +/** + * Concrete model implementation for {@link DebugLogSpec} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class DebugLogSpecImpl implements DebugLogSpec { + + private static final long serialVersionUID = 1L; + + @Delegate(types = RequestIdLogInfo.class) + private RequestIdLogInfo requestIdLogInfo; +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/ErrorLogSpecImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/ErrorLogSpecImpl.java new file mode 100644 index 0000000..6e73fcf --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/ErrorLogSpecImpl.java @@ -0,0 +1,61 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.model.spec; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Delegate; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.ErrorLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ServiceLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.TargetServiceLogInfo; +import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec; + + +/** + * Concrete model implementation for {@link ErrorLogSpec} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class ErrorLogSpecImpl implements ErrorLogSpec { + + private static final long serialVersionUID = 1L; + + @Delegate(types = RequestIdLogInfo.class) + private RequestIdLogInfo requestIdLogInfo; + + @Delegate(types = ServiceLogInfo.class) + private ServiceLogInfo serviceLogInfo; + + @Delegate(types = TargetServiceLogInfo.class) + private TargetServiceLogInfo targetServiceLogInfo; + + @Delegate(types = ErrorLogInfo.class) + private ErrorLogInfo errorLogInfo; + +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/MetricLogSpecImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/MetricLogSpecImpl.java new file mode 100644 index 0000000..d910bc2 --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/MetricLogSpecImpl.java @@ -0,0 +1,64 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.model.spec; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Delegate; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.RequestTimingLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ResponseLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ServiceLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.TargetServiceLogInfo; +import org.onap.dcae.utils.eelf.logger.api.spec.MetricLogSpec; + + +/** + * Concrete model implementation for {@link MetricLogSpec} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class MetricLogSpecImpl implements MetricLogSpec { + + private static final long serialVersionUID = 1L; + + @Delegate(types = RequestIdLogInfo.class) + private RequestIdLogInfo requestIdLogInfo; + + @Delegate(types = ServiceLogInfo.class) + private ServiceLogInfo serviceLogInfo; + + @Delegate(types = RequestTimingLogInfo.class) + private RequestTimingLogInfo requestTimingLogInfo; + + @Delegate(types = ResponseLogInfo.class) + private ResponseLogInfo responseLogInfo; + + @Delegate(types = TargetServiceLogInfo.class) + private TargetServiceLogInfo targetServiceLogInfo; +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/OptionalLogSpecImpl.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/OptionalLogSpecImpl.java new file mode 100644 index 0000000..755b4bf --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/OptionalLogSpecImpl.java @@ -0,0 +1,60 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.dcae.utils.eelf.logger.model.spec; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Delegate; +import lombok.experimental.Wither; +import org.onap.dcae.utils.eelf.logger.api.info.CodeLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.CustomFieldsLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.MessageLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.MiscLogInfo; +import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec; + + +/** + * Concrete model implementation for {@link OptionalLogSpec} + * + * @author Rajiv Singla + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Wither +public class OptionalLogSpecImpl implements OptionalLogSpec { + + private static final long serialVersionUID = 1L; + + @Delegate(types = MessageLogInfo.class) + private MessageLogInfo messageLogInfo; + + @Delegate(types = CodeLogInfo.class) + private CodeLogInfo codeLogInfo; + + @Delegate(types = CustomFieldsLogInfo.class) + private CustomFieldsLogInfo customFieldsLogInfo; + + @Delegate(types = MiscLogInfo.class) + private MiscLogInfo miscLogInfo; +} diff --git a/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/package-info.java b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/package-info.java new file mode 100644 index 0000000..73aec41 --- /dev/null +++ b/eelf-logger/eelf-logger-model/src/main/java/org/onap/dcae/utils/eelf/logger/model/spec/package-info.java @@ -0,0 +1,23 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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========================================================= + * + */ + +/** + * Contains immutable implementations for EELF Logging specification interfaces + */ +package org.onap.dcae.utils.eelf.logger.model.spec; diff --git a/eelf-logger/findbugs-exclude.xml b/eelf-logger/findbugs-exclude.xml new file mode 100644 index 0000000..9eac36d --- /dev/null +++ b/eelf-logger/findbugs-exclude.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + diff --git a/eelf-logger/pmd-exclude.properties b/eelf-logger/pmd-exclude.properties new file mode 100644 index 0000000..d325b88 --- /dev/null +++ b/eelf-logger/pmd-exclude.properties @@ -0,0 +1,22 @@ +# +# ================================================================================ +# Copyright (c) 2018 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========================================================= +# +# + +# List fully qualified names of classes that can be excluded for PMD (PROGRAMMING-MISTAKE-DETECTOR) + +# IGNORE TOO MANY STATIC IMPORTS diff --git a/eelf-logger/pom.xml b/eelf-logger/pom.xml new file mode 100644 index 0000000..acb5fda --- /dev/null +++ b/eelf-logger/pom.xml @@ -0,0 +1,476 @@ + + + + + 4.0.0 + + eelf-logger-api + eelf-logger-model + eelf-logger-logback-impl + + + + utils + org.onap.dcaegen2.utils + 1.2.0-SNAPSHOT + + + + eelf-logger + dcaegen2-utils-eelf-logger + 1.0.0-SNAPSHOT + pom + http://maven.apache.org + + + + + + UTF-8 + UTF-8 + ${project.basedir} + + + true + + + 1.7.5 + 1.2.3 + 1.16.10 + + + + 4.12 + 2.2.11 + 2.6.0 + + + + 3.3 + 2.19.1 + 2.19.1 + 3.0.2 + + 3.5 + 2.10.4 + 2.4 + 2.4 + 2.8 + 1.16.10.0 + 3.5.1 + + + 1.7 + 1.7 + **/*Test.java + false + **/*IT.java + true + true + true + + + + + + + + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + + ch.qos.logback + logback-classic + ${logback.version} + + + + + org.projectlombok + lombok + ${lombok.version} + provided + + + + + + junit + junit + ${junit.version} + test + + + + org.mockito + mockito-core + ${mockito.version} + test + + + + org.assertj + assertj-core + ${assertj-core.version} + test + + + + + + + + + + + + junit + junit + + + org.mockito + mockito-core + + + org.assertj + assertj-core + + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${compiler.plugin.version} + + ${compiler.target.version} + ${compiler.source.version} + + + + + + org.apache.maven.plugins + maven-source-plugin + ${source.plugin.version} + + true + + + + attach-sources + verify + + jar-no-fork + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${javadoc.plugin.version} + + + true + false + false + + + + aggregate + site + + aggregate + + + + attach-javadoc + + jar + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.plugin.version} + + ${skip.unit.tests} + -Xmx2048m -Djava.awt.headless=true -XX:+UseConcMarkSweepGC + -XX:OnOutOfMemoryError="kill -9 %p" -XX:+HeapDumpOnOutOfMemoryError + + ${surefire.redirectTestOutputToFile} + methods + 8 + 8 + true + xml + false + + ${project.build.directory} + + ${basedir}/src/test/resources/logback-test.xml + + + + ${unit.test.pattern} + + + ${integration.test.pattern} + + + ${surefireArgLine} + + + + org.apache.maven.surefire + surefire-junit47 + ${surefire.plugin.version} + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + ${failsafe.plugin.version} + + + integration-tests + + integration-test + verify + + + ${skip.integration.tests} + + + ${failsafeArgLine} + + + + + + + + + org.codehaus.mojo + findbugs-maven-plugin + ${findbugs.plugin.version} + + Max + Low + true + + ${findbugs.failOnError} + ${main.basedir}/findbugs-exclude.xml + ${project.reporting.outputDirectory}/findbugs + ${project.reporting.outputDirectory}/findbugs + + + + + analyze-compile + compile + + check + + + + + + + + org.apache.maven.plugins + maven-pmd-plugin + ${pmd.plugin.version} + + ${project.build.sourceEncoding} + ${compiler.target.version} + false + + ${pmd.violation.buildfail} + ${project.reporting.outputDirectory}/pmd + 200 + + + + pmd-check + + check + + + true + ${main.basedir}/pmd-exclude.properties + + + + cpd-check + + cpd-check + + + true + ${main.basedir}/cpd-exclude.properties + + + + + + + + + + + org.projectlombok + lombok-maven-plugin + ${lombok.plugin.version} + + + delombok + generate-sources + + delombok + + + false + src/main/java + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + ${jar.plugin.version} + + + + true + + + ${project.version} + + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + ${deploy.plugin.version} + + true + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.apache.maven.plugins + maven-surefire-plugin + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + org.apache.maven.plugins + maven-deploy-plugin + + + + + org.apache.maven.plugins + maven-source-plugin + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + + org.apache.maven.plugins + maven-pmd-plugin + + + + org.codehaus.mojo + findbugs-maven-plugin + + + + + + + + disable-java8-doclint + + [1.8,) + + + -Xdoclint:none + + + + + diff --git a/eelf-logger/version.properties b/eelf-logger/version.properties new file mode 100644 index 0000000..907cdc4 --- /dev/null +++ b/eelf-logger/version.properties @@ -0,0 +1,25 @@ +# +# ================================================================================ +# Copyright (c) 2018 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========================================================= +# +# + +major=1 +minor=0 +patch=0 +base_version=${major}.${minor}.${patch} +release_version=${base_version} +snapshot_version=${base_version}-SNAPSHOT diff --git a/pom.xml b/pom.xml index ac3c6c9..e611b20 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. python-discovery-client python-dockering dcaeapplib + eelf-logger -- cgit 1.2.3-korg