aboutsummaryrefslogtreecommitdiffstats
path: root/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger
diff options
context:
space:
mode:
Diffstat (limited to 'common-logging/src/main/java/org/onap/policy/common/logging/flexlogger')
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/EelfLogger.java929
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLogger.java589
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/Logger.java383
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/Logger4J.java912
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/LoggerType.java8
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/PropertyUtil.java667
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/SystemOutLogger.java957
7 files changed, 2246 insertions, 2199 deletions
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/EelfLogger.java b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/EelfLogger.java
index 07ef5626..e0c4144b 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/EelfLogger.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/EelfLogger.java
@@ -20,461 +20,498 @@
package org.onap.policy.common.logging.flexlogger;
+import com.att.eelf.configuration.EELFLogger.Level;
+
import java.io.Serializable;
import java.util.UUID;
import org.onap.policy.common.logging.eelf.MessageCodes;
import org.onap.policy.common.logging.eelf.PolicyLogger;
-import org.onap.policy.common.logging.flexlogger.Logger;
-import com.att.eelf.configuration.EELFLogger.Level;
/**
- *
- * EelfLogger implements all the methods of interface Logger by calling PolicyLogger methods
- *
+ * EelfLogger implements all the methods of interface Logger by calling PolicyLogger methods.
*/
public class EelfLogger implements Logger, Serializable {
-
- /**
- *
- */
- private static final long serialVersionUID = 5385586713941277192L;
- private String className = "";
+
+ private static final long serialVersionUID = 5385586713941277192L;
+ private String className = "";
private String transId = UUID.randomUUID().toString();
-
- /**
- * Constructor
- * @param clazz
- */
- public EelfLogger(Class<?> clazz) {
- if(clazz != null){
- className = clazz.getName();
- }
- PolicyLogger.postMDCInfoForEvent(null);
- }
-
- /**
- * Constructor
- * @param s
- */
- public EelfLogger(String s) {
- if(s != null){
- className = s;
- }
- PolicyLogger.postMDCInfoForEvent(null);
- }
-
- /**
- * Constructor
- * @param clazz
- * @param isNewTransaction
- */
- public EelfLogger(Class<?> clazz, boolean isNewTransaction) {
- if(clazz != null){
- className = clazz.getName();
- }
- if(isNewTransaction){
- transId = PolicyLogger.postMDCInfoForEvent(null);
- }else{
- transId = PolicyLogger.getTransId();
- }
- }
-
- /**
- * Constructor
- * @param s
- * @param isNewTransaction
- */
- public EelfLogger(String s, boolean isNewTransaction) {
- if(s != null){
- className = s;
- }
- if(isNewTransaction){
- transId = PolicyLogger.postMDCInfoForEvent(null);
- }else{
- transId = PolicyLogger.getTransId();
- }
- }
-
- /**
- * Constructor
- * @param clazz
- * @param transId
- */
- public EelfLogger(Class<?> clazz, String transId) {
- if(clazz != null){
- className = clazz.getName();
- }
- PolicyLogger.postMDCInfoForEvent(transId);
- this.transId = transId;
- }
-
- /**
- * Constructor
- * @param s
- * @param transId
- */
- public EelfLogger(String s, String transId) {
- if(s != null){
- className = s;
- }
- PolicyLogger.postMDCInfoForEvent(transId);
- this.transId = transId;
- }
-
- /**
- * Sets transaction Id for logging
- * @param transId
- */
- @Override
- public void setTransId(String transId){
-
- PolicyLogger.setTransId(transId);
- this.transId = transId;
- }
-
- /**
- * Returns transaction Id for logging
- */
- @Override
- public String getTransId(){
- return transId;
- }
-
- /**
- * Records a message
- * @param message
- */
- @Override
- public void debug(Object message) {
- PolicyLogger.debug(className, ""+message);
- }
-
- /**
- * Records an error message
- * @param message
- */
- @Override
- public void error(Object message) {
- PolicyLogger.error(className, ""+message);
- }
-
- /**
- * Records a message
- * @param message
- */
- @Override
- public void info(Object message) {
- PolicyLogger.info(className, ""+message);
- }
-
- /**
- * Records a message
- * @param message
- */
- @Override
- public void warn(Object message) {
- PolicyLogger.warn(className, ""+message);
- }
-
- /**
- * Records a message
- * @param message
- */
- @Override
- public void trace(Object message) {
- PolicyLogger.trace(className, ""+message);
- }
-
- /**
- * Returns true for debug enabled, or false for not
- * @return boolean
- */
- @Override
- public boolean isDebugEnabled(){
- return PolicyLogger.isDebugEnabled();
- }
-
- /**
- * Returns true for info enabled, or false for not
- * @return boolean
- */
- @Override
- public boolean isInfoEnabled(){
- return PolicyLogger.isInfoEnabled();
- }
-
- /**
- * Returns true for warn enabled, or false for not
- * @return boolean
- */
- @Override
- public boolean isWarnEnabled(){
- return PolicyLogger.isWarnEnabled();
- }
-
- /**
- * Returns true for error enabled, or false for not
- * @return boolean
- */
- @Override
- public boolean isErrorEnabled(){
- return PolicyLogger.isErrorEnabled();
- }
-
- /**
- * Returns true for audit enabled, or false for not
- * @return boolean
- */
- @Override
- public boolean isAuditEnabled(){
- return(PolicyLogger.getAuditLevel() != Level.OFF);
- }
-
- /**
- * Returns true for metrics enabled, or false for not
- * @return boolean
- */
- @Override
- public boolean isMetricsEnabled(){
- return(PolicyLogger.getMetricsLevel() != Level.OFF);
- }
-
- /**
- * Returns true for trace enabled, or false for not
- * @return boolean
- */
- @Override
- public boolean isTraceEnabled(){
- return PolicyLogger.isDebugEnabled();
- }
-
- /**
- * Records an audit message
- * @param arg0
- */
- @Override
- public void audit(Object arg0) {
- PolicyLogger.audit(className, ""+ arg0);
- }
-
- /**
- * Records a message
- * @param message
- * @param t
- */
- @Override
- public void debug(Object message, Throwable t) {
- PolicyLogger.debug(MessageCodes.GENERAL_INFO, t, message.toString());
- }
-
- /**
- * Records an error message
- * @param message
- * @param t
- */
- @Override
- public void error(Object message, Throwable t) {
- PolicyLogger.error(MessageCodes.ERROR_UNKNOWN, t, message.toString());
- }
-
- /**
- * Records a message
- * @param message
- * @param t
- */
- @Override
- public void info(Object message, Throwable t) {
- PolicyLogger.info(MessageCodes.GENERAL_INFO, t, message.toString());
- }
-
- /**
- * Records a message
- * @param message
- * @param t
- */
- @Override
- public void warn(Object message, Throwable t) {
- PolicyLogger.warn(MessageCodes.GENERAL_WARNING, t, message.toString());
- }
-
- /**
- * Records a message
- * @param message
- * @param t
- */
- @Override
- public void trace(Object message, Throwable t) {
- PolicyLogger.trace(message);
- }
-
- /**
- * Records an audit message
- * @param arg0
- * @param t
- */
- @Override
- public void audit(Object arg0, Throwable t) {
- PolicyLogger.audit(arg0);
- }
-
- /**
- * Records an audit message
- * @param eventId
- */
- @Override
- public void recordAuditEventStart(String eventId) {
- PolicyLogger.recordAuditEventStart(eventId);
- }
-
- /**
- * Records an audit message
- * @param eventId
- */
- @Override
- public void recordAuditEventStart(UUID eventId) {
- PolicyLogger.recordAuditEventStart(eventId);
- }
-
- /**
- * Records an audit message
- * @param eventId
- * @param rule
- * @param policyVersion
- */
- @Override
- public void recordAuditEventEnd(String eventId, String rule, String policyVersion) {
- PolicyLogger.recordAuditEventEnd(eventId, rule, policyVersion);
- }
-
- /**
- * Records an audit message
- * @param eventId
- * @param rule
- * @param policyVersion
- */
- @Override
- public void recordAuditEventEnd(UUID eventId, String rule, String policyVersion) {
- PolicyLogger.recordAuditEventEnd(eventId, rule, policyVersion);
- }
-
- /**
- * Records an audit message
- * @param eventId
- * @param rule
- */
- @Override
- public void recordAuditEventEnd(String eventId, String rule) {
- PolicyLogger.recordAuditEventEnd(eventId, rule);
- }
-
- /**
- * Records an audit message
- * @param eventId
- * @param rule
- */
- @Override
- public void recordAuditEventEnd(UUID eventId, String rule) {
- PolicyLogger.recordAuditEventEnd(eventId, rule);
- }
-
- /**
- * Records a metrics message
- * @param eventId
- * @param arg1
- */
- @Override
- public void recordMetricEvent(String eventId, String arg1) {
- PolicyLogger.recordMetricEvent(eventId, arg1);
- }
-
- /**
- * Records a metrics message
- * @param eventId
- * @param arg1
- */
- @Override
- public void recordMetricEvent(UUID eventId, String arg1) {
- PolicyLogger.recordMetricEvent(eventId, arg1);
- }
-
- /**
- * Records a metrics message
- * @param arg0
- */
- @Override
- public void metrics(Object arg0) {
- PolicyLogger.metrics(className, arg0);
- }
-
- /**
- * Records an error message
- * @param msg
- * @param arg0
- * @param arguments
- */
- @Override
- public void error(MessageCodes msg, Throwable arg0, String... arguments){
- PolicyLogger.error(msg, className, arg0, arguments);
- }
-
- /**
- * Records an error message
- * @param msg
- * @param arguments
- */
- @Override
- public void error(MessageCodes msg, String... arguments){
- PolicyLogger.error(msg, arguments);
- }
-
- /**
- * Populates MDC Info
- * @param transId
- */
- @Override
- public String postMDCInfoForEvent(String transId) {
- return PolicyLogger.postMDCInfoForEvent(transId);
-
- }
-
- /**
- * Records a message
- * @param msg
- * @param arguments
- */
- @Override
- public void warn(MessageCodes msg, String... arguments){
- PolicyLogger.warn(msg, className, arguments);
- }
-
- /**
- * Records a message
- * @param msg
- * @param arg0
- * @param arguments
- */
- @Override
- public void warn(MessageCodes msg, Throwable arg0, String... arguments){
- PolicyLogger.warn(msg, className, arg0, arguments);
- }
-
- /**
- * Populates MDC Info for the rule triggered
- * @param transId
- */
- @Override
- public void postMDCInfoForTriggeredRule(String transId){
- PolicyLogger.postMDCInfoForTriggeredRule(transId);
- }
-
- /**
- * Populates MDC Info
- * @param o
- */
- @Override
- public void postMDCInfoForEvent(Object o){
- PolicyLogger.postMDCInfoForEvent(o);
- }
+
+ /**
+ * Constructor.
+ *
+ * @param clazz the class
+ */
+ public EelfLogger(Class<?> clazz) {
+ if (clazz != null) {
+ className = clazz.getName();
+ }
+ PolicyLogger.postMDCInfoForEvent(null);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param className the class name
+ */
+ public EelfLogger(String className) {
+ if (className != null) {
+ this.className = className;
+ }
+ PolicyLogger.postMDCInfoForEvent(null);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param clazz the class
+ * @param isNewTransaction is a new transaction
+ */
+ public EelfLogger(Class<?> clazz, boolean isNewTransaction) {
+ if (clazz != null) {
+ className = clazz.getName();
+ }
+ if (isNewTransaction) {
+ transId = PolicyLogger.postMDCInfoForEvent(null);
+ } else {
+ transId = PolicyLogger.getTransId();
+ }
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param className the class name
+ * @param isNewTransaction is a new transaction
+ */
+ public EelfLogger(String className, boolean isNewTransaction) {
+ if (className != null) {
+ this.className = className;
+ }
+ if (isNewTransaction) {
+ transId = PolicyLogger.postMDCInfoForEvent(null);
+ } else {
+ transId = PolicyLogger.getTransId();
+ }
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param clazz the class
+ * @param transId the transaction ID
+ */
+ public EelfLogger(Class<?> clazz, String transId) {
+ if (clazz != null) {
+ className = clazz.getName();
+ }
+ PolicyLogger.postMDCInfoForEvent(transId);
+ this.transId = transId;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param className the class name
+ * @param transId the transaction ID
+ */
+ public EelfLogger(String className, String transId) {
+ if (className != null) {
+ this.className = className;
+ }
+ PolicyLogger.postMDCInfoForEvent(transId);
+ this.transId = transId;
+ }
+
+ /**
+ * Sets transaction Id for logging.
+ *
+ * @param transId the transaction ID
+ */
+ @Override
+ public void setTransId(String transId) {
+
+ PolicyLogger.setTransId(transId);
+ this.transId = transId;
+ }
+
+ /**
+ * Returns transaction Id for logging.
+ */
+ @Override
+ public String getTransId() {
+ return transId;
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void debug(Object message) {
+ PolicyLogger.debug(className, "" + message);
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ @Override
+ public void debug(Object message, Throwable throwable) {
+ PolicyLogger.debug(MessageCodes.GENERAL_INFO, throwable, message.toString());
+ }
+
+ /**
+ * Records an error message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void error(Object message) {
+ PolicyLogger.error(className, "" + message);
+ }
+
+ /**
+ * Records an error message.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ @Override
+ public void error(Object message, Throwable throwable) {
+ PolicyLogger.error(MessageCodes.ERROR_UNKNOWN, throwable, message.toString());
+ }
+
+ /**
+ * Records an error message.
+ *
+ * @param msg the message code
+ * @param throwable the throwable
+ * @param arguments the messages
+ */
+ @Override
+ public void error(MessageCodes msg, Throwable throwable, String... arguments) {
+ PolicyLogger.error(msg, className, throwable, arguments);
+ }
+
+ /**
+ * Records an error message.
+ *
+ * @param msg the message code
+ * @param arguments the messages
+ */
+ @Override
+ public void error(MessageCodes msg, String... arguments) {
+ PolicyLogger.error(msg, arguments);
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void info(Object message) {
+ PolicyLogger.info(className, "" + message);
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ @Override
+ public void info(Object message, Throwable throwable) {
+ PolicyLogger.info(MessageCodes.GENERAL_INFO, throwable, message.toString());
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void warn(Object message) {
+ PolicyLogger.warn(className, "" + message);
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ @Override
+ public void warn(Object message, Throwable throwable) {
+ PolicyLogger.warn(MessageCodes.GENERAL_WARNING, throwable, message.toString());
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param msg the message codes
+ * @param arguments the messages
+ */
+ @Override
+ public void warn(MessageCodes msg, String... arguments) {
+ PolicyLogger.warn(msg, className, arguments);
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param msg the message
+ * @param throwable the throwable
+ * @param arguments the messages
+ */
+ @Override
+ public void warn(MessageCodes msg, Throwable throwable, String... arguments) {
+ PolicyLogger.warn(msg, className, throwable, arguments);
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void trace(Object message) {
+ PolicyLogger.trace(className, "" + message);
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ @Override
+ public void trace(Object message, Throwable throwable) {
+ PolicyLogger.trace(message);
+ }
+
+ /**
+ * Returns true for debug enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isDebugEnabled() {
+ return PolicyLogger.isDebugEnabled();
+ }
+
+ /**
+ * Returns true for info enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isInfoEnabled() {
+ return PolicyLogger.isInfoEnabled();
+ }
+
+ /**
+ * Returns true for warn enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isWarnEnabled() {
+ return PolicyLogger.isWarnEnabled();
+ }
+
+ /**
+ * Returns true for error enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isErrorEnabled() {
+ return PolicyLogger.isErrorEnabled();
+ }
+
+ /**
+ * Returns true for audit enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isAuditEnabled() {
+ return (PolicyLogger.getAuditLevel() != Level.OFF);
+ }
+
+ /**
+ * Returns true for metrics enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isMetricsEnabled() {
+ return (PolicyLogger.getMetricsLevel() != Level.OFF);
+ }
+
+ /**
+ * Returns true for trace enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isTraceEnabled() {
+ return PolicyLogger.isDebugEnabled();
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param arg0 the message
+ */
+ @Override
+ public void audit(Object arg0) {
+ PolicyLogger.audit(className, "" + arg0);
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ @Override
+ public void audit(Object message, Throwable throwable) {
+ PolicyLogger.audit(message);
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param eventId the event ID
+ */
+ @Override
+ public void recordAuditEventStart(String eventId) {
+ PolicyLogger.recordAuditEventStart(eventId);
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param eventId the event ID
+ */
+ @Override
+ public void recordAuditEventStart(UUID eventId) {
+ PolicyLogger.recordAuditEventStart(eventId);
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param eventId the event ID
+ * @param rule the rule
+ * @param policyVersion the policy cersion
+ */
+ @Override
+ public void recordAuditEventEnd(String eventId, String rule, String policyVersion) {
+ PolicyLogger.recordAuditEventEnd(eventId, rule, policyVersion);
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param eventId the event ID
+ * @param rule the rule
+ * @param policyVersion the policy version
+ */
+ @Override
+ public void recordAuditEventEnd(UUID eventId, String rule, String policyVersion) {
+ PolicyLogger.recordAuditEventEnd(eventId, rule, policyVersion);
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param eventId the event ID
+ * @param rule the rule
+ */
+ @Override
+ public void recordAuditEventEnd(String eventId, String rule) {
+ PolicyLogger.recordAuditEventEnd(eventId, rule);
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param eventId the event ID
+ * @param rule the rule
+ */
+ @Override
+ public void recordAuditEventEnd(UUID eventId, String rule) {
+ PolicyLogger.recordAuditEventEnd(eventId, rule);
+ }
+
+ /**
+ * Records a metrics message.
+ *
+ * @param eventId the event ID
+ * @param message the message
+ */
+ @Override
+ public void recordMetricEvent(String eventId, String message) {
+ PolicyLogger.recordMetricEvent(eventId, message);
+ }
+
+ /**
+ * Records a metrics message.
+ *
+ * @param eventId the event ID
+ * @param message the message
+ */
+ @Override
+ public void recordMetricEvent(UUID eventId, String message) {
+ PolicyLogger.recordMetricEvent(eventId, message);
+ }
+
+ /**
+ * Records a metrics message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void metrics(Object message) {
+ PolicyLogger.metrics(className, message);
+ }
+
+ /**
+ * Populates MDC Info.
+ *
+ * @param transId the transaction ID
+ */
+ @Override
+ public String postMDCInfoForEvent(String transId) {
+ return PolicyLogger.postMDCInfoForEvent(transId);
+ }
+
+ /**
+ * Populates MDC Info.
+ *
+ * @param obj the object
+ */
+ @Override
+ public void postMDCInfoForEvent(Object obj) {
+ PolicyLogger.postMDCInfoForEvent(obj);
+ }
+
+ /**
+ * Populates MDC Info for the rule triggered.
+ *
+ * @param transId the transaction ID
+ */
+ @Override
+ public void postMDCInfoForTriggeredRule(String transId) {
+ PolicyLogger.postMDCInfoForTriggeredRule(transId);
+ }
+
}
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLogger.java b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLogger.java
index 9723755e..90240a77 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLogger.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLogger.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-Logging
* ================================================================================
- * 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.
@@ -32,300 +32,305 @@ import org.onap.policy.common.logging.eelf.PolicyLogger;
import org.onap.policy.common.logging.flexlogger.PropertyUtil.Listener;
/**
- *
- * FlexLogger acts as factory to generate instances of Logger based on logger type
- *
+ * FlexLogger acts as factory to generate instances of Logger based on logger type.
*/
-public class FlexLogger extends SecurityManager{
+public class FlexLogger extends SecurityManager {
- private static final String GET_LOGGER_PREFIX = "FlexLogger:getLogger : loggerType = ";
- private static LoggerType loggerType = LoggerType.EELF;
+ private static final String GET_LOGGER_PREFIX = "FlexLogger:getLogger : loggerType = ";
+ private static LoggerType loggerType = LoggerType.EELF;
private static ConcurrentHashMap<String, Logger4J> logger4JMap = new ConcurrentHashMap<>();
private static ConcurrentHashMap<String, EelfLogger> eelfLoggerMap = new ConcurrentHashMap<>();
private static ConcurrentHashMap<String, SystemOutLogger> systemOutMap = new ConcurrentHashMap<>();
- //--- init logger first
- static {
- loggerType = initlogger();
- }
-
- /**
- * Returns an instance of Logger
- * @param clazz
- */
- public static Logger getLogger(Class<?> clazz) {
- Logger logger = null;
- System.out.println(GET_LOGGER_PREFIX + loggerType);
- switch (loggerType) {
-
- case EELF:
- logger = getEelfLogger(clazz, false);
- break;
- case LOG4J:
- logger = getLog4JLogger();
- break;
- case SYSTEMOUT:
- logger = getSystemOutLogger();
- break;
- }
-
- return logger;
-
- }
-
- /**
- * Returns an instance of Logger
- * @param s
- */
- public static Logger getLogger(String s) {
- Logger logger = null;
- System.out.println(GET_LOGGER_PREFIX + loggerType);
- switch (loggerType) {
-
- case EELF:
- logger = getEelfLogger(null,false);
- break;
- case LOG4J:
- logger = getLog4JLogger(s);
- break;
- case SYSTEMOUT:
- logger = getSystemOutLogger();
- break;
- }
-
- return logger;
-
- }
-
- /**
- * Returns an instance of Logger
- * @param clazz
- * @param isNewTransaction
- */
- public static Logger getLogger(Class<?> clazz, boolean isNewTransaction) {
- Logger logger = null;
- System.out.println(GET_LOGGER_PREFIX + loggerType);
- switch (loggerType) {
-
- case EELF:
- logger = getEelfLogger(clazz, isNewTransaction);
- break;
- case LOG4J:
- logger = getLog4JLogger();
- break;
- case SYSTEMOUT:
- logger = getSystemOutLogger();
- break;
- }
-
- return logger;
-
- }
-
- /**
- * Returns an instance of Logger
- * @param s
- * @param isNewTransaction
- */
- public static Logger getLogger(String s, boolean isNewTransaction) {
- Logger logger = null;
- System.out.println(GET_LOGGER_PREFIX + loggerType);
- switch (loggerType) {
-
- case EELF:
- logger = getEelfLogger(null, isNewTransaction);
- break;
- case LOG4J:
- logger = getLog4JLogger(s);
- break;
- case SYSTEMOUT:
- logger = getSystemOutLogger();
- break;
- }
-
- return logger;
- }
-
- /**
- * Returns the calling class name
- */
- public String getClassName(){
- System.out.println("getClassContext()[3].getName() " + getClassContext()[3].getName());
- return getClassContext()[3].getName();
- }
-
- /**
- * Returns an instance of Logger4J
- * @param clazz
- */
- private static Logger4J getLog4JLogger(){
- String className = new FlexLogger().getClassName();
-
- if(!logger4JMap.containsKey(className)){
- //for 1610 release use the default debug.log for log4j
- Logger4J logger = new Logger4J("debugLogger", className);
- logger4JMap.put(className, logger);
- }
-
- return logger4JMap.get(className);
- }
-
- /**
- * Returns an instance of Logger4J
- * @param s
- */
- private static Logger4J getLog4JLogger(String s){
- String className = new FlexLogger().getClassName();
-
- if(!logger4JMap.containsKey(className)){
- Logger4J logger = new Logger4J(s, className);
- logger4JMap.put(className, logger);
- }
-
- return logger4JMap.get(className);
- }
-
- /**
- * Returns an instance of EelfLogger
- * @param clazz
- * @param isNewTransaction
- */
- private static EelfLogger getEelfLogger(Class<?> clazz, boolean isNewTransaction){
-
- String className;
- EelfLogger logger;
- if(clazz != null){
- className = clazz.getName();
- }else{
- className = new FlexLogger().getClassName();
- }
-
- if(!eelfLoggerMap.containsKey(className)){
- logger = new EelfLogger(clazz, isNewTransaction);
- eelfLoggerMap.put(className, logger);
- }else{
- logger = eelfLoggerMap.get(className);
- if(logger == null){
- logger = new EelfLogger(clazz, isNewTransaction);
- eelfLoggerMap.put(className, logger);
- }
- //installl already created but it is new transaction
- if(isNewTransaction){
- String transId = PolicyLogger.postMDCInfoForEvent(null);
- logger.setTransId(transId);
- }
- }
- System.out.println("eelfLoggerMap size : " + eelfLoggerMap.size() + " class name: " + className);
- return logger;
- }
-
- /**
- * Returns an instance of SystemOutLogger
- * @param clazz
- */
- private static SystemOutLogger getSystemOutLogger(){
-
- String className = new FlexLogger().getClassName();
-
- if(!systemOutMap.containsKey(className)){
- SystemOutLogger logger = new SystemOutLogger(className);
- systemOutMap.put(className, logger);
- }
-
- return systemOutMap.get(className);
- }
-
- /**
- * loads the logger properties
- */
- private static LoggerType initlogger() {
- LoggerType loggerType = LoggerType.EELF;
- String overrideLogbackLevel = "FALSE";
- String loggerTypeString = "";
- Properties properties = null;
-
- try {
- properties = PropertyUtil.getProperties("config/policyLogger.properties");
- System.out.println("FlexLogger:properties => " + properties);
-
- if(properties != null) {
- overrideLogbackLevel = properties.getProperty("override.logback.level.setup");
- System.out.println("FlexLogger:overrideLogbackLevel => " + overrideLogbackLevel);
- loggerTypeString = properties.getProperty("logger.type");
- if (loggerTypeString != null){
- if ("EELF".equalsIgnoreCase(loggerTypeString)){
- loggerType = LoggerType.EELF;
- if ("TRUE".equalsIgnoreCase(overrideLogbackLevel)) {
- System.out.println("FlexLogger: start listener.");
- properties = PropertyUtil.getProperties
- ("config/policyLogger.properties",
- new PropertiesCallBack("FlexLogger-CallBack"));
- }
- }else if ("LOG4J".equalsIgnoreCase(loggerTypeString)){
- loggerType = LoggerType.LOG4J;
- }else if ("SYSTEMOUT".equalsIgnoreCase(loggerTypeString)){
- loggerType = LoggerType.SYSTEMOUT;
- }
-
- System.out.println("FlexLogger.logger_Type value: " + loggerTypeString);
- }
- }
- } catch (IOException e1) {
- System.out.println("initlogger" + e1);
- } finally {
- // OK to pass no properties (null)
- loggerType = PolicyLogger.init(properties);
- }
-
- return loggerType;
- }
-
- /**
- * PropertiesCallBack is listening any updates on the policyLogger.properties
- */
- public static class PropertiesCallBack implements Listener {
- String name;
-
- public PropertiesCallBack(String name) {
- this.name = name;
- }
-
- /**
- * This method will be called automatically if he policyLogger.properties got updated
- */
- @Override
- public void propertiesChanged(Properties properties,
- Set<String> changedKeys) {
-
- String debugLevel = properties.getProperty("debugLogger.level");
- String metricsLevel = properties.getProperty("metricsLogger.level");
- String auditLevel = properties.getProperty("audit.level");
- String errorLevel = properties.getProperty("error.level");
-
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+00:00");
- Instant startTime = Instant.now();
- String formatedTime = sdf.format(Date.from(startTime));
- System.out.println("FlexLogger.propertiesChanged : called at time : " + formatedTime);
- System.out.println("FlexLogger.propertiesChanged : debugLevel : " + debugLevel);
-
- if (changedKeys != null) {
-
- if (changedKeys.contains("debugLogger.level")) {
- PolicyLogger.setDebugLevel(debugLevel);
- }
-
- if (changedKeys.contains("metricsLogger.level")) {
- PolicyLogger.setMetricsLevel(metricsLevel);
- }
-
- if (changedKeys.contains("error.level")) {
- PolicyLogger.setErrorLevel(errorLevel);
- }
-
- if (changedKeys.contains("audit.level")) {
- PolicyLogger.setAuditLevel(auditLevel);
- }
- }
- }
- }
-
+
+ // --- init logger first
+ static {
+ loggerType = initlogger();
+ }
+
+ /**
+ * Returns an instance of Logger.
+ *
+ * @param clazz the class
+ */
+ public static Logger getLogger(Class<?> clazz) {
+ Logger logger = null;
+ System.out.println(GET_LOGGER_PREFIX + loggerType);
+ switch (loggerType) {
+
+ case EELF:
+ logger = getEelfLogger(clazz, false);
+ break;
+ case LOG4J:
+ logger = getLog4JLogger();
+ break;
+ case SYSTEMOUT:
+ default:
+ logger = getSystemOutLogger();
+ break;
+ }
+
+ return logger;
+
+ }
+
+ /**
+ * Returns an instance of Logger.
+ *
+ * @param name the name of the logger
+ */
+ public static Logger getLogger(String name) {
+ Logger logger = null;
+ System.out.println(GET_LOGGER_PREFIX + loggerType);
+ switch (loggerType) {
+
+ case EELF:
+ logger = getEelfLogger(null, false);
+ break;
+ case LOG4J:
+ logger = getLog4JLogger(name);
+ break;
+ case SYSTEMOUT:
+ default:
+ logger = getSystemOutLogger();
+ break;
+ }
+
+ return logger;
+
+ }
+
+ /**
+ * Returns an instance of Logger.
+ *
+ * @param clazz the class
+ * @param isNewTransaction is a new transaction
+ */
+ public static Logger getLogger(Class<?> clazz, boolean isNewTransaction) {
+ Logger logger = null;
+ System.out.println(GET_LOGGER_PREFIX + loggerType);
+ switch (loggerType) {
+
+ case EELF:
+ logger = getEelfLogger(clazz, isNewTransaction);
+ break;
+ case LOG4J:
+ logger = getLog4JLogger();
+ break;
+ case SYSTEMOUT:
+ default:
+ logger = getSystemOutLogger();
+ break;
+ }
+
+ return logger;
+
+ }
+
+ /**
+ * Returns an instance of Logger.
+ *
+ * @param name the name of the logger
+ * @param isNewTransaction is a new transaction
+ */
+ public static Logger getLogger(String name, boolean isNewTransaction) {
+ Logger logger = null;
+ System.out.println(GET_LOGGER_PREFIX + loggerType);
+ switch (loggerType) {
+
+ case EELF:
+ logger = getEelfLogger(null, isNewTransaction);
+ break;
+ case LOG4J:
+ logger = getLog4JLogger(name);
+ break;
+ case SYSTEMOUT:
+ default:
+ logger = getSystemOutLogger();
+ break;
+ }
+
+ return logger;
+ }
+
+ /**
+ * Returns the calling class name.
+ */
+ public String getClassName() {
+ System.out.println("getClassContext()[3].getName() " + getClassContext()[3].getName());
+ return getClassContext()[3].getName();
+ }
+
+ /**
+ * Returns an instance of Logger4J.
+ */
+ private static Logger4J getLog4JLogger() {
+ String className = new FlexLogger().getClassName();
+
+ if (!logger4JMap.containsKey(className)) {
+ // for 1610 release use the default debug.log for log4j
+ Logger4J logger = new Logger4J("debugLogger", className);
+ logger4JMap.put(className, logger);
+ }
+
+ return logger4JMap.get(className);
+ }
+
+ /**
+ * Returns an instance of Logger4J.
+ *
+ * @param name the name of the logger
+ */
+ private static Logger4J getLog4JLogger(String name) {
+ String className = new FlexLogger().getClassName();
+
+ if (!logger4JMap.containsKey(className)) {
+ Logger4J logger = new Logger4J(name, className);
+ logger4JMap.put(className, logger);
+ }
+
+ return logger4JMap.get(className);
+ }
+
+ /**
+ * Returns an instance of EelfLogger.
+ *
+ * @param clazz the class
+ * @param isNewTransaction is a new transaction
+ */
+ private static EelfLogger getEelfLogger(Class<?> clazz, boolean isNewTransaction) {
+
+ String className;
+ EelfLogger logger;
+ if (clazz != null) {
+ className = clazz.getName();
+ } else {
+ className = new FlexLogger().getClassName();
+ }
+
+ if (!eelfLoggerMap.containsKey(className)) {
+ logger = new EelfLogger(clazz, isNewTransaction);
+ eelfLoggerMap.put(className, logger);
+ } else {
+ logger = eelfLoggerMap.get(className);
+ if (logger == null) {
+ logger = new EelfLogger(clazz, isNewTransaction);
+ eelfLoggerMap.put(className, logger);
+ }
+ // installl already created but it is new transaction
+ if (isNewTransaction) {
+ String transId = PolicyLogger.postMDCInfoForEvent(null);
+ logger.setTransId(transId);
+ }
+ }
+ System.out.println("eelfLoggerMap size : " + eelfLoggerMap.size() + " class name: " + className);
+ return logger;
+ }
+
+ /**
+ * Returns an instance of SystemOutLogger.
+ */
+ private static SystemOutLogger getSystemOutLogger() {
+
+ String className = new FlexLogger().getClassName();
+
+ if (!systemOutMap.containsKey(className)) {
+ SystemOutLogger logger = new SystemOutLogger(className);
+ systemOutMap.put(className, logger);
+ }
+
+ return systemOutMap.get(className);
+ }
+
+ /**
+ * loads the logger properties.
+ */
+ private static LoggerType initlogger() {
+ LoggerType loggerType = LoggerType.EELF;
+ String overrideLogbackLevel = "FALSE";
+ String loggerTypeString = "";
+ Properties properties = null;
+
+ try {
+ properties = PropertyUtil.getProperties("config/policyLogger.properties");
+ System.out.println("FlexLogger:properties => " + properties);
+
+ if (properties != null) {
+ overrideLogbackLevel = properties.getProperty("override.logback.level.setup");
+ System.out.println("FlexLogger:overrideLogbackLevel => " + overrideLogbackLevel);
+ loggerTypeString = properties.getProperty("logger.type");
+ if (loggerTypeString != null) {
+ if ("EELF".equalsIgnoreCase(loggerTypeString)) {
+ loggerType = LoggerType.EELF;
+ if ("TRUE".equalsIgnoreCase(overrideLogbackLevel)) {
+ System.out.println("FlexLogger: start listener.");
+ properties = PropertyUtil.getProperties("config/policyLogger.properties",
+ new PropertiesCallBack("FlexLogger-CallBack"));
+ }
+ } else if ("LOG4J".equalsIgnoreCase(loggerTypeString)) {
+ loggerType = LoggerType.LOG4J;
+ } else if ("SYSTEMOUT".equalsIgnoreCase(loggerTypeString)) {
+ loggerType = LoggerType.SYSTEMOUT;
+ }
+
+ System.out.println("FlexLogger.logger_Type value: " + loggerTypeString);
+ }
+ }
+ } catch (IOException e1) {
+ System.out.println("initlogger" + e1);
+ } finally {
+ // OK to pass no properties (null)
+ loggerType = PolicyLogger.init(properties);
+ }
+
+ return loggerType;
+ }
+
+ /**
+ * PropertiesCallBack is listening any updates on the policyLogger.properties
+ */
+ public static class PropertiesCallBack implements Listener {
+ String name;
+
+ public PropertiesCallBack(String name) {
+ this.name = name;
+ }
+
+ /**
+ * This method will be called automatically if he policyLogger.properties got updated
+ */
+ @Override
+ public void propertiesChanged(Properties properties, Set<String> changedKeys) {
+
+ String debugLevel = properties.getProperty("debugLogger.level");
+ String metricsLevel = properties.getProperty("metricsLogger.level");
+ String auditLevel = properties.getProperty("audit.level");
+ String errorLevel = properties.getProperty("error.level");
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+00:00");
+ Instant startTime = Instant.now();
+ String formatedTime = sdf.format(Date.from(startTime));
+ System.out.println("FlexLogger.propertiesChanged : called at time : " + formatedTime);
+ System.out.println("FlexLogger.propertiesChanged : debugLevel : " + debugLevel);
+
+ if (changedKeys != null) {
+
+ if (changedKeys.contains("debugLogger.level")) {
+ PolicyLogger.setDebugLevel(debugLevel);
+ }
+
+ if (changedKeys.contains("metricsLogger.level")) {
+ PolicyLogger.setMetricsLevel(metricsLevel);
+ }
+
+ if (changedKeys.contains("error.level")) {
+ PolicyLogger.setErrorLevel(errorLevel);
+ }
+
+ if (changedKeys.contains("audit.level")) {
+ PolicyLogger.setAuditLevel(auditLevel);
+ }
+ }
+ }
+ }
+
}
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/Logger.java b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/Logger.java
index d3113d31..f74aca14 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/Logger.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/Logger.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-Logging
* ================================================================================
- * 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.
@@ -25,197 +25,196 @@ import java.util.UUID;
import org.onap.policy.common.logging.eelf.MessageCodes;
/**
- *
- * Interface Logger - implemented by Logger4J, EelfLogger and SystemOutLogger
+ * Interface Logger - implemented by Logger4J, EelfLogger and SystemOutLogger.
*
*/
-public interface Logger {
-
- /**
- * Prints messages with the level.DEBUG
- */
- public void debug(Object message);
-
- /**
- * Prints messages with the level.ERROR
- */
- public void error(Object message);
-
- /**
- * Prints messages with the level.ERROR
- */
- public void error(MessageCodes msg, Throwable arg0, String... arguments);
-
- /**
- * Prints messages with the level.INFO
- */
- public void info(Object message);
-
- /**
- * Prints messages with the level.WARN
- */
- public void warn(Object message);
-
- /**
- * Prints messages with the level.TRACE
- */
- public void trace(Object message);
-
- /**
- * Prints messages in audit log with the level.INFO
- */
- public void audit(Object arg0);
-
- /**
- * Prints messages with the level.DEBUG
- */
- public void debug(Object message, Throwable t);
-
- /**
- * Prints messages with the level.ERROR
- */
- public void error(Object message, Throwable t);
-
- /**
- * Prints messages with the level.INFO
- */
- public void info(Object message, Throwable t);
-
- /**
- * Prints messages with the level.WARN
- */
- public void warn(Object message, Throwable t);
-
- /**
- * Prints messages with the level.TRACE
- */
- public void trace(Object message, Throwable t);
-
- /**
- * Prints messages in audit log with the level.INFO
- */
- public void audit(Object arg0, Throwable t);
-
- /**
- * Records event Id in audit log with the level.INFO
- */
- public void recordAuditEventStart(String eventId);
-
- /**
- * Records the starting time of the event with its request Id as the key
- */
- public void recordAuditEventStart(UUID eventId);
-
- /**
- * Records the ending time of the event with its request Id as the key
- */
- public void recordAuditEventEnd(String eventId, String rule, String policyVersion );
-
- /**
- * Records the ending time of the event with its request Id as the key
- */
- public void recordAuditEventEnd(UUID eventId, String rule, String policyVersion);
-
- /**
- * Records the ending time of the event with its request Id as the key
- */
- public void recordAuditEventEnd(String eventId, String rule);
-
- /**
- * Records the ending time of the event with its request Id as the key
- */
- public void recordAuditEventEnd(UUID eventId, String rule);
-
-
- /**
- * Records the Metrics with event Id and log message
- */
- public void recordMetricEvent(String eventId, String arg1);
-
- /**
- * Records the Metrics with event Id and log message
- */
- public void recordMetricEvent(UUID eventId, String arg1);
-
- /**
- * Records the Metrics log message
- */
- public void metrics(Object arg0);
-
- /**
- * Returns a boolean value, true for debug logging enabled, false for not enabled
- */
- public boolean isDebugEnabled();
-
- /**
- * Returns a boolean value, true for error logging enabled, false for not enabled
- */
- public boolean isErrorEnabled();
-
- /**
- * Returns a boolean value, true for warn logging enabled, false for not enabled
- */
- public boolean isWarnEnabled();
-
- /**
- * Returns a boolean value, true for info logging enabled, false for not enabled
- */
- public boolean isInfoEnabled();
-
- /**
- * Returns a boolean value, true for error logging enabled, false for not enabled
- */
- public boolean isAuditEnabled();
-
- /**
- * Returns a boolean value, true for warn logging enabled, false for not enabled
- */
- public boolean isMetricsEnabled();
-
- /**
- * Returns a boolean value, true for trace logging enabled, false for not enabled
- */
- public boolean isTraceEnabled();
-
-
- /**
- * Populates MDC info
- */
- public String postMDCInfoForEvent(String transId);
-
- /**
- * Prints messages with the level.WARN
- */
- public void warn(MessageCodes msg, String... arguments) ;
-
- /**
- * Prints messages with the level.WARN
- */
- public void warn(MessageCodes msg, Throwable arg0, String... arguments) ;
-
- /**
- * Prints messages with the level.ERROR
- */
- public void error(MessageCodes msg, String... arguments) ;
-
- /**
- * Sets transaction Id
- */
- public void setTransId(String transId);
-
- /**
- * Returns transaction Id
- */
- String getTransId();
-
- /**
- * Populates MDC Info for the rule triggered
- */
- public void postMDCInfoForTriggeredRule(String transId);
-
- /**
- * Populates MDC Info
- */
- public void postMDCInfoForEvent(Object o);
-
+public interface Logger {
+
+ /**
+ * Prints messages with the level.DEBUG
+ */
+ public void debug(Object message);
+
+ /**
+ * Prints messages with the level.DEBUG
+ */
+ public void debug(Object message, Throwable throwable);
+
+ /**
+ * Prints messages with the level.ERROR
+ */
+ public void error(Object message);
+
+ /**
+ * Prints messages with the level.ERROR
+ */
+ public void error(Object message, Throwable throwable);
+
+ /**
+ * Prints messages with the level.ERROR
+ */
+ public void error(MessageCodes msg, String... arguments);
+
+ /**
+ * Prints messages with the level.ERROR
+ */
+ public void error(MessageCodes msg, Throwable arg0, String... arguments);
+
+ /**
+ * Prints messages with the level.INFO
+ */
+ public void info(Object message);
+
+ /**
+ * Prints messages with the level.INFO
+ */
+ public void info(Object message, Throwable throwable);
+
+ /**
+ * Prints messages with the level.WARN
+ */
+ public void warn(Object message);
+
+ /**
+ * Prints messages with the level.WARN
+ */
+ public void warn(Object message, Throwable throwable);
+
+ /**
+ * Prints messages with the level.WARN
+ */
+ public void warn(MessageCodes msg, String... arguments);
+
+ /**
+ * Prints messages with the level.WARN
+ */
+ public void warn(MessageCodes msg, Throwable arg0, String... arguments);
+
+ /**
+ * Prints messages with the level.TRACE
+ */
+ public void trace(Object message);
+
+ /**
+ * Prints messages with the level.TRACE
+ */
+ public void trace(Object message, Throwable throwable);
+
+ /**
+ * Prints messages in audit log with the level.INFO
+ */
+ public void audit(Object arg0);
+
+ /**
+ * Prints messages in audit log with the level.INFO
+ */
+ public void audit(Object arg0, Throwable throwable);
+
+ /**
+ * Records event Id in audit log with the level.INFO
+ */
+ public void recordAuditEventStart(String eventId);
+
+ /**
+ * Records the starting time of the event with its request Id as the key.
+ */
+ public void recordAuditEventStart(UUID eventId);
+
+ /**
+ * Records the ending time of the event with its request Id as the key.
+ */
+ public void recordAuditEventEnd(String eventId, String rule, String policyVersion);
+
+ /**
+ * Records the ending time of the event with its request Id as the key.
+ */
+ public void recordAuditEventEnd(UUID eventId, String rule, String policyVersion);
+
+ /**
+ * Records the ending time of the event with its request Id as the key.
+ */
+ public void recordAuditEventEnd(String eventId, String rule);
+
+ /**
+ * Records the ending time of the event with its request Id as the key.
+ */
+ public void recordAuditEventEnd(UUID eventId, String rule);
+
+
+ /**
+ * Records the Metrics with event Id and log message.
+ */
+ public void recordMetricEvent(String eventId, String arg1);
+
+ /**
+ * Records the Metrics with event Id and log message.
+ */
+ public void recordMetricEvent(UUID eventId, String arg1);
+
+ /**
+ * Records the Metrics log message.
+ */
+ public void metrics(Object arg0);
+
+ /**
+ * Returns a boolean value, true for debug logging enabled, false for not enabled.
+ */
+ public boolean isDebugEnabled();
+
+ /**
+ * Returns a boolean value, true for error logging enabled, false for not enabled.
+ */
+ public boolean isErrorEnabled();
+
+ /**
+ * Returns a boolean value, true for warn logging enabled, false for not enabled.
+ */
+ public boolean isWarnEnabled();
+
+ /**
+ * Returns a boolean value, true for info logging enabled, false for not enabled.
+ */
+ public boolean isInfoEnabled();
+
+ /**
+ * Returns a boolean value, true for error logging enabled, false for not enabled.
+ */
+ public boolean isAuditEnabled();
+
+ /**
+ * Returns a boolean value, true for warn logging enabled, false for not enabled.
+ */
+ public boolean isMetricsEnabled();
+
+ /**
+ * Returns a boolean value, true for trace logging enabled, false for not enabled.
+ */
+ public boolean isTraceEnabled();
+
+
+ /**
+ * Populates MDC info.
+ */
+ public String postMDCInfoForEvent(String transId);
+
+ /**
+ * Populates MDC Info.
+ */
+ public void postMDCInfoForEvent(Object obj);
+
+ /**
+ * Sets transaction Id.
+ */
+ public void setTransId(String transId);
+
+ /**
+ * Returns transaction Id.
+ */
+ String getTransId();
+
+ /**
+ * Populates MDC Info for the rule triggered.
+ */
+ public void postMDCInfoForTriggeredRule(String transId);
+
}
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/Logger4J.java b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/Logger4J.java
index 555620f2..88d3800a 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/Logger4J.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/Logger4J.java
@@ -20,6 +20,8 @@
package org.onap.policy.common.logging.flexlogger;
+import com.att.eelf.configuration.EELFLogger.Level;
+
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -29,454 +31,482 @@ import java.util.UUID;
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
-
import org.onap.policy.common.logging.eelf.MessageCodes;
import org.onap.policy.common.logging.eelf.PolicyLogger;
-import com.att.eelf.configuration.EELFLogger.Level;
/**
- *
* Logger4J implements all the methods of interface Logger by calling org.apache.log4j.Logger
- *
*/
public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logger, Serializable {
-
- /**
- *
- */
- private static final long serialVersionUID = 3183729429888828471L;
- private Logger log = null;
+
+ private static final long serialVersionUID = 3183729429888828471L;
+ private Logger log = null;
private String methodName = "";
private String className = "";
- private String transId = UUID.randomUUID().toString();
-
- /**
- * Constructor
- * @param clazz
- */
- public Logger4J (Class<?> clazz){
- System.out.println("create instance of Logger4J");
- if(clazz != null){
- log = Logger.getLogger(clazz);
- className = clazz.getName();
- }
- }
-
- /**
- * Constructor
- * @param s
- * @param className
- */
- public Logger4J (String s, String className){
- System.out.println("create instance of Logger4J");
- if(s != null){
- log = Logger.getLogger(s);
- }
- this.className = className;
- }
-
- /**
- * Sets transaction Id
- */
- @Override
- public void setTransId(String transId){
- log.info(transId);
- this.transId = transId;
- }
-
- /**
- * Returns transaction Id
- */
- @Override
- public String getTransId(){
- return transId;
- }
-
- /**
- * Records a message
- * @param message
- */
- @Override
- public void debug(Object message) {
- if(isDebugEnabled()){
- log.debug(transId + "|" + message);
- }
- }
-
- /**
- * Records an error message
- * @param message
- */
- @Override
- public void error(Object message) {
- log.error( transId + "|" + className +"|" + message);
- }
-
- /**
- * Records a message
- * @param message
- */
- @Override
- public void info(Object message) {
- log.info( transId + "|" + className +"|" + message);
- }
-
- /**
- * Records a message
- * @param message
- */
- @Override
- public void warn(Object message) {
- log.warn( transId + "|" + className +"|" + message);
- }
-
- /**
- * Records a message
- * @param message
- */
- @Override
- public void trace(Object message) {
- log.trace(transId + "|"+ className +"|" + message);
- }
-
- /**
- * Returns true for debug enabled, or false for not
- * @return boolean
- */
- @Override
- public boolean isDebugEnabled(){
- return log.isDebugEnabled();
- }
-
- /**
- * Returns true for error enabled, or false for not
- * @return boolean
- */
- @SuppressWarnings("deprecation")
- @Override
- public boolean isErrorEnabled(){
- return log.isEnabledFor(Priority.ERROR);
- }
-
- /**
- * Returns true for info enabled, or false for not
- * @return boolean
- */
- @Override
- public boolean isInfoEnabled(){
- return log.isInfoEnabled();
- }
-
- /**
- * Returns true for warn enabled, or false for not
- * @return boolean
- */
- @SuppressWarnings("deprecation")
- @Override
- public boolean isWarnEnabled(){
- //return log4j value
- return log.isEnabledFor(Priority.WARN);
- }
-
- /**
- * Returns true for audit enabled, or false for not
- * @return boolean
- */
- @Override
- public boolean isAuditEnabled(){
- return(PolicyLogger.getAuditLevel() != Level.OFF);
- }
-
- /**
- * Returns true for metrics enabled, or false for not
- * @return boolean
- */
- @Override
- public boolean isMetricsEnabled(){
- return(PolicyLogger.getMetricsLevel() != Level.OFF);
- }
-
- /**
- * Records an audit message
- * @param arg0
- */
- @Override
- public void audit(Object arg0) {
- log.info(className +"|" +arg0);
- }
-
- /**
- * Records an audit message
- * @param eventId
- */
- @Override
- public void recordAuditEventStart(String eventId) {
- log.info(className +"|recordAuditEventStart with eventId " + eventId);
- }
-
- /**
- * Records an audit message
- * @param eventId
- */
- @Override
- public void recordAuditEventStart(UUID eventId) {
- if(eventId != null){
- recordAuditEventStart(eventId.toString());
- }
- }
-
- /**
- * Records an audit message
- * @param eventId
- * @param rule
- * @param policyVersion
- */
- @Override
- public void recordAuditEventEnd(String eventId, String rule, String policyVersion) {
- log.info(className +"|"+ eventId + ":" + rule);
- }
-
- /**
- * Records an audit message
- * @param eventId
- * @param rule
- * @param policyVersion
- */
- @Override
- public void recordAuditEventEnd(UUID eventId, String rule, String policyVersion) {
- if(eventId != null){
- recordAuditEventEnd(eventId.toString(), rule, policyVersion);
- }else{
- recordAuditEventEnd(eventId, rule, policyVersion);
- }
- }
-
- /**
- * Records an audit message
- * @param eventId
- * @param rule
- */
- @Override
- public void recordAuditEventEnd(String eventId, String rule) {
- log.info(className +"|" +eventId + ":" + rule);
- }
-
- /**
- * Records an audit message
- * @param eventId
- * @param rule
- */
- @Override
- public void recordAuditEventEnd(UUID eventId, String rule) {
- if(eventId != null){
- recordAuditEventEnd(eventId.toString(), rule);
- }else{
- recordAuditEventEnd(eventId, rule);
- }
- }
-
- /**
- * Records a metrics message
- * @param eventId
- * @param arg1
- */
- @Override
- public void recordMetricEvent(String eventId, String arg1) {
- log.info(className +"|" +eventId + ":" + arg1);
-
- }
-
- /**
- * Records a metrics message
- * @param eventId
- * @param arg1
- */
- @Override
- public void recordMetricEvent(UUID eventId, String arg1) {
- if(eventId != null){
- recordMetricEvent(eventId.toString(), arg1);
- }else{
- recordMetricEvent(eventId, arg1);
- }
- }
-
- /**
- * Records a metrics message
- * @param arg0
- */
- @Override
- public void metrics(Object arg0) {
- log.info(arg0);
- }
-
- /**
- * Records an error message
- * @param msg
- * @param arg0
- * @param arguments
- */
- @Override
- public void error(MessageCodes msg, Throwable arg0, String... arguments){
- log.error(transId + "|" + className +"|" + "MessageCodes :" + msg + Arrays.asList(arguments));
-
- }
-
- /**
- * Records an error message
- * @param msg
- * @param arguments
- */
- @Override
- public void error(MessageCodes msg, String... arguments){
- log.error(transId + "|" + className +"|" + "MessageCode:" + msg + Arrays.asList(arguments));
- }
-
- /**
- * Returns transaction Id
- * @param transId
- */
- @Override
- public String postMDCInfoForEvent(String transId) {
- String transactionId = transId;
- if(transactionId == null || transactionId.isEmpty()){
- transactionId = UUID.randomUUID().toString();
- }
-
- return transactionId;
- }
-
- /**
- * Records a message
- * @param msg
- * @param arguments
- */
- @Override
- public void warn(MessageCodes msg, String... arguments){
- log.warn(className +"|" +"MessageCodes:" + msg + Arrays.asList(arguments));
- }
-
- /**
- * Records a message
- * @param msg
- * @param arg0
- * @param arguments
- */
- @Override
- public void warn(MessageCodes msg, Throwable arg0, String... arguments){
- log.warn(className +"|" +"MessageCodes:" + msg + Arrays.asList(arguments));
- }
-
- /**
- * Records a message
- * @param message
- * @param t
- */
- @Override
- public void debug(Object message, Throwable t) {
- log.debug(message, t);
- }
-
- /**
- * Records an error message
- * @param message
- * @param t
- */
- @Override
- public void error(Object message, Throwable t) {
- log.error(message, t);
- }
-
- /**
- * Records a message
- * @param message
- * @param t
- */
- @Override
- public void info(Object message, Throwable t) {
- log.info(message, t);
- }
-
- /**
- * Records a message
- * @param message
- * @param t
- */
- @Override
- public void warn(Object message, Throwable t) {
- log.warn(message, t);
- }
-
- /**
- * Records a message
- * @param message
- * @param t
- */
- @Override
- public void trace(Object message, Throwable t) {
- log.trace(message, t);
- }
-
- /**
- * Records an audit message
- * @param arg0
- * @param t
- */
-
- @Override
- public void audit(Object arg0, Throwable t) {
- log.info(arg0, t);
- }
-
- /**
- * Returns true for trace enabled, or false for not
- * @return boolean
- */
- @Override
- public boolean isTraceEnabled() {
- return log.isTraceEnabled();
- }
-
- /**
- * Records transaction Id
- * @param transId
- */
- @Override
- public void postMDCInfoForTriggeredRule(String transId){
- log.info(transId);
- }
-
- /**
- * Records transaction Id
- * @param o
- */
- @Override
- public void postMDCInfoForEvent(Object o){
- log.info(o);
- }
-
- /* ============================================================ */
-
- /*
- * Support for 'Serializable' --
- * the default rules don't work for the 'log' field
- */
-
- private void writeObject(ObjectOutputStream out) throws IOException {
- // write out 'methodName', 'className', 'transId' strings
- out.writeObject(methodName);
- out.writeObject(className);
- out.writeObject(transId);
- }
-
- private void readObject(ObjectInputStream in)
- throws IOException, ClassNotFoundException {
-
- // read in 'methodName', 'className', 'transId' strings
- methodName = (String)(in.readObject());
- className = (String)(in.readObject());
- transId = (String)(in.readObject());
-
- // look up associated logger
- log = Logger.getLogger(className);
- }
+ private String transId = UUID.randomUUID().toString();
+
+ /**
+ * Constructor.
+ *
+ * @param clazz the class
+ */
+ public Logger4J(Class<?> clazz) {
+ System.out.println("create instance of Logger4J");
+ if (clazz != null) {
+ log = Logger.getLogger(clazz);
+ className = clazz.getName();
+ }
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param name the name of the logger
+ * @param className the name of the class
+ */
+ public Logger4J(String name, String className) {
+ System.out.println("create instance of Logger4J");
+ if (name != null) {
+ log = Logger.getLogger(name);
+ }
+ this.className = className;
+ }
+
+ /**
+ * Sets transaction Id.
+ */
+ @Override
+ public void setTransId(String transId) {
+ log.info(transId);
+ this.transId = transId;
+ }
+
+ /**
+ * Returns transaction Id.
+ */
+ @Override
+ public String getTransId() {
+ return transId;
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void debug(Object message) {
+ if (isDebugEnabled()) {
+ log.debug(transId + "|" + message);
+ }
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ @Override
+ public void debug(Object message, Throwable throwable) {
+ log.debug(message, throwable);
+ }
+
+ /**
+ * Records an error message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void error(Object message) {
+ log.error(transId + "|" + className + "|" + message);
+ }
+
+ /**
+ * Records an error message.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ @Override
+ public void error(Object message, Throwable throwable) {
+ log.error(message, throwable);
+ }
+
+ /**
+ * Records an error message.
+ *
+ * @param msg the message code
+ * @param throwable the throwable
+ * @param arguments the messages
+ */
+ @Override
+ public void error(MessageCodes msg, Throwable throwable, String... arguments) {
+ log.error(transId + "|" + className + "|" + "MessageCodes :" + msg + Arrays.asList(arguments));
+
+ }
+
+ /**
+ * Records an error message.
+ *
+ * @param msg the message code
+ * @param arguments the messages
+ */
+ @Override
+ public void error(MessageCodes msg, String... arguments) {
+ log.error(transId + "|" + className + "|" + "MessageCode:" + msg + Arrays.asList(arguments));
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void info(Object message) {
+ log.info(transId + "|" + className + "|" + message);
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ @Override
+ public void info(Object message, Throwable throwable) {
+ log.info(message, throwable);
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void warn(Object message) {
+ log.warn(transId + "|" + className + "|" + message);
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ @Override
+ public void warn(Object message, Throwable throwable) {
+ log.warn(message, throwable);
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param msg the message code
+ * @param arguments the messages
+ */
+ @Override
+ public void warn(MessageCodes msg, String... arguments) {
+ log.warn(className + "|" + "MessageCodes:" + msg + Arrays.asList(arguments));
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param msg the message code
+ * @param throwable the throwable
+ * @param arguments the messages
+ */
+ @Override
+ public void warn(MessageCodes msg, Throwable throwable, String... arguments) {
+ log.warn(className + "|" + "MessageCodes:" + msg + Arrays.asList(arguments));
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void trace(Object message) {
+ log.trace(transId + "|" + className + "|" + message);
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ @Override
+ public void trace(Object message, Throwable throwable) {
+ log.trace(message, throwable);
+ }
+
+ /**
+ * Returns true for debug enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isDebugEnabled() {
+ return log.isDebugEnabled();
+ }
+
+ /**
+ * Returns true for error enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @SuppressWarnings("deprecation")
+ @Override
+ public boolean isErrorEnabled() {
+ return log.isEnabledFor(Priority.ERROR);
+ }
+
+ /**
+ * Returns true for info enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isInfoEnabled() {
+ return log.isInfoEnabled();
+ }
+
+ /**
+ * Returns true for warn enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @SuppressWarnings("deprecation")
+ @Override
+ public boolean isWarnEnabled() {
+ // return log4j value
+ return log.isEnabledFor(Priority.WARN);
+ }
+
+ /**
+ * Returns true for audit enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isAuditEnabled() {
+ return (PolicyLogger.getAuditLevel() != Level.OFF);
+ }
+
+ /**
+ * Returns true for metrics enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isMetricsEnabled() {
+ return (PolicyLogger.getMetricsLevel() != Level.OFF);
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void audit(Object message) {
+ log.info(className + "|" + message);
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+
+ @Override
+ public void audit(Object message, Throwable throwable) {
+ log.info(message, throwable);
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param eventId the event ID
+ */
+ @Override
+ public void recordAuditEventStart(String eventId) {
+ log.info(className + "|recordAuditEventStart with eventId " + eventId);
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param eventId the event ID
+ */
+ @Override
+ public void recordAuditEventStart(UUID eventId) {
+ if (eventId != null) {
+ recordAuditEventStart(eventId.toString());
+ }
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param eventId the event ID
+ * @param rule the rule
+ * @param policyVersion the policy version
+ */
+ @Override
+ public void recordAuditEventEnd(String eventId, String rule, String policyVersion) {
+ log.info(className + "|" + eventId + ":" + rule);
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param eventId the event ID
+ * @param rule the rule
+ * @param policyVersion the policy version
+ */
+ @Override
+ public void recordAuditEventEnd(UUID eventId, String rule, String policyVersion) {
+ if (eventId != null) {
+ recordAuditEventEnd(eventId.toString(), rule, policyVersion);
+ } else {
+ recordAuditEventEnd(eventId, rule, policyVersion);
+ }
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param eventId the event ID
+ * @param rule the rule
+ */
+ @Override
+ public void recordAuditEventEnd(String eventId, String rule) {
+ log.info(className + "|" + eventId + ":" + rule);
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param eventId the event ID
+ * @param rule the rule
+ */
+ @Override
+ public void recordAuditEventEnd(UUID eventId, String rule) {
+ if (eventId != null) {
+ recordAuditEventEnd(eventId.toString(), rule);
+ } else {
+ recordAuditEventEnd(eventId, rule);
+ }
+ }
+
+ /**
+ * Records a metrics message.
+ *
+ * @param eventId the event ID
+ * @param message the message
+ */
+ @Override
+ public void recordMetricEvent(String eventId, String message) {
+ log.info(className + "|" + eventId + ":" + message);
+
+ }
+
+ /**
+ * Records a metrics message.
+ *
+ * @param eventId the event ID
+ * @param message the message
+ */
+ @Override
+ public void recordMetricEvent(UUID eventId, String message) {
+ if (eventId != null) {
+ recordMetricEvent(eventId.toString(), message);
+ } else {
+ recordMetricEvent(eventId, message);
+ }
+ }
+
+ /**
+ * Records a metrics message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void metrics(Object message) {
+ log.info(message);
+ }
+
+ /**
+ * Returns transaction Id.
+ *
+ * @param transId the transaction ID
+ */
+ @Override
+ public String postMDCInfoForEvent(String transId) {
+ String transactionId = transId;
+ if (transactionId == null || transactionId.isEmpty()) {
+ transactionId = UUID.randomUUID().toString();
+ }
+
+ return transactionId;
+ }
+
+ /**
+ * Records transaction Id.
+ *
+ * @param message the message
+ */
+ @Override
+ public void postMDCInfoForEvent(Object message) {
+ log.info(message);
+ }
+
+ /**
+ * Returns true for trace enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isTraceEnabled() {
+ return log.isTraceEnabled();
+ }
+
+ /**
+ * Records transaction Id.
+ *
+ * @param transId the transaction ID
+ */
+ @Override
+ public void postMDCInfoForTriggeredRule(String transId) {
+ log.info(transId);
+ }
+
+ /* ============================================================ */
+
+ /*
+ * Support for 'Serializable' -- the default rules don't work for the 'log' field
+ */
+
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ // write out 'methodName', 'className', 'transId' strings
+ out.writeObject(methodName);
+ out.writeObject(className);
+ out.writeObject(transId);
+ }
+
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+
+ // read in 'methodName', 'className', 'transId' strings
+ methodName = (String) (in.readObject());
+ className = (String) (in.readObject());
+ transId = (String) (in.readObject());
+
+ // look up associated logger
+ log = Logger.getLogger(className);
+ }
}
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/LoggerType.java b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/LoggerType.java
index ed2029e6..8bf0dd78 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/LoggerType.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/LoggerType.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-Logging
* ================================================================================
- * 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.
@@ -21,10 +21,8 @@
package org.onap.policy.common.logging.flexlogger;
/**
- *
- * Logger types
- *
+ * Logger types.
*/
public enum LoggerType {
- EELF, LOG4J, SYSTEMOUT
+ EELF, LOG4J, SYSTEMOUT
}
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/PropertyUtil.java b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/PropertyUtil.java
index 86d119ea..54e06411 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/PropertyUtil.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/PropertyUtil.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-Logging
* ================================================================================
- * 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.
@@ -32,360 +32,313 @@ import java.util.Timer;
import java.util.TimerTask;
/**
- * This class provides utilities to read properties from a properties
- * file, and optionally get notifications of future changes
+ * This class provides utilities to read properties from a properties file, and optionally get
+ * notifications of future changes.
*/
-public class PropertyUtil
-{
-
- // timer thread used for polling for property file changes
- private static Timer timer = null;
-
- // this table maps canonical file into a 'ListenerRegistration' instance
- private static HashMap<File, ListenerRegistration> registrations =
- new HashMap<>();
-
- /**
- * Read in a properties file
- * @param file the properties file
- * @return a Properties object, containing the associated properties
- * @throws IOException - subclass 'FileNotFoundException' if the file
- * does not exist or can't be opened, and 'IOException' if there is
- * a problem loading the properties file.
- */
- public static Properties getProperties(File file) throws IOException
- {
- // create an InputStream (may throw a FileNotFoundException)
- FileInputStream fis = new FileInputStream(file);
- try
- {
- // create the properties instance
- Properties rval = new Properties();
-
- // load properties (may throw an IOException)
- rval.load(fis);
- return rval;
- }
- finally
- {
- // close input stream
- fis.close();
- }
- }
-
- /**
- * Read in a properties file
- * @param fileName the properties file
- * @return a Properties object, containing the associated properties
- * @throws IOException - subclass 'FileNotFoundException' if the file
- * does not exist or can't be opened, and 'IOException' if there is
- * a problem loading the properties file.
- */
- public static Properties getProperties(String fileName) throws IOException
- {
- return getProperties(new File(fileName));
- }
-
- /* ============================================================ */
-
- /**
- * This is the callback interface, used for sending notifications of
- * changes in the properties file.
- */
- @FunctionalInterface
- public interface Listener
- {
- /**
- * Notification of a properties file change
- * @param properties the new properties
- * @param the set of property names that have changed, including
- * additions and removals
- */
- void propertiesChanged(Properties properties, Set<String> changedKeys);
- }
-
- /**
- * This is an internal class - one instance of this exists for each
- * property file that is being monitored. Note that multiple listeners
- * can be registered for the same file.
- */
- private static class ListenerRegistration
- {
- // the canonical path of the file being monitored
- File file;
-
- // the most recent value of 'file.lastModified()'
- long lastModified;
-
- // the most recent set of properties
- Properties properties;
-
- // the set of listeners monitoring this file
- LinkedList<Listener> listeners;
-
- // the 'TimerTask' instance, used for periodic polling
- TimerTask timerTask;
-
- /**
- * Constructor - create a 'ListenerRegistration' instance for this
- * file, but with no listeners
- */
- ListenerRegistration(File file) throws IOException
- {
- this.file = file;
-
- // The initial value of 'lastModified' is set to 0 to ensure that we
- // correctly handle the case where the file is modified within the
- // same second that polling begins.
- lastModified = 0;
-
- // fetch current properties
- properties = getProperties(file);
-
- // no listeners yet
- listeners = new LinkedList<>();
-
- // add to static table, so this instance can be shared
- registrations.put(file, this);
-
- if (timer == null)
- {
- // still need to create a timer thread
- synchronized(PropertyUtil.class)
- {
- // an additional check is added inside the 'synchronized' block,
- // just in case someone beat us to it
- if (timer == null)
- {
- timer = new Timer("PropertyUtil-Timer", true);
- }
- }
- }
-
- // create and schedule the timer task, so this is periodically polled
- timerTask = new TimerTask()
- {
- @Override
- public void run()
- {
- try
- {
- poll();
- }
- catch (Exception e)
- {
- System.err.println(e);
- }
- }
- };
- timer.schedule(timerTask, 10000L, 10000L);
- }
-
- /**
- * Add a listener to the notification list
- * @param listener this is the listener to add to the list
- * @return the properties at the moment the listener was added to the list
- */
- synchronized Properties addListener(Listener listener)
- {
- listeners.add(listener);
- return (Properties)properties.clone();
- }
-
- /**
- * Remove a listener from the notification list
- * @param listener this is the listener to remove
- */
- synchronized void removeListener(Listener listener)
- {
- listeners.remove(listener);
-
- // See if we need to remove this 'ListenerRegistration' instance
- // from the table. The 'synchronized' block is needed in case
- // another listener is being added at about the same time that this
- // one is being removed.
- synchronized(registrations)
- {
- if (listeners.isEmpty())
- {
- timerTask.cancel();
- registrations.remove(file);
- }
- }
- }
-
- /**
- * This method is periodically called to check for property list updates
- * @throws IOException if there is an error in reading the properties file
- */
- synchronized void poll() throws IOException
- {
- long timestamp = file.lastModified();
- if (timestamp != lastModified)
- {
- // update the record, and send out the notifications
- lastModified = timestamp;
-
- // Save old set, and initial set of changed properties.
- Properties oldProperties = properties;
- HashSet<String> changedProperties =
- new HashSet<>(oldProperties.stringPropertyNames());
-
- // Fetch the list of listeners that we will potentially notify,
- // and the new properties. Note that this is in a 'synchronized'
- // block to ensure that all listeners receiving notifications
- // actually have a newer list of properties than the one
- // returned on the initial 'getProperties' call.
- properties = getProperties(file);
-
- Set<String> newPropertyNames = properties.stringPropertyNames();
- changedProperties.addAll(newPropertyNames);
-
- // At this point, 'changedProperties' is the union of all properties
- // in both the old and new properties files. Iterate through all
- // of the entries in the new properties file - if the entry
- // matches the one in the old file, remove it from
- // 'changedProperties'.
- for (String name : newPropertyNames)
- {
- if (properties.getProperty(name).equals
- (oldProperties.getProperty(name)))
- {
- // Apparently, any property that exists must be of type
- // 'String', and can't be null. For this reason, we don't
- // need to worry about the case where
- // 'properties.getProperty(name)' returns 'null'. Note that
- // 'oldProperties.getProperty(name)' may be 'null' if the
- // old property does not exist.
- changedProperties.remove(name);
- }
- }
-
- // 'changedProperties' should be correct at this point
- if (!changedProperties.isEmpty())
- {
- // there were changes - notify everyone in 'listeners'
- for (final Listener notify : listeners)
- {
- // Copy 'properties' and 'changedProperties', so it doesn't
- // cause problems if the recipient makes changes.
- final Properties tmpProperties =
- (Properties)(properties.clone());
- final HashSet<String> tmpChangedProperties =
- new HashSet<>(changedProperties);
-
- // Do the notification in a separate thread, so blocking
- // won't cause any problems.
- new Thread()
- {
- @Override
- public void run()
- {
- notify.propertiesChanged
- (tmpProperties, tmpChangedProperties);
- }
- }.start();
- }
- }
- }
- }
- }
-
- /**
- * Read in a properties file, and register for update notifications.
- * NOTE: it is possible that the first callback will occur while this
- * method is still in progress. To avoid this problem, use 'synchronized'
- * blocks around this invocation and in the callback -- that will ensure
- * that the processing of the initial properties complete before any
- * updates are processed.
- *
- * @param file the properties file
- * @param notify if not null, this is a callback interface that is used for
- * notifications of changes
- * @return a Properties object, containing the associated properties
- * @throws IOException - subclass 'FileNotFoundException' if the file
- * does not exist or can't be opened, and 'IOException' if there is
- * a problem loading the properties file.
- */
- public static Properties getProperties(File file, Listener listener)
- throws IOException
- {
- if (listener == null)
- {
- // no listener specified -- just fetch the properties
- return getProperties(file);
- }
-
- // Convert the file to a canonical form in order to avoid the situation
- // where different names refer to the same file.
- File tempFile = file.getCanonicalFile();
-
- // See if there is an existing registration. The 'synchronized' block
- // is needed to handle the case where a new listener is added at about
- // the same time that another one is being removed.
- synchronized(registrations)
- {
- ListenerRegistration reg = registrations.get(tempFile);
- if (reg == null)
- {
- // a new registration is needed
- reg = new ListenerRegistration(tempFile);
- }
- return reg.addListener(listener);
- }
- }
-
- /**
- * Read in a properties file, and register for update notifications.
- * NOTE: it is possible that the first callback will occur while this
- * method is still in progress. To avoid this problem, use 'synchronized'
- * blocks around this invocation and in the callback -- that will ensure
- * that the processing of the initial properties complete before any
- * updates are processed.
- *
- * @param fileName the properties file
- * @param notify if not null, this is a callback interface that is used for
- * notifications of changes
- * @return a Properties object, containing the associated properties
- * @throws IOException - subclass 'FileNotFoundException' if the file
- * does not exist or can't be opened, and 'IOException' if there is
- * a problem loading the properties file.
- */
- public static Properties getProperties(String fileName, Listener listener)
- throws IOException
- {
- return getProperties(new File(fileName), listener);
- }
-
- /**
- * Stop listenening for updates
- * @param file the properties file
- * @param notify if not null, this is a callback interface that was used for
- * notifications of changes
- * @throws IOException
- */
- public static void stopListening(File file, Listener listener) throws IOException
- {
- if (listener != null)
- {
- ListenerRegistration reg = registrations.get(file.getCanonicalFile());
- if (reg != null)
- {
- reg.removeListener(listener);
- }
- }
- }
-
- /**
- * Stop listenening for updates
- * @param fileName the properties file
- * @param notify if not null, this is a callback interface that was used for
- * notifications of changes
- * @throws IOException
- */
- public static void stopListening(String fileName, Listener listener) throws IOException
- {
- stopListening(new File(fileName), listener);
- }
-
-}
+public class PropertyUtil {
+
+ // timer thread used for polling for property file changes
+ private static Timer timer = null;
+
+ // this table maps canonical file into a 'ListenerRegistration' instance
+ private static HashMap<File, ListenerRegistration> registrations = new HashMap<>();
+
+ /**
+ * Read in a properties file
+ *
+ * @param file the properties file
+ * @return a Properties object, containing the associated properties
+ * @throws IOException - subclass 'FileNotFoundException' if the file does not exist or can't be
+ * opened, and 'IOException' if there is a problem loading the properties file.
+ */
+ public static Properties getProperties(File file) throws IOException {
+ // create an InputStream (may throw a FileNotFoundException)
+ FileInputStream fis = new FileInputStream(file);
+ try {
+ // create the properties instance
+ Properties rval = new Properties();
+
+ // load properties (may throw an IOException)
+ rval.load(fis);
+ return rval;
+ } finally {
+ // close input stream
+ fis.close();
+ }
+ }
+
+ /**
+ * Read in a properties file
+ *
+ * @param fileName the properties file
+ * @return a Properties object, containing the associated properties
+ * @throws IOException - subclass 'FileNotFoundException' if the file does not exist or can't be
+ * opened, and 'IOException' if there is a problem loading the properties file.
+ */
+ public static Properties getProperties(String fileName) throws IOException {
+ return getProperties(new File(fileName));
+ }
+
+ /* ============================================================ */
+
+ /**
+ * This is the callback interface, used for sending notifications of changes in the properties
+ * file.
+ */
+ @FunctionalInterface
+ public interface Listener {
+ /**
+ * Notification of a properties file change.
+ *
+ * @param properties the new properties
+ * @param changedKeys the set of property names that have changed, including additions and
+ * removals
+ */
+ void propertiesChanged(Properties properties, Set<String> changedKeys);
+ }
+
+ /**
+ * This is an internal class - one instance of this exists for each property file that is being
+ * monitored. Note that multiple listeners can be registered for the same file.
+ */
+ private static class ListenerRegistration {
+ // the canonical path of the file being monitored
+ File file;
+
+ // the most recent value of 'file.lastModified()'
+ long lastModified;
+
+ // the most recent set of properties
+ Properties properties;
+
+ // the set of listeners monitoring this file
+ LinkedList<Listener> listeners;
+
+ // the 'TimerTask' instance, used for periodic polling
+ TimerTask timerTask;
+
+ /**
+ * Constructor - create a 'ListenerRegistration' instance for this file, but with no
+ * listeners.
+ */
+ ListenerRegistration(File file) throws IOException {
+ this.file = file;
+
+ // The initial value of 'lastModified' is set to 0 to ensure that we
+ // correctly handle the case where the file is modified within the
+ // same second that polling begins.
+ lastModified = 0;
+
+ // fetch current properties
+ properties = getProperties(file);
+
+ // no listeners yet
+ listeners = new LinkedList<>();
+
+ // add to static table, so this instance can be shared
+ registrations.put(file, this);
+
+ if (timer == null) {
+ // still need to create a timer thread
+ synchronized (PropertyUtil.class) {
+ // an additional check is added inside the 'synchronized' block,
+ // just in case someone beat us to it
+ if (timer == null) {
+ timer = new Timer("PropertyUtil-Timer", true);
+ }
+ }
+ }
+
+ // create and schedule the timer task, so this is periodically polled
+ timerTask = new TimerTask() {
+ @Override
+ public void run() {
+ try {
+ poll();
+ } catch (Exception e) {
+ System.err.println(e);
+ }
+ }
+ };
+ timer.schedule(timerTask, 10000L, 10000L);
+ }
+
+ /**
+ * Add a listener to the notification list.
+ *
+ * @param listener this is the listener to add to the list
+ * @return the properties at the moment the listener was added to the list
+ */
+ synchronized Properties addListener(Listener listener) {
+ listeners.add(listener);
+ return (Properties) properties.clone();
+ }
+
+ /**
+ * Remove a listener from the notification list.
+ *
+ * @param listener this is the listener to remove
+ */
+ synchronized void removeListener(Listener listener) {
+ listeners.remove(listener);
+
+ // See if we need to remove this 'ListenerRegistration' instance
+ // from the table. The 'synchronized' block is needed in case
+ // another listener is being added at about the same time that this
+ // one is being removed.
+ synchronized (registrations) {
+ if (listeners.isEmpty()) {
+ timerTask.cancel();
+ registrations.remove(file);
+ }
+ }
+ }
+
+ /**
+ * This method is periodically called to check for property list updates.
+ *
+ * @throws IOException if there is an error in reading the properties file
+ */
+ synchronized void poll() throws IOException {
+ long timestamp = file.lastModified();
+ if (timestamp != lastModified) {
+ // update the record, and send out the notifications
+ lastModified = timestamp;
+
+ // Save old set, and initial set of changed properties.
+ Properties oldProperties = properties;
+ HashSet<String> changedProperties = new HashSet<>(oldProperties.stringPropertyNames());
+
+ // Fetch the list of listeners that we will potentially notify,
+ // and the new properties. Note that this is in a 'synchronized'
+ // block to ensure that all listeners receiving notifications
+ // actually have a newer list of properties than the one
+ // returned on the initial 'getProperties' call.
+ properties = getProperties(file);
+
+ Set<String> newPropertyNames = properties.stringPropertyNames();
+ changedProperties.addAll(newPropertyNames);
+
+ // At this point, 'changedProperties' is the union of all properties
+ // in both the old and new properties files. Iterate through all
+ // of the entries in the new properties file - if the entry
+ // matches the one in the old file, remove it from
+ // 'changedProperties'.
+ for (String name : newPropertyNames) {
+ if (properties.getProperty(name).equals(oldProperties.getProperty(name))) {
+ // Apparently, any property that exists must be of type
+ // 'String', and can't be null. For this reason, we don't
+ // need to worry about the case where
+ // 'properties.getProperty(name)' returns 'null'. Note that
+ // 'oldProperties.getProperty(name)' may be 'null' if the
+ // old property does not exist.
+ changedProperties.remove(name);
+ }
+ }
+
+ // 'changedProperties' should be correct at this point
+ if (!changedProperties.isEmpty()) {
+ // there were changes - notify everyone in 'listeners'
+ for (final Listener notify : listeners) {
+ // Copy 'properties' and 'changedProperties', so it doesn't
+ // cause problems if the recipient makes changes.
+ final Properties tmpProperties = (Properties) (properties.clone());
+ final HashSet<String> tmpChangedProperties = new HashSet<>(changedProperties);
+
+ // Do the notification in a separate thread, so blocking
+ // won't cause any problems.
+ new Thread() {
+ @Override
+ public void run() {
+ notify.propertiesChanged(tmpProperties, tmpChangedProperties);
+ }
+ }.start();
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Read in a properties file, and register for update notifications. NOTE: it is possible that
+ * the first callback will occur while this method is still in progress. To avoid this problem,
+ * use 'synchronized' blocks around this invocation and in the callback -- that will ensure that
+ * the processing of the initial properties complete before any updates are processed.
+ *
+ * @param file the properties file
+ * @param listener notify if not null, this is a callback interface that is used for
+ * notifications of changes
+ * @return a Properties object, containing the associated properties
+ * @throws IOException - subclass 'FileNotFoundException' if the file does not exist or can't be
+ * opened, and 'IOException' if there is a problem loading the properties file.
+ */
+ public static Properties getProperties(File file, Listener listener) throws IOException {
+ if (listener == null) {
+ // no listener specified -- just fetch the properties
+ return getProperties(file);
+ }
+
+ // Convert the file to a canonical form in order to avoid the situation
+ // where different names refer to the same file.
+ File tempFile = file.getCanonicalFile();
+
+ // See if there is an existing registration. The 'synchronized' block
+ // is needed to handle the case where a new listener is added at about
+ // the same time that another one is being removed.
+ synchronized (registrations) {
+ ListenerRegistration reg = registrations.get(tempFile);
+ if (reg == null) {
+ // a new registration is needed
+ reg = new ListenerRegistration(tempFile);
+ }
+ return reg.addListener(listener);
+ }
+ }
+
+ /**
+ * Read in a properties file, and register for update notifications. NOTE: it is possible that
+ * the first callback will occur while this method is still in progress. To avoid this problem,
+ * use 'synchronized' blocks around this invocation and in the callback -- that will ensure that
+ * the processing of the initial properties complete before any updates are processed.
+ *
+ * @param fileName the properties file
+ * @param listener notify if not null, this is a callback interface that is used for
+ * notifications of changes
+ * @return a Properties object, containing the associated properties
+ * @throws IOException - subclass 'FileNotFoundException' if the file does not exist or can't be
+ * opened, and 'IOException' if there is a problem loading the properties file.
+ */
+ public static Properties getProperties(String fileName, Listener listener) throws IOException {
+ return getProperties(new File(fileName), listener);
+ }
+
+ /**
+ * Stop listenening for updates.
+ *
+ * @param file the properties file
+ * @param listener notify if not null, this is a callback interface that was used for
+ * notifications of changes
+ * @throws IOException If an I/O error occurs
+ */
+ public static void stopListening(File file, Listener listener) throws IOException {
+ if (listener != null) {
+ ListenerRegistration reg = registrations.get(file.getCanonicalFile());
+ if (reg != null) {
+ reg.removeListener(listener);
+ }
+ }
+ }
+
+ /**
+ * Stop listenening for updates.
+ *
+ * @param fileName the properties file
+ * @param listener notify if not null, this is a callback interface that was used for
+ * notifications of changes
+ * @throws IOException If an I/O error occurs
+ */
+ public static void stopListening(String fileName, Listener listener) throws IOException {
+ stopListening(new File(fileName), listener);
+ }
+
+}
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/SystemOutLogger.java b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/SystemOutLogger.java
index 825799b9..70ad08ae 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/SystemOutLogger.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/SystemOutLogger.java
@@ -20,485 +20,510 @@
package org.onap.policy.common.logging.flexlogger;
+import com.att.eelf.configuration.EELFLogger.Level;
+
import java.io.Serializable;
import java.util.Arrays;
import java.util.UUID;
import org.onap.policy.common.logging.eelf.MessageCodes;
import org.onap.policy.common.logging.eelf.PolicyLogger;
-import com.att.eelf.configuration.EELFLogger.Level;
/**
- *
* SystemOutLogger implements all the methods of interface Logger by calling System.out.println
- *
*/
public class SystemOutLogger implements Logger, Serializable {
-
- /**
- *
- */
- private static final long serialVersionUID = 4956408061058933929L;
- private String className = "";
- private boolean isDebugEnabled = true;
- private boolean isInfoEnabled = true;
- private boolean isWarnEnabled = true;
- private boolean isErrorEnabled = true;
- private boolean isAuditEnabled = true;
- private boolean isMetricsEnabled = true;
- private String transId = UUID.randomUUID().toString();
-
- /**
- * Constructor
- * @param clazz
- */
- public SystemOutLogger (Class<?> clazz){
- System.out.println("create instance of SystemOutLogger");
- if(clazz != null){
- className = clazz.getName();
- }
+
+ private static final long serialVersionUID = 4956408061058933929L;
+ private String className = "";
+ private boolean isDebugEnabled = true;
+ private boolean isInfoEnabled = true;
+ private boolean isWarnEnabled = true;
+ private boolean isErrorEnabled = true;
+ private boolean isAuditEnabled = true;
+ private boolean isMetricsEnabled = true;
+ private String transId = UUID.randomUUID().toString();
+
+ /**
+ * Constructor.
+ *
+ * @param clazz the class
+ */
+ public SystemOutLogger(Class<?> clazz) {
+ System.out.println("create instance of SystemOutLogger");
+ if (clazz != null) {
+ className = clazz.getName();
+ }
initLevel();
- }
-
+ }
+
/**
- * Constructor
- * @param s
+ * Constructor.
+ *
+ * @param className the class name
*/
- public SystemOutLogger (String s){
- System.out.println("create instance of SystemOutLogger");
- if(s != null){
- className = s;
- }
+ public SystemOutLogger(String className) {
+ System.out.println("create instance of SystemOutLogger");
+ if (className != null) {
+ this.className = className;
+ }
initLevel();
- }
-
- /**
- * Sets logging levels
- */
- private void initLevel(){
-
- if(PolicyLogger.getDebugLevel() == Level.DEBUG){
- isDebugEnabled = true;
- isInfoEnabled = true;
- isWarnEnabled = true;
- }else{
- isDebugEnabled = false;
- }
-
- if(PolicyLogger.getDebugLevel() == Level.INFO){
- isInfoEnabled = true;
- isWarnEnabled = true;
- isDebugEnabled = false;
- }
-
- if(PolicyLogger.getDebugLevel() == Level.OFF){
- isInfoEnabled = false;
- isWarnEnabled = false;
- isDebugEnabled = false;
- }
-
- if(PolicyLogger.getErrorLevel() == Level.OFF){
- isErrorEnabled = false;
- }
-
- if(PolicyLogger.getAuditLevel() == Level.OFF){
- isAuditEnabled = false;
- }
-
- if(PolicyLogger.getMetricsLevel() == Level.OFF){
- isMetricsEnabled = false;
- }
- }
-
- /**
- * Sets transaction Id
- */
- @Override
- public void setTransId(String transId){
-
- System.out.println(transId);
- this.transId = transId;
- }
-
- /**
- * Returns transaction Id
- */
- @Override
- public String getTransId(){
-
- return transId;
- }
-
- /**
- * Records a message
- * @param message
- */
- @Override
- public void debug(Object message) {
-
- System.out.println(transId + "|" + className+" : "+message);
- }
-
- /**
- * Records an error message
- * @param message
- */
- @Override
- public void error(Object message) {
-
- System.out.println(transId + "|" + className+" : "+message);
- }
-
- /**
- * Records a message
- * @param message
- */
- @Override
- public void info(Object message) {
-
- System.out.println(transId + "|" + className+" : "+message);
-
- }
-
- /**
- * Records a message
- * @param message
- */
- @Override
- public void warn(Object message) {
-
- System.out.println(transId + "|" + className+" : "+message);
- }
-
- /**
- * Records a message
- * @param message
- */
- @Override
- public void trace(Object message) {
-
- System.out.println(transId + "|" + className+" : "+message);
- }
-
- /**
- * Returns true for debug enabled, or false for not
- * @return boolean
- */
- @Override
- public boolean isDebugEnabled(){
-
- return isDebugEnabled;
- }
-
- /**
- * Returns true for warn enabled, or false for not
- * @return boolean
- */
- @Override
- public boolean isWarnEnabled(){
-
- return isWarnEnabled;
- }
-
- /**
- * Returns true for info enabled, or false for not
- * @return boolean
- */
- @Override
- public boolean isInfoEnabled(){
-
- return isInfoEnabled;
- }
-
- /**
- * Returns true for error enabled, or false for not
- * @return boolean
- */
- @Override
- public boolean isErrorEnabled(){
-
- return isErrorEnabled;
- }
-
- /**
- * Returns true for audit enabled, or false for not
- * @return boolean
- */
- @Override
- public boolean isAuditEnabled(){
-
- return isAuditEnabled;
- }
-
- /**
- * Returns true for metrics enabled, or false for not
- * @return boolean
- */
- @Override
- public boolean isMetricsEnabled(){
-
- return isMetricsEnabled;
- }
-
- /**
- * Records an audit message
- * @param arg0
- */
- @Override
- public void audit(Object arg0) {
-
- System.out.println(transId + "|" +className+" : "+arg0);
- }
-
- /**
- * Records an audit message
- * @param eventId
- */
- @Override
- public void recordAuditEventStart(String eventId) {
-
- System.out.println(transId + "|" +className+" : "+eventId);
-
- }
-
- /**
- * Records an audit message
- * @param eventId
- */
- @Override
- public void recordAuditEventStart(UUID eventId) {
-
- System.out.println(eventId);
- }
-
- /**
- * Records an audit message
- * @param eventId
- * @param rule
- * @param policyVersion
- */
- @Override
- public void recordAuditEventEnd(String eventId, String rule, String policyVersion) {
-
- System.out.println(className+" : "+eventId + ":" + rule + ":" + policyVersion);
- }
-
- /**
- * Records an audit message
- * @param eventId
- * @param rule
- * @param policyVersion
- */
- @Override
- public void recordAuditEventEnd(UUID eventId, String rule, String policyVersion) {
-
- System.out.println(className+" : "+eventId + ":" + rule + ":" + policyVersion);
- }
-
- /**
- * Records an audit message
- * @param eventId
- * @param rule
- */
- @Override
- public void recordAuditEventEnd(String eventId, String rule) {
-
- System.out.println(className+" : "+eventId + ":" + rule);
- }
-
- /**
- * Records an audit message
- * @param eventId
- * @param rule
- */
- @Override
- public void recordAuditEventEnd(UUID eventId, String rule) {
-
- System.out.println(className+" : "+eventId + ":" + rule);
- }
-
- /**
- * Records a metrics message
- * @param eventId
- * @param arg1
- */
- @Override
- public void recordMetricEvent(String eventId, String arg1) {
-
- System.out.println(className+" : "+"eventId:" + eventId + "message:" + arg1);
-
- }
-
- /**
- * Records a metrics message
- * @param eventId
- * @param arg1
- */
- @Override
- public void recordMetricEvent(UUID eventId, String arg1) {
-
- System.out.println(className+" : "+eventId + ":" + arg1);
- }
-
- /**
- * Records a metrics message
- * @param arg0
- */
- @Override
- public void metrics(Object arg0) {
-
- System.out.println(className+" : "+arg0);
- }
-
- /**
- * Records an error message
- * @param msg
- * @param arg0
- * @param arguments
- */
- @Override
- public void error(MessageCodes msg, Throwable arg0, String... arguments){
-
- System.out.println(className+" : "+"MessageCodes :" + msg + Arrays.asList(arguments));
-
- }
-
- /**
- * Records an error message
- * @param msg
- * @param arguments
- */
- @Override
- public void error(MessageCodes msg, String... arguments){
-
- System.out.println(transId + "|" + className+" : "+"MessageCode:" + msg + Arrays.asList(arguments));
- }
-
- /**
- * Returns transaction Id
- * @param transId
- */
- @Override
- public String postMDCInfoForEvent(String transId) {
-
- String transactionId = transId;
- if(transactionId == null || transactionId.isEmpty()){
- transactionId = UUID.randomUUID().toString();
- }
-
- return transactionId;
- }
-
- /**
- * Records a message
- * @param msg
- * @param arguments
- */
- @Override
- public void warn(MessageCodes msg, String... arguments){
-
- System.out.println(transId + "|" + className+" : "+"MessageCodes:" + msg + Arrays.asList(arguments));
- }
-
- /**
- * Records a message
- * @param msg
- * @param arg0
- * @param arguments
- */
- @Override
- public void warn(MessageCodes msg, Throwable arg0, String... arguments){
-
- System.out.println(transId + "|" + className+" : "+"MessageCodes:" + msg + Arrays.asList(arguments));
-
- }
-
- /**
- * Records a message
- * @param message
- * @param t
- */
- @Override
- public void debug(Object message, Throwable t) {
- System.out.println(transId + "|" + className+" : "+ message + ":" + t);
- }
-
- /**
- * Records an error message
- * @param message
- * @param t
- */
- @Override
- public void error(Object message, Throwable t) {
- System.out.println(transId + "|" + className+" : "+ message + ":" + t);
- }
-
- /**
- * Records a message
- * @param message
- * @param t
- */
- @Override
- public void info(Object message, Throwable t) {
- System.out.println(transId + "|" + className+" : "+ message + ":" + t);
- }
-
- /**
- * Records a message
- * @param message
- * @param t
- */
- @Override
- public void warn(Object message, Throwable t) {
- System.out.println(transId + "|" + className+" : "+ message + ":" + t);
- }
-
- /**
- * Records a message
- * @param message
- * @param t
- */
- @Override
- public void trace(Object message, Throwable t) {
- System.out.println(transId + "|" + className+" : "+ message + ":" + t);
- }
-
- /**
- * Records an audit message
- * @param arg0
- * @param t
- */
- @Override
- public void audit(Object arg0, Throwable t) {
- System.out.println(transId + "|" + className+" : "+ arg0 + ":" + t);
- }
-
- /**
- * Returns true for trace enabled, or false for not
- * @return boolean
- */
- @Override
- public boolean isTraceEnabled() {
- // default
- return false;
- }
-
- /**
- * Records transaction Id
- * @param transId
- */
- @Override
- public void postMDCInfoForTriggeredRule(String transId){
-
- System.out.println(transId);
- }
-
- /**
- * Records transaction Id
- * @param o
- */
- @Override
- public void postMDCInfoForEvent(Object o){
- System.out.println(o);
- }
+ }
+
+ /**
+ * Sets logging levels.
+ */
+ private void initLevel() {
+
+ if (PolicyLogger.getDebugLevel() == Level.DEBUG) {
+ isDebugEnabled = true;
+ isInfoEnabled = true;
+ isWarnEnabled = true;
+ } else {
+ isDebugEnabled = false;
+ }
+
+ if (PolicyLogger.getDebugLevel() == Level.INFO) {
+ isInfoEnabled = true;
+ isWarnEnabled = true;
+ isDebugEnabled = false;
+ }
+
+ if (PolicyLogger.getDebugLevel() == Level.OFF) {
+ isInfoEnabled = false;
+ isWarnEnabled = false;
+ isDebugEnabled = false;
+ }
+
+ if (PolicyLogger.getErrorLevel() == Level.OFF) {
+ isErrorEnabled = false;
+ }
+
+ if (PolicyLogger.getAuditLevel() == Level.OFF) {
+ isAuditEnabled = false;
+ }
+
+ if (PolicyLogger.getMetricsLevel() == Level.OFF) {
+ isMetricsEnabled = false;
+ }
+ }
+
+ /**
+ * Sets transaction Id.
+ */
+ @Override
+ public void setTransId(String transId) {
+
+ System.out.println(transId);
+ this.transId = transId;
+ }
+
+ /**
+ * Returns transaction Id.
+ */
+ @Override
+ public String getTransId() {
+
+ return transId;
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void debug(Object message) {
+
+ System.out.println(transId + "|" + className + " : " + message);
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ @Override
+ public void debug(Object message, Throwable throwable) {
+ System.out.println(transId + "|" + className + " : " + message + ":" + throwable);
+ }
+
+ /**
+ * Records an error message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void error(Object message) {
+
+ System.out.println(transId + "|" + className + " : " + message);
+ }
+
+ /**
+ * Records an error message.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ @Override
+ public void error(Object message, Throwable throwable) {
+ System.out.println(transId + "|" + className + " : " + message + ":" + throwable);
+ }
+
+ /**
+ * Records an error message.
+ *
+ * @param msg the message code
+ * @param throwable the throwable
+ * @param arguments the messages
+ */
+ @Override
+ public void error(MessageCodes msg, Throwable throwable, String... arguments) {
+ System.out.println(className + " : " + "MessageCodes :" + msg + Arrays.asList(arguments));
+ }
+
+ /**
+ * Records an error message.
+ *
+ * @param msg the message code
+ * @param arguments the messages
+ */
+ @Override
+ public void error(MessageCodes msg, String... arguments) {
+
+ System.out.println(transId + "|" + className + " : " + "MessageCode:" + msg + Arrays.asList(arguments));
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void info(Object message) {
+ System.out.println(transId + "|" + className + " : " + message);
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ @Override
+ public void info(Object message, Throwable throwable) {
+ System.out.println(transId + "|" + className + " : " + message + ":" + throwable);
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void warn(Object message) {
+ System.out.println(transId + "|" + className + " : " + message);
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ @Override
+ public void warn(Object message, Throwable throwable) {
+ System.out.println(transId + "|" + className + " : " + message + ":" + throwable);
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param msg the message code
+ * @param arguments the messages
+ */
+ @Override
+ public void warn(MessageCodes msg, String... arguments) {
+
+ System.out.println(transId + "|" + className + " : " + "MessageCodes:" + msg + Arrays.asList(arguments));
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param msg the message code
+ * @param throwable the throwable
+ * @param arguments the messages
+ */
+ @Override
+ public void warn(MessageCodes msg, Throwable throwable, String... arguments) {
+
+ System.out.println(transId + "|" + className + " : " + "MessageCodes:" + msg + Arrays.asList(arguments));
+
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void trace(Object message) {
+ System.out.println(transId + "|" + className + " : " + message);
+ }
+
+ /**
+ * Records a message.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ @Override
+ public void trace(Object message, Throwable throwable) {
+ System.out.println(transId + "|" + className + " : " + message + ":" + throwable);
+ }
+
+ /**
+ * Returns true for debug enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isDebugEnabled() {
+ return isDebugEnabled;
+ }
+
+ /**
+ * Returns true for warn enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isWarnEnabled() {
+ return isWarnEnabled;
+ }
+
+ /**
+ * Returns true for info enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isInfoEnabled() {
+ return isInfoEnabled;
+ }
+
+ /**
+ * Returns true for error enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isErrorEnabled() {
+ return isErrorEnabled;
+ }
+
+ /**
+ * Returns true for audit enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isAuditEnabled() {
+
+ return isAuditEnabled;
+ }
+
+ /**
+ * Returns true for metrics enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isMetricsEnabled() {
+
+ return isMetricsEnabled;
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void audit(Object message) {
+
+ System.out.println(transId + "|" + className + " : " + message);
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ @Override
+ public void audit(Object message, Throwable throwable) {
+ System.out.println(transId + "|" + className + " : " + message + ":" + throwable);
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param eventId the event ID
+ */
+ @Override
+ public void recordAuditEventStart(String eventId) {
+
+ System.out.println(transId + "|" + className + " : " + eventId);
+
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param eventId the event ID
+ */
+ @Override
+ public void recordAuditEventStart(UUID eventId) {
+
+ System.out.println(eventId);
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param eventId the event ID
+ * @param rule the rule
+ * @param policyVersion the policy version
+ */
+ @Override
+ public void recordAuditEventEnd(String eventId, String rule, String policyVersion) {
+
+ System.out.println(className + " : " + eventId + ":" + rule + ":" + policyVersion);
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param eventId the event ID
+ * @param rule the rule
+ * @param policyVersion the policy version
+ */
+ @Override
+ public void recordAuditEventEnd(UUID eventId, String rule, String policyVersion) {
+
+ System.out.println(className + " : " + eventId + ":" + rule + ":" + policyVersion);
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param eventId the event ID
+ * @param rule the rule
+ */
+ @Override
+ public void recordAuditEventEnd(String eventId, String rule) {
+
+ System.out.println(className + " : " + eventId + ":" + rule);
+ }
+
+ /**
+ * Records an audit message.
+ *
+ * @param eventId the event ID
+ * @param rule the rule
+ */
+ @Override
+ public void recordAuditEventEnd(UUID eventId, String rule) {
+
+ System.out.println(className + " : " + eventId + ":" + rule);
+ }
+
+ /**
+ * Records a metrics message.
+ *
+ * @param eventId the event ID
+ * @param message the message
+ */
+ @Override
+ public void recordMetricEvent(String eventId, String message) {
+
+ System.out.println(className + " : " + "eventId:" + eventId + "message:" + message);
+
+ }
+
+ /**
+ * Records a metrics message.
+ *
+ * @param eventId the event ID
+ * @param message the message
+ */
+ @Override
+ public void recordMetricEvent(UUID eventId, String message) {
+
+ System.out.println(className + " : " + eventId + ":" + message);
+ }
+
+ /**
+ * Records a metrics message.
+ *
+ * @param message the message
+ */
+ @Override
+ public void metrics(Object message) {
+
+ System.out.println(className + " : " + message);
+ }
+
+ /**
+ * Returns transaction Id.
+ *
+ * @param transId the transaction ID
+ */
+ @Override
+ public String postMDCInfoForEvent(String transId) {
+
+ String transactionId = transId;
+ if (transactionId == null || transactionId.isEmpty()) {
+ transactionId = UUID.randomUUID().toString();
+ }
+
+ return transactionId;
+ }
+
+ /**
+ * Records transaction Id.
+ *
+ * @param message the message
+ */
+ @Override
+ public void postMDCInfoForEvent(Object message) {
+ System.out.println(message);
+ }
+
+
+ /**
+ * Returns true for trace enabled, or false for not.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isTraceEnabled() {
+ // default
+ return false;
+ }
+
+ /**
+ * Records transaction Id.
+ *
+ * @param transId the transaction ID
+ */
+ @Override
+ public void postMDCInfoForTriggeredRule(String transId) {
+
+ System.out.println(transId);
+ }
+
}