aboutsummaryrefslogtreecommitdiffstats
path: root/cmso-logger
diff options
context:
space:
mode:
authorMaciej Malewski <maciej.malewski@nokia.com>2020-07-17 08:31:51 +0200
committerMaciej Malewski <maciej.malewski@nokia.com>2020-07-21 08:35:51 +0200
commitd8f4b453be2dd8b188ad4bca11cede52a30e7806 (patch)
tree4740721a0ca7f82e880068121f678a6fa87af8d3 /cmso-logger
parent08eb98801d6c009a2819ea913105e1fcabf0c08a (diff)
Upgrade log4j to 2.13.1 and add log4j api 2.13.1.
Issue-ID: OPTFRA-752 Signed-off-by: Maciej Malewski <maciej.malewski@nokia.com> Change-Id: Ib39de5e892f00c07c812a8dc8d3ac7d1fca009cf
Diffstat (limited to 'cmso-logger')
-rw-r--r--cmso-logger/pom.xml57
-rw-r--r--cmso-logger/src/main/java/org/onap/logger/Logger.java123
-rw-r--r--cmso-logger/src/main/java/org/onap/observations/ObservationInterface.java46
3 files changed, 226 insertions, 0 deletions
diff --git a/cmso-logger/pom.xml b/cmso-logger/pom.xml
new file mode 100644
index 0000000..2665690
--- /dev/null
+++ b/cmso-logger/pom.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>cmso</artifactId>
+ <groupId>org.onap.optf.cmso</groupId>
+ <version>2.2.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>cmso-logger</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <version>${log4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ <version>${log4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.att.eelf</groupId>
+ <artifactId>eelf-core</artifactId>
+ <version>${eelf.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ </exclusion>
+
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <version>${javax.version.rs.api}</version>
+ </dependency>
+ </dependencies>
+
+
+</project> \ No newline at end of file
diff --git a/cmso-logger/src/main/java/org/onap/logger/Logger.java b/cmso-logger/src/main/java/org/onap/logger/Logger.java
new file mode 100644
index 0000000..602def3
--- /dev/null
+++ b/cmso-logger/src/main/java/org/onap/logger/Logger.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright © 2019 AT&T Intellectual Property.
+ * Modified 2020 Nokia.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.logger;
+
+import com.att.eelf.configuration.EELFLogger;
+import org.apache.logging.log4j.spi.StandardLevel;
+import org.onap.observations.ObservationInterface;
+
+public class Logger {
+
+ private final EELFLogger log;
+ private final EELFLogger metrics;
+ private final EELFLogger audit;
+ private final EELFLogger errors;
+ private final EELFLogger debug;
+
+ public Logger(EELFLogger log, EELFLogger metrics, EELFLogger audit, EELFLogger errors, EELFLogger debug) {
+ this.log = log;
+ this.metrics = metrics;
+ this.audit = audit;
+ this.errors = errors;
+ this.debug = debug;
+ }
+
+ public void report(ObservationInterface obs, Exception except, String... arguments) {
+
+ if (obs.getAudit()) {
+ audit.info(obs, except, arguments);
+ }
+ if (obs.getMetric()) {
+ metrics.info(obs, except, arguments);
+ }
+
+ final StandardLevel standardLevel = obs.getLevel().getStandardLevel();
+
+ switch (standardLevel) {
+ case WARN:
+ errors.warn(obs, arguments);
+ debug.debug(obs, except, arguments);
+ break;
+ case INFO:
+ log.info(obs, except, arguments);
+ debug.debug(obs, except, arguments);
+ break;
+ case ERROR:
+ errors.error(obs, arguments);
+ debug.debug(obs, except, arguments);
+ break;
+ case TRACE:
+ debug.trace(obs, except, arguments);
+ break;
+ case DEBUG:
+ debug.debug(obs, except, arguments);
+ break;
+ default:
+ log.info(obs, except, arguments);
+ }
+
+ }
+
+ public void report(ObservationInterface obs, String... arguments) {
+
+ if (obs.getAudit()) {
+ audit.info(obs, arguments);
+ }
+ if (obs.getMetric()) {
+ metrics.info(obs, arguments);
+ }
+
+ final StandardLevel standardLevel = obs.getLevel().getStandardLevel();
+
+ switch (standardLevel) {
+ case WARN:
+ errors.warn(obs, arguments);
+ debug.debug(obs, arguments);
+ break;
+ case INFO:
+ log.info(obs, arguments);
+ debug.debug(obs, arguments);
+ break;
+ case ERROR:
+ errors.error(obs, arguments);
+ debug.debug(obs, arguments);
+ break;
+ case TRACE:
+ debug.debug(obs, arguments);
+ break;
+ case DEBUG:
+ debug.debug(obs, arguments);
+ break;
+ default:
+ log.info(obs, arguments);
+ }
+ }
+}
diff --git a/cmso-logger/src/main/java/org/onap/observations/ObservationInterface.java b/cmso-logger/src/main/java/org/onap/observations/ObservationInterface.java
new file mode 100644
index 0000000..bc14f33
--- /dev/null
+++ b/cmso-logger/src/main/java/org/onap/observations/ObservationInterface.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright © 2019 AT&T Intellectual Property.
+ * Modified 2020 Nokia.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed under the Creative
+ * Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.observations;
+
+
+import com.att.eelf.i18n.EELFResolvableErrorEnum;
+import org.apache.logging.log4j.Level;
+
+import static javax.ws.rs.core.Response.Status;
+
+public interface ObservationInterface extends EELFResolvableErrorEnum {
+
+ Enum<?> getValue();
+ Level getLevel();
+ String getMessage();
+ Status getStatus();
+ String getDomain();
+ String name();
+ Boolean getAudit();
+ Boolean getMetric();
+}