diff options
Diffstat (limited to 'common-logging/src/main/java/org/onap/policy/common/logging/flexlogger')
7 files changed, 270 insertions, 236 deletions
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/DisplayUtils.java b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/DisplayUtils.java new file mode 100644 index 00000000..dc740440 --- /dev/null +++ b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/DisplayUtils.java @@ -0,0 +1,41 @@ +/* + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.common.logging.flexlogger; + +/** + * Utilities to display messages. These are generally used while logging is being + * configured, or when logging being directed to System.out. As a result, it directly + * writes to System.out rather than to a logger. + */ +public class DisplayUtils { + + private DisplayUtils() { + // do nothing + } + + public static void displayMessage(Object message) { + System.out.println(message); + } + + public static void displayErrorMessage(Object msg) { + System.err.println(msg); + } +} 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 e0c4144b..a3e5cc8f 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 @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP-Logging * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -40,31 +40,31 @@ public class EelfLogger implements Logger, Serializable { /** * Constructor. - * + * * @param clazz the class */ public EelfLogger(Class<?> clazz) { if (clazz != null) { className = clazz.getName(); } - PolicyLogger.postMDCInfoForEvent(null); + PolicyLogger.postMdcInfoForEvent(null); } /** * Constructor. - * + * * @param className the class name */ public EelfLogger(String className) { if (className != null) { this.className = className; } - PolicyLogger.postMDCInfoForEvent(null); + PolicyLogger.postMdcInfoForEvent(null); } /** * Constructor. - * + * * @param clazz the class * @param isNewTransaction is a new transaction */ @@ -73,7 +73,7 @@ public class EelfLogger implements Logger, Serializable { className = clazz.getName(); } if (isNewTransaction) { - transId = PolicyLogger.postMDCInfoForEvent(null); + transId = PolicyLogger.postMdcInfoForEvent(null); } else { transId = PolicyLogger.getTransId(); } @@ -81,7 +81,7 @@ public class EelfLogger implements Logger, Serializable { /** * Constructor. - * + * * @param className the class name * @param isNewTransaction is a new transaction */ @@ -90,7 +90,7 @@ public class EelfLogger implements Logger, Serializable { this.className = className; } if (isNewTransaction) { - transId = PolicyLogger.postMDCInfoForEvent(null); + transId = PolicyLogger.postMdcInfoForEvent(null); } else { transId = PolicyLogger.getTransId(); } @@ -98,7 +98,7 @@ public class EelfLogger implements Logger, Serializable { /** * Constructor. - * + * * @param clazz the class * @param transId the transaction ID */ @@ -106,13 +106,13 @@ public class EelfLogger implements Logger, Serializable { if (clazz != null) { className = clazz.getName(); } - PolicyLogger.postMDCInfoForEvent(transId); + PolicyLogger.postMdcInfoForEvent(transId); this.transId = transId; } /** * Constructor. - * + * * @param className the class name * @param transId the transaction ID */ @@ -120,13 +120,13 @@ public class EelfLogger implements Logger, Serializable { if (className != null) { this.className = className; } - PolicyLogger.postMDCInfoForEvent(transId); + PolicyLogger.postMdcInfoForEvent(transId); this.transId = transId; } /** * Sets transaction Id for logging. - * + * * @param transId the transaction ID */ @Override @@ -146,7 +146,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records a message. - * + * * @param message the message */ @Override @@ -156,7 +156,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records a message. - * + * * @param message the message * @param throwable the throwable */ @@ -167,7 +167,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records an error message. - * + * * @param message the message */ @Override @@ -177,7 +177,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records an error message. - * + * * @param message the message * @param throwable the throwable */ @@ -188,7 +188,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records an error message. - * + * * @param msg the message code * @param throwable the throwable * @param arguments the messages @@ -200,7 +200,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records an error message. - * + * * @param msg the message code * @param arguments the messages */ @@ -211,7 +211,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records a message. - * + * * @param message the message */ @Override @@ -221,7 +221,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records a message. - * + * * @param message the message * @param throwable the throwable */ @@ -232,7 +232,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records a message. - * + * * @param message the message */ @Override @@ -242,7 +242,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records a message. - * + * * @param message the message * @param throwable the throwable */ @@ -253,7 +253,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records a message. - * + * * @param msg the message codes * @param arguments the messages */ @@ -264,7 +264,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records a message. - * + * * @param msg the message * @param throwable the throwable * @param arguments the messages @@ -276,7 +276,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records a message. - * + * * @param message the message */ @Override @@ -286,7 +286,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records a message. - * + * * @param message the message * @param throwable the throwable */ @@ -297,7 +297,7 @@ public class EelfLogger implements Logger, Serializable { /** * Returns true for debug enabled, or false for not. - * + * * @return boolean */ @Override @@ -307,7 +307,7 @@ public class EelfLogger implements Logger, Serializable { /** * Returns true for info enabled, or false for not. - * + * * @return boolean */ @Override @@ -317,7 +317,7 @@ public class EelfLogger implements Logger, Serializable { /** * Returns true for warn enabled, or false for not. - * + * * @return boolean */ @Override @@ -327,7 +327,7 @@ public class EelfLogger implements Logger, Serializable { /** * Returns true for error enabled, or false for not. - * + * * @return boolean */ @Override @@ -337,7 +337,7 @@ public class EelfLogger implements Logger, Serializable { /** * Returns true for audit enabled, or false for not. - * + * * @return boolean */ @Override @@ -347,7 +347,7 @@ public class EelfLogger implements Logger, Serializable { /** * Returns true for metrics enabled, or false for not. - * + * * @return boolean */ @Override @@ -357,7 +357,7 @@ public class EelfLogger implements Logger, Serializable { /** * Returns true for trace enabled, or false for not. - * + * * @return boolean */ @Override @@ -367,7 +367,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records an audit message. - * + * * @param arg0 the message */ @Override @@ -377,7 +377,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records an audit message. - * + * * @param message the message * @param throwable the throwable */ @@ -388,7 +388,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records an audit message. - * + * * @param eventId the event ID */ @Override @@ -398,7 +398,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records an audit message. - * + * * @param eventId the event ID */ @Override @@ -408,7 +408,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records an audit message. - * + * * @param eventId the event ID * @param rule the rule * @param policyVersion the policy cersion @@ -420,7 +420,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records an audit message. - * + * * @param eventId the event ID * @param rule the rule * @param policyVersion the policy version @@ -432,7 +432,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records an audit message. - * + * * @param eventId the event ID * @param rule the rule */ @@ -443,7 +443,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records an audit message. - * + * * @param eventId the event ID * @param rule the rule */ @@ -454,7 +454,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records a metrics message. - * + * * @param eventId the event ID * @param message the message */ @@ -465,7 +465,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records a metrics message. - * + * * @param eventId the event ID * @param message the message */ @@ -476,7 +476,7 @@ public class EelfLogger implements Logger, Serializable { /** * Records a metrics message. - * + * * @param message the message */ @Override @@ -486,32 +486,32 @@ public class EelfLogger implements Logger, Serializable { /** * Populates MDC Info. - * + * * @param transId the transaction ID */ @Override - public String postMDCInfoForEvent(String transId) { - return PolicyLogger.postMDCInfoForEvent(transId); + 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); + 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); + 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 90240a77..030363dc 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,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP-Logging * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,6 +20,8 @@ package org.onap.policy.common.logging.flexlogger; +import static org.onap.policy.common.logging.flexlogger.DisplayUtils.displayMessage; + import java.io.IOException; import java.text.SimpleDateFormat; import java.time.Instant; @@ -49,12 +51,12 @@ public class FlexLogger extends SecurityManager { /** * 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); + displayMessage(GET_LOGGER_PREFIX + loggerType); switch (loggerType) { case EELF: @@ -75,12 +77,12 @@ public class FlexLogger extends SecurityManager { /** * 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); + displayMessage(GET_LOGGER_PREFIX + loggerType); switch (loggerType) { case EELF: @@ -101,13 +103,13 @@ public class FlexLogger extends SecurityManager { /** * 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); + displayMessage(GET_LOGGER_PREFIX + loggerType); switch (loggerType) { case EELF: @@ -128,13 +130,13 @@ public class FlexLogger extends SecurityManager { /** * 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); + displayMessage(GET_LOGGER_PREFIX + loggerType); switch (loggerType) { case EELF: @@ -156,7 +158,7 @@ public class FlexLogger extends SecurityManager { * Returns the calling class name. */ public String getClassName() { - System.out.println("getClassContext()[3].getName() " + getClassContext()[3].getName()); + displayMessage("getClassContext()[3].getName() " + getClassContext()[3].getName()); return getClassContext()[3].getName(); } @@ -177,7 +179,7 @@ public class FlexLogger extends SecurityManager { /** * Returns an instance of Logger4J. - * + * * @param name the name of the logger */ private static Logger4J getLog4JLogger(String name) { @@ -193,7 +195,7 @@ public class FlexLogger extends SecurityManager { /** * Returns an instance of EelfLogger. - * + * * @param clazz the class * @param isNewTransaction is a new transaction */ @@ -218,11 +220,11 @@ public class FlexLogger extends SecurityManager { } // installl already created but it is new transaction if (isNewTransaction) { - String transId = PolicyLogger.postMDCInfoForEvent(null); + String transId = PolicyLogger.postMdcInfoForEvent(null); logger.setTransId(transId); } } - System.out.println("eelfLoggerMap size : " + eelfLoggerMap.size() + " class name: " + className); + displayMessage("eelfLoggerMap size : " + eelfLoggerMap.size() + " class name: " + className); return logger; } @@ -246,37 +248,24 @@ public class FlexLogger extends SecurityManager { */ 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); + displayMessage("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); + String overrideLogbackLevel = properties.getProperty("override.logback.level.setup"); + displayMessage("FlexLogger:overrideLogbackLevel => " + overrideLogbackLevel); + String loggerTypeString = properties.getProperty("logger.type"); + if ("EELF".equalsIgnoreCase(loggerTypeString) && "TRUE".equalsIgnoreCase(overrideLogbackLevel)) { + displayMessage("FlexLogger: start listener."); + properties = PropertyUtil.getProperties("config/policyLogger.properties", + new PropertiesCallBack("FlexLogger-CallBack")); } } } catch (IOException e1) { - System.out.println("initlogger" + e1); + displayMessage("initlogger" + e1); } finally { // OK to pass no properties (null) loggerType = PolicyLogger.init(properties); @@ -309,8 +298,8 @@ public class FlexLogger extends SecurityManager { 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); + displayMessage("FlexLogger.propertiesChanged : called at time : " + formatedTime); + displayMessage("FlexLogger.propertiesChanged : debugLevel : " + debugLevel); if (changedKeys != null) { @@ -332,5 +321,4 @@ public class FlexLogger extends SecurityManager { } } } - } 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 f74aca14..d6f020e0 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,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP-Logging * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -195,12 +195,12 @@ public interface Logger { /** * Populates MDC info. */ - public String postMDCInfoForEvent(String transId); + public String postMdcInfoForEvent(String transId); /** * Populates MDC Info. */ - public void postMDCInfoForEvent(Object obj); + public void postMdcInfoForEvent(Object obj); /** * Sets transaction Id. @@ -215,6 +215,6 @@ public interface Logger { /** * Populates MDC Info for the rule triggered. */ - public void postMDCInfoForTriggeredRule(String transId); + 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 88d3800a..8802d17e 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 @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP-Logging * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,6 +20,8 @@ package org.onap.policy.common.logging.flexlogger; +import static org.onap.policy.common.logging.flexlogger.DisplayUtils.displayMessage; + import com.att.eelf.configuration.EELFLogger.Level; import java.io.IOException; @@ -47,11 +49,11 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Constructor. - * + * * @param clazz the class */ public Logger4J(Class<?> clazz) { - System.out.println("create instance of Logger4J"); + displayMessage("create instance of Logger4J"); if (clazz != null) { log = Logger.getLogger(clazz); className = clazz.getName(); @@ -60,12 +62,12 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * 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"); + displayMessage("create instance of Logger4J"); if (name != null) { log = Logger.getLogger(name); } @@ -91,7 +93,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records a message. - * + * * @param message the message */ @Override @@ -103,7 +105,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records a message. - * + * * @param message the message * @param throwable the throwable */ @@ -114,7 +116,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records an error message. - * + * * @param message the message */ @Override @@ -124,7 +126,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records an error message. - * + * * @param message the message * @param throwable the throwable */ @@ -135,7 +137,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records an error message. - * + * * @param msg the message code * @param throwable the throwable * @param arguments the messages @@ -148,7 +150,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records an error message. - * + * * @param msg the message code * @param arguments the messages */ @@ -159,7 +161,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records a message. - * + * * @param message the message */ @Override @@ -169,7 +171,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records a message. - * + * * @param message the message * @param throwable the throwable */ @@ -180,7 +182,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records a message. - * + * * @param message the message */ @Override @@ -190,7 +192,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records a message. - * + * * @param message the message * @param throwable the throwable */ @@ -201,7 +203,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records a message. - * + * * @param msg the message code * @param arguments the messages */ @@ -212,7 +214,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records a message. - * + * * @param msg the message code * @param throwable the throwable * @param arguments the messages @@ -224,7 +226,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records a message. - * + * * @param message the message */ @Override @@ -234,7 +236,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records a message. - * + * * @param message the message * @param throwable the throwable */ @@ -245,7 +247,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Returns true for debug enabled, or false for not. - * + * * @return boolean */ @Override @@ -255,7 +257,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Returns true for error enabled, or false for not. - * + * * @return boolean */ @SuppressWarnings("deprecation") @@ -266,7 +268,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Returns true for info enabled, or false for not. - * + * * @return boolean */ @Override @@ -276,7 +278,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Returns true for warn enabled, or false for not. - * + * * @return boolean */ @SuppressWarnings("deprecation") @@ -288,7 +290,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Returns true for audit enabled, or false for not. - * + * * @return boolean */ @Override @@ -298,7 +300,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Returns true for metrics enabled, or false for not. - * + * * @return boolean */ @Override @@ -308,7 +310,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records an audit message. - * + * * @param message the message */ @Override @@ -318,7 +320,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records an audit message. - * + * * @param message the message * @param throwable the throwable */ @@ -330,7 +332,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records an audit message. - * + * * @param eventId the event ID */ @Override @@ -340,7 +342,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records an audit message. - * + * * @param eventId the event ID */ @Override @@ -352,7 +354,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records an audit message. - * + * * @param eventId the event ID * @param rule the rule * @param policyVersion the policy version @@ -364,7 +366,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records an audit message. - * + * * @param eventId the event ID * @param rule the rule * @param policyVersion the policy version @@ -380,7 +382,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records an audit message. - * + * * @param eventId the event ID * @param rule the rule */ @@ -391,7 +393,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records an audit message. - * + * * @param eventId the event ID * @param rule the rule */ @@ -406,7 +408,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records a metrics message. - * + * * @param eventId the event ID * @param message the message */ @@ -418,7 +420,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records a metrics message. - * + * * @param eventId the event ID * @param message the message */ @@ -433,7 +435,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records a metrics message. - * + * * @param message the message */ @Override @@ -443,11 +445,11 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Returns transaction Id. - * + * * @param transId the transaction ID */ @Override - public String postMDCInfoForEvent(String transId) { + public String postMdcInfoForEvent(String transId) { String transactionId = transId; if (transactionId == null || transactionId.isEmpty()) { transactionId = UUID.randomUUID().toString(); @@ -458,17 +460,17 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records transaction Id. - * + * * @param message the message */ @Override - public void postMDCInfoForEvent(Object message) { + public void postMdcInfoForEvent(Object message) { log.info(message); } /** * Returns true for trace enabled, or false for not. - * + * * @return boolean */ @Override @@ -478,11 +480,11 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records transaction Id. - * + * * @param transId the transaction ID */ @Override - public void postMDCInfoForTriggeredRule(String transId) { + public void postMdcInfoForTriggeredRule(String transId) { log.info(transId); } 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 9d9165ef..38759bc2 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,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP-Logging * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,6 +20,8 @@ package org.onap.policy.common.logging.flexlogger; +import static org.onap.policy.common.logging.flexlogger.DisplayUtils.displayErrorMessage; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -36,7 +38,7 @@ import java.util.TimerTask; * notifications of future changes. */ public class PropertyUtil { - + protected static class LazyHolder { /** * Timer thread. Will not be allocated by the JVM until it is first referenced. @@ -50,7 +52,7 @@ public class PropertyUtil { /** * 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 @@ -74,7 +76,7 @@ public class PropertyUtil { /** * 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 @@ -94,7 +96,7 @@ public class PropertyUtil { 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 @@ -150,7 +152,7 @@ public class PropertyUtil { try { poll(); } catch (Exception e) { - System.err.println(e); + displayErrorMessage(e); } } }; @@ -159,7 +161,7 @@ public class PropertyUtil { /** * 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 */ @@ -170,7 +172,7 @@ public class PropertyUtil { /** * Remove a listener from the notification list. - * + * * @param listener this is the listener to remove */ synchronized void removeListener(Listener listener) { @@ -190,7 +192,7 @@ public class PropertyUtil { /** * 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 { @@ -308,7 +310,7 @@ public class PropertyUtil { /** * 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 @@ -325,7 +327,7 @@ public class PropertyUtil { /** * 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 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 70ad08ae..f7a68a3d 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 @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP-Logging * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,6 +20,8 @@ package org.onap.policy.common.logging.flexlogger; +import static org.onap.policy.common.logging.flexlogger.DisplayUtils.displayMessage; + import com.att.eelf.configuration.EELFLogger.Level; import java.io.Serializable; @@ -46,11 +48,11 @@ public class SystemOutLogger implements Logger, Serializable { /** * Constructor. - * + * * @param clazz the class */ public SystemOutLogger(Class<?> clazz) { - System.out.println("create instance of SystemOutLogger"); + displayMessage("create instance of SystemOutLogger"); if (clazz != null) { className = clazz.getName(); } @@ -59,11 +61,11 @@ public class SystemOutLogger implements Logger, Serializable { /** * Constructor. - * + * * @param className the class name */ public SystemOutLogger(String className) { - System.out.println("create instance of SystemOutLogger"); + displayMessage("create instance of SystemOutLogger"); if (className != null) { this.className = className; } @@ -114,7 +116,7 @@ public class SystemOutLogger implements Logger, Serializable { @Override public void setTransId(String transId) { - System.out.println(transId); + displayMessage(transId); this.transId = transId; } @@ -129,129 +131,129 @@ public class SystemOutLogger implements Logger, Serializable { /** * Records a message. - * + * * @param message the message */ @Override public void debug(Object message) { - System.out.println(transId + "|" + className + " : " + message); + displayMessage(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); + displayMessage(transId + "|" + className + " : " + message + ":" + throwable); } /** * Records an error message. - * + * * @param message the message */ @Override public void error(Object message) { - System.out.println(transId + "|" + className + " : " + message); + displayMessage(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); + displayMessage(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)); + displayMessage(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)); + displayMessage(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); + displayMessage(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); + displayMessage(transId + "|" + className + " : " + message + ":" + throwable); } /** * Records a message. - * + * * @param message the message */ @Override public void warn(Object message) { - System.out.println(transId + "|" + className + " : " + message); + displayMessage(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); + displayMessage(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)); + displayMessage(transId + "|" + className + " : " + "MessageCodes:" + msg + Arrays.asList(arguments)); } /** * Records a message. - * + * * @param msg the message code * @param throwable the throwable * @param arguments the messages @@ -259,34 +261,34 @@ public class SystemOutLogger implements Logger, Serializable { @Override public void warn(MessageCodes msg, Throwable throwable, String... arguments) { - System.out.println(transId + "|" + className + " : " + "MessageCodes:" + msg + Arrays.asList(arguments)); + displayMessage(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); + displayMessage(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); + displayMessage(transId + "|" + className + " : " + message + ":" + throwable); } /** * Returns true for debug enabled, or false for not. - * + * * @return boolean */ @Override @@ -296,7 +298,7 @@ public class SystemOutLogger implements Logger, Serializable { /** * Returns true for warn enabled, or false for not. - * + * * @return boolean */ @Override @@ -306,7 +308,7 @@ public class SystemOutLogger implements Logger, Serializable { /** * Returns true for info enabled, or false for not. - * + * * @return boolean */ @Override @@ -316,7 +318,7 @@ public class SystemOutLogger implements Logger, Serializable { /** * Returns true for error enabled, or false for not. - * + * * @return boolean */ @Override @@ -326,7 +328,7 @@ public class SystemOutLogger implements Logger, Serializable { /** * Returns true for audit enabled, or false for not. - * + * * @return boolean */ @Override @@ -337,7 +339,7 @@ public class SystemOutLogger implements Logger, Serializable { /** * Returns true for metrics enabled, or false for not. - * + * * @return boolean */ @Override @@ -348,52 +350,52 @@ public class SystemOutLogger implements Logger, Serializable { /** * Records an audit message. - * + * * @param message the message */ @Override public void audit(Object message) { - System.out.println(transId + "|" + className + " : " + message); + displayMessage(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); + displayMessage(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); + displayMessage(transId + "|" + className + " : " + eventId); } /** * Records an audit message. - * + * * @param eventId the event ID */ @Override public void recordAuditEventStart(UUID eventId) { - System.out.println(eventId); + displayMessage(eventId); } /** * Records an audit message. - * + * * @param eventId the event ID * @param rule the rule * @param policyVersion the policy version @@ -401,12 +403,12 @@ public class SystemOutLogger implements Logger, Serializable { @Override public void recordAuditEventEnd(String eventId, String rule, String policyVersion) { - System.out.println(className + " : " + eventId + ":" + rule + ":" + policyVersion); + displayMessage(className + " : " + eventId + ":" + rule + ":" + policyVersion); } /** * Records an audit message. - * + * * @param eventId the event ID * @param rule the rule * @param policyVersion the policy version @@ -414,76 +416,76 @@ public class SystemOutLogger implements Logger, Serializable { @Override public void recordAuditEventEnd(UUID eventId, String rule, String policyVersion) { - System.out.println(className + " : " + eventId + ":" + rule + ":" + policyVersion); + displayMessage(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); + displayMessage(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); + displayMessage(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); + displayMessage(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); + displayMessage(className + " : " + eventId + ":" + message); } /** * Records a metrics message. - * + * * @param message the message */ @Override public void metrics(Object message) { - System.out.println(className + " : " + message); + displayMessage(className + " : " + message); } /** * Returns transaction Id. - * + * * @param transId the transaction ID */ @Override - public String postMDCInfoForEvent(String transId) { + public String postMdcInfoForEvent(String transId) { String transactionId = transId; if (transactionId == null || transactionId.isEmpty()) { @@ -495,18 +497,18 @@ public class SystemOutLogger implements Logger, Serializable { /** * Records transaction Id. - * + * * @param message the message */ @Override - public void postMDCInfoForEvent(Object message) { - System.out.println(message); + public void postMdcInfoForEvent(Object message) { + displayMessage(message); } /** * Returns true for trace enabled, or false for not. - * + * * @return boolean */ @Override @@ -517,13 +519,12 @@ public class SystemOutLogger implements Logger, Serializable { /** * Records transaction Id. - * + * * @param transId the transaction ID */ @Override - public void postMDCInfoForTriggeredRule(String transId) { + public void postMdcInfoForTriggeredRule(String transId) { - System.out.println(transId); + displayMessage(transId); } - } |