aboutsummaryrefslogtreecommitdiffstats
path: root/feature-eelf/src
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2017-06-26 08:05:30 -0500
committerJorge Hernandez <jh1730@att.com>2017-06-26 08:16:10 -0500
commit9e69cc20f40f8ec89aa8a1487c2f6b3e687ded40 (patch)
treeb8851c6243f09575132e4a1a99bc0ad5233c4263 /feature-eelf/src
parentb61e46ab34a649b29f788e9e0e0db3fb018b6fcd (diff)
[POLICY-30] optional loadable eelf feature
for backwards compatibility purposes or if desired to use EELF and common-framework (from policy-common) for logging purposes in miscellaneous environments. It supports EELF/Common Framework style logging at the same time than traditional logging. This functionality is an optional loadable module. policy-docker changes need to be made to optionally unpack to make it active (in a different submission). started marking feature projects with feature prefix in project name to give a clear picture to the community which modules are features vs. code base. Change-Id: I5076c462409f03415ce54f0c9b5f50b78abb18f9 Signed-off-by: Jorge Hernandez <jh1730@att.com>
Diffstat (limited to 'feature-eelf/src')
-rw-r--r--feature-eelf/src/assembly/assemble_zip.xml67
-rw-r--r--feature-eelf/src/main/install/config/logback.xml185
-rw-r--r--feature-eelf/src/main/install/config/policyLogger.properties49
-rw-r--r--feature-eelf/src/main/java/org/openecomp/policy/drools/eelf/EelfFeature.java89
-rw-r--r--feature-eelf/src/main/resources/META-INF/services/org.openecomp.policy.drools.features.PolicyEngineFeatureAPI1
-rw-r--r--feature-eelf/src/test/java/org/openecomp/policy/drools/eelf/test/EElfTest.java138
6 files changed, 529 insertions, 0 deletions
diff --git a/feature-eelf/src/assembly/assemble_zip.xml b/feature-eelf/src/assembly/assemble_zip.xml
new file mode 100644
index 00000000..001d3c66
--- /dev/null
+++ b/feature-eelf/src/assembly/assemble_zip.xml
@@ -0,0 +1,67 @@
+<!--
+ ============LICENSE_START=======================================================
+ feature-eelf
+ ================================================================================
+ Copyright (C) 2017 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=========================================================
+ -->
+
+<!-- Defines how we build the .zip file which is our distribution. -->
+
+<assembly
+ xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
+
+ <id>feature-eelf-package</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+
+ <includeBaseDirectory>false</includeBaseDirectory>
+
+ <fileSets>
+ <fileSet>
+ <directory>target</directory>
+ <outputDirectory>lib/opt</outputDirectory>
+ <includes>
+ <include>feature-eelf-${project.version}.jar</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>target/assembly/</directory>
+ <outputDirectory>.</outputDirectory>
+ <excludes/>
+ </fileSet>
+ <fileSet>
+ <directory>.</directory>
+ <outputDirectory>lib</outputDirectory>
+ <includes>
+ <include>*.jar</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>src/main/install/config</directory>
+ <outputDirectory>config</outputDirectory>
+ </fileSet>
+ <fileSet>
+ <directory>src/main/install/bin</directory>
+ <outputDirectory>bin</outputDirectory>
+ <fileMode>0744</fileMode>
+ <excludes/>
+ </fileSet>
+ </fileSets>
+
+</assembly>
diff --git a/feature-eelf/src/main/install/config/logback.xml b/feature-eelf/src/main/install/config/logback.xml
new file mode 100644
index 00000000..f4295628
--- /dev/null
+++ b/feature-eelf/src/main/install/config/logback.xml
@@ -0,0 +1,185 @@
+<!--
+ ============LICENSE_START=======================================================
+ feature-eelf
+ ================================================================================
+ Copyright (C) 2017 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=========================================================
+ -->
+
+<configuration scan="true" scanPeriod="30 seconds" debug="false">
+
+ <property name="errorLogName" value="error" />
+ <property name="metricsLogName" value="metrics" />
+ <property name="auditLogName" value="audit" />
+ <property name="debugLogName" value="debug" />
+ <property name="networkLogName" value="network" />
+
+ <property name="defaultPattern"
+ value="%X{BeginTimestamp}|%X{EndTimestamp}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServerName}|%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{RemoteHost}|%X{ClassName}||%X{ProcessKey}|%X{TargetVirtualEntity}|%X{CustomField1}|%X{CustomField2}|%X{CustomField3}|%X{CustomField4}|%msg%n" />
+ <property name="defaultMetricPattern"
+ value="%X{BeginTimestamp}|%X{EndTimestamp}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServerName}|%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{RemoteHost}|%X{ClassName}||%X{ProcessKey}|%X{TargetVirtualEntity}|%X{CustomField1}|%X{CustomField2}|%X{CustomField3}|%X{CustomField4}|%msg%n" />
+ <property name="defaultAuditPattern"
+ value="%X{BeginTimestamp}|%X{EndTimestamp}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServerName}|%X{ServiceName}|%X{PartnerName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{RemoteHost}|%X{ClassName}||%X{ProcessKey}|%X{CustomField1}|%X{CustomField2}|%X{CustomField3}|%X{CustomField4}|%msg%n" />
+ <property name="defaultErrorPattern"
+ value="%d{yyyy-MM-dd'T'HH:mm:ss.SSS+00:00, UTC}|%X{RequestId}|%thread|%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%X{ErrorCategory}|%X{ErrorCode}|%X{ErrorDesciption}|%msg%n" />
+ <property name="networkPattern" value="[%d|%t]%m%n" />
+ <property name="debugPattern" value="[%date|%level|%logger{0}|%thread] %msg%n" />
+
+ <property name="logDirectory" value="logs/Policy" />
+ <property name="debugLogDirectory" value="logs/Policy" />
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>${defaultPattern}</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="EELFAudit"
+ class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${logDirectory}/${auditLogName}.log</file>
+ <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>${logDirectory}/${auditLogName}.%i.log.zip
+ </fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>5</maxIndex>
+ </rollingPolicy>
+ <triggeringPolicy
+ class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>10MB</maxFileSize>
+ </triggeringPolicy>
+ <encoder>
+ <pattern>${defaultAuditPattern}</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="asyncEELFAudit" class="ch.qos.logback.classic.AsyncAppender">
+ <appender-ref ref="EELFAudit" />
+ </appender>
+
+ <appender name="EELFMetrics"
+ class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${logDirectory}/${metricsLogName}.log</file>
+ <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>${logDirectory}/${metricsLogName}.%i.log.zip
+ </fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>5</maxIndex>
+ </rollingPolicy>
+ <triggeringPolicy
+ class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>15MB</maxFileSize>
+ </triggeringPolicy>
+ <encoder>
+ <pattern>${defaultMetricPattern}</pattern>
+ </encoder>
+ </appender>
+
+
+ <appender name="asyncEELFMetrics" class="ch.qos.logback.classic.AsyncAppender">
+ <appender-ref ref="EELFMetrics" />
+ </appender>
+
+ <appender name="EELFError"
+ class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${logDirectory}/${errorLogName}.log</file>
+ <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>${logDirectory}/${errorLogName}.%i.log.zip
+ </fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>5</maxIndex>
+ </rollingPolicy>
+ <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
+ <level>ERROR</level>
+ </filter>
+ <triggeringPolicy
+ class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>20MB</maxFileSize>
+ </triggeringPolicy>
+ <encoder>
+ <pattern>${defaultErrorPattern}</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="asyncEELFError" class="ch.qos.logback.classic.AsyncAppender">
+ <appender-ref ref="EELFError" />
+ </appender>
+
+ <appender name="EELFDebug"
+ class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${debugLogDirectory}/${debugLogName}.log</file>
+ <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>${debugLogDirectory}/${debugLogName}.%i.log.zip
+ </fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>5</maxIndex>
+ </rollingPolicy>
+ <triggeringPolicy
+ class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>20MB</maxFileSize>
+ </triggeringPolicy>
+ <encoder>
+ <pattern>${debugPattern}</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="asyncEELFDebug" class="ch.qos.logback.classic.AsyncAppender">
+ <appender-ref ref="EELFDebug" />
+ </appender>
+
+ <appender name="NetworkOut" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${logDirectory}/${networkLogName}.log</file>
+ <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>logs/network.log.%i.zip</fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>5</maxIndex>
+ </rollingPolicy>
+ <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>15MB</maxFileSize>
+ </triggeringPolicy>
+ <encoder>
+ <pattern>${networkPattern}</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="AsyncNetworkOut" class="ch.qos.logback.classic.AsyncAppender">
+ <appender-ref ref="NetworkOut" />
+ </appender>
+
+ <logger name="com.att.eelf.audit" level="info" additivity="false">
+ <appender-ref ref="asyncEELFAudit" />
+ </logger>
+
+ <logger name="com.att.eelf.metrics" level="info" additivity="false">
+ <appender-ref ref="asyncEELFMetrics" />
+ </logger>
+
+ <logger name="com.att.eelf.error" level="error" additivity="false">
+ <appender-ref ref="asyncEELFError" />
+ </logger>
+
+ <logger name="com.att.eelf.debug" level="info" additivity="false">
+ <appender-ref ref="asyncEELFDebug" />
+ </logger>
+
+ <logger name="network" level="INFO" additivity="false">
+ <appender-ref ref="AsyncNetworkOut" />
+ </logger>
+
+ <root level="INFO">
+ <appender-ref ref="asyncEELFDebug" />
+ <appender-ref ref="asyncEELFError" />
+ </root>
+
+</configuration>
diff --git a/feature-eelf/src/main/install/config/policyLogger.properties b/feature-eelf/src/main/install/config/policyLogger.properties
new file mode 100644
index 00000000..d8987252
--- /dev/null
+++ b/feature-eelf/src/main/install/config/policyLogger.properties
@@ -0,0 +1,49 @@
+###
+# ============LICENSE_START=======================================================
+# feature-eelf
+# ================================================================================
+# Copyright (C) 2017 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=========================================================
+###
+
+################################### Set concurrentHashMap and timer info #######################
+#Timer initial delay and the delay between in milliseconds before task is to be execute.
+timer.delay.time=1000
+#Timer scheduleAtFixedRate period - time in milliseconds between successive task executions.
+check.interval= 30000
+#Longest time an event info can be stored in the concurrentHashMap for logging - in seconds.
+event.expired.time=86400
+#Size of the concurrentHashMap which stores the event starting time, etc - when its size reaches this limit, the Timer gets executed
+#to remove all expired records from this concurrentHashMap.
+concurrentHashMap.limit=5000
+#Size of the concurrentHashMap - when its size drops to this point, stop the Timer
+stop.check.point=2500
+################################### Set logging format #############################################
+# set EELF for EELF logging format, set LOG4J for using log4j, set SYSTEMOUT for using system.out.println
+logger.type=EELF
+#################################### Set level for EELF or SYSTEMOUT logging ##################################
+# Set level for debug file. Set DEBUG to enable .info, .warn and .debug; set INFO for enable .info and .warn; set OFF to disable all
+# Set override flag. Set TRUE for override the level setups in logback.xml. Set FALSE for using the level setups of logback.xml
+override.logback.level.setup=FALSE
+debugLogger.level=INFO
+# Set level for metrics file. Set OFF to disable; set ON to enable
+metricsLogger.level=ON
+# Set level for error file. Set OFF to disable; set ON to enable
+error.level=ON
+# Set level for audit file. Set OFF to disable; set ON to enable
+audit.level=ON
+#################################### Set Policy Component ##################################
+# Set DROOLS for drools PDP. Set XACML to xacml PDP
+policy.component=DROOLS
diff --git a/feature-eelf/src/main/java/org/openecomp/policy/drools/eelf/EelfFeature.java b/feature-eelf/src/main/java/org/openecomp/policy/drools/eelf/EelfFeature.java
new file mode 100644
index 00000000..de39f3a3
--- /dev/null
+++ b/feature-eelf/src/main/java/org/openecomp/policy/drools/eelf/EelfFeature.java
@@ -0,0 +1,89 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * feature-eelf
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.policy.drools.eelf;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
+import org.openecomp.policy.common.logging.flexlogger.Logger;
+import org.openecomp.policy.drools.features.PolicyEngineFeatureAPI;
+import org.openecomp.policy.drools.system.Main;
+import org.openecomp.policy.drools.system.PolicyEngine;
+
+public class EelfFeature implements PolicyEngineFeatureAPI {
+
+ /**
+ * EELF logback configuration path system property
+ */
+ public static final String EELF_LOGBACK_PATH_SYSTEM_PROPERTY = "com.att.eelf.logging.file";
+
+ /**
+ * EELF logback configuration path value
+ */
+ public static final String EELF_LOGBACK_PATH_DEFAULT = "config";
+
+ /**
+ * EELF logback configuration file system property
+ */
+ public static final String EELF_LOGBACK_FILE_SYSTEM_PROPERTY = "com.att.eelf.logging.path";
+
+ /**
+ * EELF logback configuration file default value
+ */
+ public static final String EELF_LOGBACK_FILE_DEFAULT = "logback.xml";
+
+ @Override
+ public boolean beforeBoot(PolicyEngine engine, String cliArgs[]) {
+
+ String logback = System.getProperty(Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY,
+ Main.LOGBACK_CONFIGURATION_FILE_DEFAULT);
+
+ Path logbackPath = Paths.get(logback);
+
+ if (System.getProperty(EELF_LOGBACK_PATH_SYSTEM_PROPERTY) == null)
+ System.setProperty(EELF_LOGBACK_PATH_SYSTEM_PROPERTY, logbackPath.getFileName().toString());
+
+ if (System.getProperty(EELF_LOGBACK_FILE_SYSTEM_PROPERTY) == null)
+ System.setProperty(EELF_LOGBACK_FILE_SYSTEM_PROPERTY,
+ logbackPath.toAbsolutePath().getParent().toString());
+
+ Logger logger = FlexLogger.getLogger(this.getClass(), true);
+
+ logger.warn("EELF/Common Frameworks Logging Enabled");
+ if (logger.isInfoEnabled()) {
+ logger.info("EELFFeature: Property " + Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY + "=" +
+ System.getProperty(Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY));
+ logger.info("EELFFeature: Property " + EELF_LOGBACK_PATH_SYSTEM_PROPERTY + "=" +
+ System.getProperty(EELF_LOGBACK_PATH_SYSTEM_PROPERTY));
+ logger.info("EELFFeature: Property " + EELF_LOGBACK_FILE_SYSTEM_PROPERTY + "=" +
+ System.getProperty(EELF_LOGBACK_FILE_SYSTEM_PROPERTY));
+ }
+
+ return false;
+ };
+
+ @Override
+ public int getSequenceNumber() {
+ return 0;
+ }
+
+}
diff --git a/feature-eelf/src/main/resources/META-INF/services/org.openecomp.policy.drools.features.PolicyEngineFeatureAPI b/feature-eelf/src/main/resources/META-INF/services/org.openecomp.policy.drools.features.PolicyEngineFeatureAPI
new file mode 100644
index 00000000..70d1bb8e
--- /dev/null
+++ b/feature-eelf/src/main/resources/META-INF/services/org.openecomp.policy.drools.features.PolicyEngineFeatureAPI
@@ -0,0 +1 @@
+org.openecomp.policy.drools.eelf.EelfFeature
diff --git a/feature-eelf/src/test/java/org/openecomp/policy/drools/eelf/test/EElfTest.java b/feature-eelf/src/test/java/org/openecomp/policy/drools/eelf/test/EElfTest.java
new file mode 100644
index 00000000..2ded0d0d
--- /dev/null
+++ b/feature-eelf/src/test/java/org/openecomp/policy/drools/eelf/test/EElfTest.java
@@ -0,0 +1,138 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * feature-eelf
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.policy.drools.eelf.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
+import org.openecomp.policy.drools.eelf.EelfFeature;
+import org.openecomp.policy.drools.system.Main;
+import org.openecomp.policy.drools.system.PolicyEngine;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.att.eelf.configuration.Configuration;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFLogger.Level;
+import com.att.eelf.configuration.EELFManager;
+
+import ch.qos.logback.classic.LoggerContext;
+
+/**
+ * Logger Tests
+ */
+public class EElfTest {
+
+ /**
+ * logback configuration location
+ */
+ public final static String LOGBACK_CONFIGURATION_FILE_DEFAULT = "src/main/install/config/logback.xml";
+
+ /**
+ * SLF4J Logger
+ */
+ private final Logger slf4jLogger = LoggerFactory.getLogger(EElfTest.class);
+
+ /**
+ * get all loggers
+ * @return list of all loggers
+ */
+ protected List<String> loggers() {
+ List<String> loggers = new ArrayList<String>();
+ LoggerContext context =
+ (LoggerContext) org.slf4j.LoggerFactory.getILoggerFactory();
+ for (org.slf4j.Logger logger: context.getLoggerList()) {
+ loggers.add(logger.getName());
+ }
+ slf4jLogger.info(loggers.toString());
+ return loggers;
+ }
+
+ /**
+ * Assert Log Levels are the same between an EELF Logger and an SLF4J Logger
+ *
+ * @param eelfAuditLogger
+ * @param slf4jAuditLogger
+ */
+ protected void assertLogLevels(EELFLogger eelfAuditLogger, Logger slf4jAuditLogger) {
+ assertTrue(slf4jAuditLogger.isDebugEnabled() == eelfAuditLogger.isDebugEnabled());
+ assertTrue(slf4jAuditLogger.isInfoEnabled() == eelfAuditLogger.isInfoEnabled());
+ assertTrue(slf4jAuditLogger.isErrorEnabled() == eelfAuditLogger.isErrorEnabled());
+ assertTrue(slf4jAuditLogger.isWarnEnabled() == eelfAuditLogger.isWarnEnabled());
+ assertTrue(slf4jAuditLogger.isTraceEnabled() == eelfAuditLogger.isTraceEnabled());
+ }
+
+ @Test
+ public void slf4jLog() {
+
+ /* standard slf4j using defaults */
+
+ slf4jLogger.info("slf4j info");
+
+ List<String> loggers = loggers();
+
+ assertFalse(loggers.contains(Configuration.DEBUG_LOGGER_NAME));
+ assertFalse(loggers.contains(Configuration.AUDIT_LOGGER_NAME));
+ assertFalse(loggers.contains(Configuration.ERROR_LOGGER_NAME));
+ assertFalse(loggers.contains(Configuration.METRICS_LOGGER_NAME));
+
+ /* set logback configuration */
+
+ System.setProperty(Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY,
+ LOGBACK_CONFIGURATION_FILE_DEFAULT);
+
+ /* set up eelf throuth common loggings library */
+
+ EelfFeature feature = new EelfFeature();
+ feature.beforeBoot(PolicyEngine.manager, null);
+
+ loggers = loggers();
+ assertTrue(loggers.contains(Configuration.DEBUG_LOGGER_NAME));
+ assertTrue(loggers.contains(Configuration.AUDIT_LOGGER_NAME));
+ assertTrue(loggers.contains(Configuration.ERROR_LOGGER_NAME));
+ assertTrue(loggers.contains(Configuration.METRICS_LOGGER_NAME));
+
+ EELFLogger eelfAuditLogger = EELFManager.getInstance().getAuditLogger();
+ Logger slf4jAuditLogger = org.slf4j.LoggerFactory.getLogger(Configuration.AUDIT_LOGGER_NAME);
+ org.openecomp.policy.common.logging.flexlogger.Logger flexLogger =
+ FlexLogger.getLogger(EElfTest.class);
+
+ /* generate an audit entry through both logs */
+
+ flexLogger.audit("flexlogger audit");
+ eelfAuditLogger.info("eelf audit");
+ slf4jAuditLogger.info("slf4j audit");
+
+ /* check log levels in eelf and standard slf4j change in both directions */
+
+ /* eelf initiated */
+ eelfAuditLogger.setLevel(Level.ERROR);
+ assertLogLevels(eelfAuditLogger, slf4jAuditLogger);
+
+ /* slf4j initiated */
+ ((ch.qos.logback.classic.Logger) slf4jLogger).setLevel((ch.qos.logback.classic.Level.INFO));
+ assertLogLevels(eelfAuditLogger, slf4jAuditLogger);
+ }
+}