aboutsummaryrefslogtreecommitdiffstats
path: root/feature-eelf
diff options
context:
space:
mode:
Diffstat (limited to 'feature-eelf')
-rw-r--r--feature-eelf/src/main/java/org/onap/policy/drools/eelf/EelfFeature.java72
-rw-r--r--feature-eelf/src/test/java/org/onap/policy/drools/eelf/test/EElfTest.java218
2 files changed, 147 insertions, 143 deletions
diff --git a/feature-eelf/src/main/java/org/onap/policy/drools/eelf/EelfFeature.java b/feature-eelf/src/main/java/org/onap/policy/drools/eelf/EelfFeature.java
index aac456e2..bf0f0000 100644
--- a/feature-eelf/src/main/java/org/onap/policy/drools/eelf/EelfFeature.java
+++ b/feature-eelf/src/main/java/org/onap/policy/drools/eelf/EelfFeature.java
@@ -31,43 +31,45 @@ import org.onap.policy.drools.system.Main;
import org.onap.policy.drools.system.PolicyEngine;
/**
- * Feature EELF : Enables EELF Logging Libraries
+ * Feature EELF : Enables EELF Logging Libraries .
*/
public class EelfFeature implements PolicyEngineFeatureAPI {
- @Override
- public final 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(Configuration.PROPERTY_LOGGING_FILE_PATH) == null)
- System.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH,
- logbackPath.toAbsolutePath().getParent().toString());
-
- if (System.getProperty(Configuration.PROPERTY_LOGGING_FILE_NAME) == null)
- System.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME,
- logbackPath.getFileName().toString());
-
- Logger logger = FlexLogger.getLogger(this.getClass(), true);
-
- if (logger.isInfoEnabled()) {
- logProperty(logger, Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY);
- logProperty(logger, Configuration.PROPERTY_LOGGING_FILE_PATH);
- logProperty(logger, Configuration.PROPERTY_LOGGING_FILE_NAME);
- }
-
- return false;
- }
-
- private void logProperty(Logger logger, String propnm) {
- logger.info("eelf-feature: Property " + propnm + "=" + System.getProperty(propnm));
- }
-
- @Override
- public int getSequenceNumber() {
- return 0;
- }
+ @Override
+ public final 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(Configuration.PROPERTY_LOGGING_FILE_PATH) == null) {
+ System.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH,
+ logbackPath.toAbsolutePath().getParent().toString());
+ }
+
+ if (System.getProperty(Configuration.PROPERTY_LOGGING_FILE_NAME) == null) {
+ System.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME,
+ logbackPath.getFileName().toString());
+ }
+
+ Logger logger = FlexLogger.getLogger(this.getClass(), true);
+
+ if (logger.isInfoEnabled()) {
+ logProperty(logger, Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY);
+ logProperty(logger, Configuration.PROPERTY_LOGGING_FILE_PATH);
+ logProperty(logger, Configuration.PROPERTY_LOGGING_FILE_NAME);
+ }
+
+ return false;
+ }
+
+ private void logProperty(Logger logger, String propnm) {
+ logger.info("eelf-feature: Property " + propnm + "=" + System.getProperty(propnm));
+ }
+
+ @Override
+ public int getSequenceNumber() {
+ return 0;
+ }
}
diff --git a/feature-eelf/src/test/java/org/onap/policy/drools/eelf/test/EElfTest.java b/feature-eelf/src/test/java/org/onap/policy/drools/eelf/test/EElfTest.java
index f7003706..7f9e81cc 100644
--- a/feature-eelf/src/test/java/org/onap/policy/drools/eelf/test/EElfTest.java
+++ b/feature-eelf/src/test/java/org/onap/policy/drools/eelf/test/EElfTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* feature-eelf
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-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.
@@ -17,11 +17,19 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.drools.eelf.test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import ch.qos.logback.classic.LoggerContext;
+
+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 java.util.ArrayList;
import java.util.List;
@@ -33,114 +41,108 @@ import org.onap.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
+ * Logger Tests.
*/
public class EElfTest {
-
- /**
- * logback configuration location
- */
- public final static String LOGBACK_CONFIGURATION_FILE_DEFAULT = "src/main/feature/config/logback-eelf.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 eelfLogger EELF Logger
- * @param slf4jLogger SLF4J Logger
- */
- protected void assertLogLevels(EELFLogger eelfLogger, Logger slf4jLogger) {
- assertTrue(slf4jLogger.isDebugEnabled() == eelfLogger.isDebugEnabled());
- assertTrue(slf4jLogger.isInfoEnabled() == eelfLogger.isInfoEnabled());
- assertTrue(slf4jLogger.isErrorEnabled() == eelfLogger.isErrorEnabled());
- assertTrue(slf4jLogger.isWarnEnabled() == eelfLogger.isWarnEnabled());
- assertTrue(slf4jLogger.isTraceEnabled() == eelfLogger.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.onap.policy.common.logging.flexlogger.Logger flexLogger =
- FlexLogger.getLogger(EElfTest.class, true);
-
- /* generate an error entry */
-
- Exception testException = new IllegalStateException("exception test");
- flexLogger.error("flex-logger exception", testException);
- EELFManager.getInstance().getErrorLogger().error("eelf-logger exception", testException);
- org.slf4j.LoggerFactory.getLogger(Configuration.ERROR_LOGGER_NAME).error("slf4j-logger", testException);
-
-
- /* generate an audit entry through all 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);
- }
+
+ /**
+ * logback configuration location.
+ */
+ public static final String LOGBACK_CONFIGURATION_FILE_DEFAULT = "src/main/feature/config/logback-eelf.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 eelfLogger EELF Logger
+ * @param slf4jLogger SLF4J Logger
+ */
+ protected void assertLogLevels(EELFLogger eelfLogger, Logger slf4jLogger) {
+ assertTrue(slf4jLogger.isDebugEnabled() == eelfLogger.isDebugEnabled());
+ assertTrue(slf4jLogger.isInfoEnabled() == eelfLogger.isInfoEnabled());
+ assertTrue(slf4jLogger.isErrorEnabled() == eelfLogger.isErrorEnabled());
+ assertTrue(slf4jLogger.isWarnEnabled() == eelfLogger.isWarnEnabled());
+ assertTrue(slf4jLogger.isTraceEnabled() == eelfLogger.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));
+
+ final EELFLogger eelfAuditLogger = EELFManager.getInstance().getAuditLogger();
+ final Logger slf4jAuditLogger = org.slf4j.LoggerFactory.getLogger(Configuration.AUDIT_LOGGER_NAME);
+ org.onap.policy.common.logging.flexlogger.Logger flexLogger =
+ FlexLogger.getLogger(EElfTest.class, true);
+
+ /* generate an error entry */
+
+ Exception testException = new IllegalStateException("exception test");
+ flexLogger.error("flex-logger exception", testException);
+ EELFManager.getInstance().getErrorLogger().error("eelf-logger exception", testException);
+ org.slf4j.LoggerFactory.getLogger(Configuration.ERROR_LOGGER_NAME).error("slf4j-logger", testException);
+
+
+ /* generate an audit entry through all 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);
+ }
}