diff options
Diffstat (limited to 'common-logging/src/main/java/org/onap/policy/common/logging/flexlogger')
4 files changed, 287 insertions, 9 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 a3e5cc8f..df60fa9c 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,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-Logging * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 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. @@ -166,6 +166,17 @@ public class EelfLogger implements Logger, Serializable { } /** + * Records a message. + * + * @param message the message + * @param arguments the arguments for message + */ + @Override + public void debug(String message, Object... arguments) { + PolicyLogger.debug(message, arguments); + } + + /** * Records an error message. * * @param message the message @@ -210,6 +221,17 @@ public class EelfLogger implements Logger, Serializable { } /** + * Records an error message. + * + * @param message the message + * @param arguments the arguments for message + */ + @Override + public void error(String message, Object... arguments) { + PolicyLogger.error(message, arguments); + } + + /** * Records a message. * * @param message the message @@ -234,6 +256,17 @@ public class EelfLogger implements Logger, Serializable { * Records a message. * * @param message the message + * @param arguments the arguments for message + */ + @Override + public void info(String message, Object... arguments) { + PolicyLogger.info(message, arguments); + } + + /** + * Records a message. + * + * @param message the message */ @Override public void warn(Object message) { @@ -278,6 +311,17 @@ public class EelfLogger implements Logger, Serializable { * Records a message. * * @param message the message + * @param arguments the arguments for message + */ + @Override + public void warn(String message, Object... arguments) { + PolicyLogger.warn(message, arguments); + } + + /** + * Records a message. + * + * @param message the message */ @Override public void trace(Object message) { @@ -387,6 +431,17 @@ public class EelfLogger implements Logger, Serializable { } /** + * Records a message. + * + * @param message the message + * @param arguments the arguments for message + */ + @Override + public void audit(String message, Object... arguments) { + PolicyLogger.audit(message, arguments); + } + + /** * Records an audit message. * * @param eventId the event ID @@ -485,6 +540,17 @@ public class EelfLogger implements Logger, Serializable { } /** + * Records a message. + * + * @param message the message + * @param arguments the arguments for message + */ + @Override + public void metrics(String message, Object... arguments) { + PolicyLogger.metrics(message, arguments); + } + + /** * Populates MDC Info. * * @param transId the transaction ID 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 d6f020e0..315cd935 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-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 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. @@ -41,6 +41,11 @@ public interface Logger { public void debug(Object message, Throwable throwable); /** + * Prints messages with the level.DEBUG + */ + public void debug(String message, Object... arguments); + + /** * Prints messages with the level.ERROR */ public void error(Object message); @@ -61,6 +66,11 @@ public interface Logger { public void error(MessageCodes msg, Throwable arg0, String... arguments); /** + * Prints messages with the level.ERROR + */ + public void error(String message, Object... arguments); + + /** * Prints messages with the level.INFO */ public void info(Object message); @@ -71,6 +81,11 @@ public interface Logger { public void info(Object message, Throwable throwable); /** + * Prints messages with the level.INFO + */ + public void info(String message, Object... arguments); + + /** * Prints messages with the level.WARN */ public void warn(Object message); @@ -91,6 +106,11 @@ public interface Logger { public void warn(MessageCodes msg, Throwable arg0, String... arguments); /** + * Prints messages with the level.WARN + */ + public void warn(String message, Object... arguments); + + /** * Prints messages with the level.TRACE */ public void trace(Object message); @@ -111,6 +131,11 @@ public interface Logger { public void audit(Object arg0, Throwable throwable); /** + * Prints messages in audit log with the level.INFO + */ + public void audit(String message, Object... arguments); + + /** * Records event Id in audit log with the level.INFO */ public void recordAuditEventStart(String eventId); @@ -157,6 +182,11 @@ public interface Logger { public void metrics(Object arg0); /** + * Records the Metrics log message. + */ + public void metrics(String message, Object... arguments); + + /** * Returns a boolean value, true for debug logging enabled, false for not enabled. */ public boolean isDebugEnabled(); 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 5af40b09..bb5e1142 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 @@ -33,6 +33,7 @@ import java.util.UUID; import org.apache.log4j.Logger; import org.apache.log4j.Priority; +import org.onap.policy.common.logging.OnapLoggingUtils; import org.onap.policy.common.logging.eelf.MessageCodes; import org.onap.policy.common.logging.eelf.PolicyLogger; @@ -115,6 +116,21 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge } /** + * Records a message. + * + * @param message the message + * @param arguments variable number of arguments + */ + @Override + public void debug(String message, Object... arguments) { + if (arguments.length == 1 && OnapLoggingUtils.isThrowable(arguments[0])) { + log.debug(message, (Throwable)arguments[0]); + } else { + log.debug(OnapLoggingUtils.formatMessage(message, arguments)); + } + } + + /** * Records an error message. * * @param message the message @@ -163,6 +179,21 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge * Records a message. * * @param message the message + * @param arguments variable number of arguments + */ + @Override + public void error(String message, Object... arguments) { + if (arguments.length == 1 && OnapLoggingUtils.isThrowable(arguments[0])) { + log.error(message, (Throwable)arguments[0]); + } else { + log.error(OnapLoggingUtils.formatMessage(message, arguments)); + } + } + + /** + * Records a message. + * + * @param message the message */ @Override public void info(Object message) { @@ -184,6 +215,21 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge * Records a message. * * @param message the message + * @param arguments variable number of arguments + */ + @Override + public void info(String message, Object... arguments) { + if (arguments.length == 1 && OnapLoggingUtils.isThrowable(arguments[0])) { + log.info(message, (Throwable)arguments[0]); + } else { + log.info(OnapLoggingUtils.formatMessage(message, arguments)); + } + } + + /** + * Records a message. + * + * @param message the message */ @Override public void warn(Object message) { @@ -228,6 +274,21 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge * Records a message. * * @param message the message + * @param arguments variable number of arguments + */ + @Override + public void warn(String message, Object... arguments) { + if (arguments.length == 1 && OnapLoggingUtils.isThrowable(arguments[0])) { + log.warn(message, (Throwable)arguments[0]); + } else { + log.warn(OnapLoggingUtils.formatMessage(message, arguments)); + } + } + + /** + * Records a message. + * + * @param message the message */ @Override public void trace(Object message) { @@ -333,6 +394,21 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge /** * Records an audit message. * + * @param message the message + * @param arguments variable number of arguments + */ + @Override + public void audit(String message, Object... arguments) { + if (arguments.length == 1) { + log.info(message, (Throwable)arguments[0]); + } else { + log.info(OnapLoggingUtils.formatMessage(message, arguments)); + } + } + + /** + * Records an audit message. + * * @param eventId the event ID */ @Override @@ -444,6 +520,22 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge } /** + * Records a metrics message. + * + * @param message the message + * @param arguments variable number of arguments + */ + @Override + public void metrics(String message, Object... arguments) { + if (arguments.length > 0 && OnapLoggingUtils.isThrowable(arguments[arguments.length - 1])) { + log.info(OnapLoggingUtils.formatMessage(message, arguments), + (Throwable)arguments[arguments.length - 1]); + } else { + log.info(OnapLoggingUtils.formatMessage(message, arguments)); + } + } + + /** * Returns transaction Id. * * @param transId the transaction ID @@ -511,4 +603,5 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge // look up associated logger log = Logger.getLogger(className); } + } 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 f7a68a3d..bc7633da 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,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-Logging * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 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. @@ -28,6 +28,7 @@ import java.io.Serializable; import java.util.Arrays; import java.util.UUID; +import org.onap.policy.common.logging.OnapLoggingUtils; import org.onap.policy.common.logging.eelf.MessageCodes; import org.onap.policy.common.logging.eelf.PolicyLogger; @@ -152,6 +153,21 @@ public class SystemOutLogger implements Logger, Serializable { } /** + * Records a message. + * + * @param message the message + * @param arguments variable number of arguments + */ + @Override + public void debug(String message, Object...arguments) { + if (arguments.length == 1 && OnapLoggingUtils.isThrowable(arguments[0])) { + displayMessage(transId + "|" + className + " : " + message + ":" + arguments[0]); + } else { + displayMessage(OnapLoggingUtils.formatMessage(message, arguments)); + } + } + + /** * Records an error message. * * @param message the message @@ -193,11 +209,25 @@ public class SystemOutLogger implements Logger, Serializable { */ @Override public void error(MessageCodes msg, String... arguments) { - displayMessage(transId + "|" + className + " : " + "MessageCode:" + msg + Arrays.asList(arguments)); } /** + * Records a error message. + * + * @param message the message + * @param arguments variable number of arguments + */ + @Override + public void error(String message, Object...arguments) { + if (arguments.length == 1 && OnapLoggingUtils.isThrowable(arguments[0])) { + displayMessage(transId + "|" + className + " : " + message + ":" + arguments[0]); + } else { + displayMessage(OnapLoggingUtils.formatMessage(message, arguments)); + } + } + + /** * Records a message. * * @param message the message @@ -222,21 +252,25 @@ public class SystemOutLogger implements Logger, Serializable { * Records a message. * * @param message the message + * @param arguments variable number of arguments */ @Override - public void warn(Object message) { - displayMessage(transId + "|" + className + " : " + message); + public void info(String message, Object...arguments) { + if (arguments.length == 1 && OnapLoggingUtils.isThrowable(arguments[0])) { + displayMessage(transId + "|" + className + " : " + message + ":" + arguments[0]); + } else { + displayMessage(OnapLoggingUtils.formatMessage(message, arguments)); + } } /** * Records a message. * * @param message the message - * @param throwable the throwable */ @Override - public void warn(Object message, Throwable throwable) { - displayMessage(transId + "|" + className + " : " + message + ":" + throwable); + public void warn(Object message) { + displayMessage(transId + "|" + className + " : " + message); } /** @@ -254,6 +288,17 @@ public class SystemOutLogger implements Logger, Serializable { /** * Records a message. * + * @param message the message + * @param throwable the throwable + */ + @Override + public void warn(Object message, Throwable throwable) { + displayMessage(transId + "|" + className + " : " + message + ":" + throwable); + } + + /** + * Records a message. + * * @param msg the message code * @param throwable the throwable * @param arguments the messages @@ -269,6 +314,21 @@ public class SystemOutLogger implements Logger, Serializable { * Records a message. * * @param message the message + * @param arguments variable number of arguments + */ + @Override + public void warn(String message, Object...arguments) { + if (arguments.length == 1 && OnapLoggingUtils.isThrowable(arguments[0])) { + displayMessage(transId + "|" + className + " : " + message + ":" + arguments[0]); + } else { + displayMessage(OnapLoggingUtils.formatMessage(message, arguments)); + } + } + + /** + * Records a message. + * + * @param message the message */ @Override public void trace(Object message) { @@ -373,6 +433,20 @@ public class SystemOutLogger implements Logger, Serializable { /** * Records an audit message. * + * @param message the message + */ + @Override + public void audit(String message, Object... arguments) { + if (arguments.length == 1) { + displayMessage(transId + "|" + className + " : " + message + ":" + arguments[0]); + } else { + displayMessage(OnapLoggingUtils.formatMessage(message, arguments)); + } + } + + /** + * Records an audit message. + * * @param eventId the event ID */ @Override @@ -480,6 +554,21 @@ public class SystemOutLogger implements Logger, Serializable { } /** + * Records a metrics message. + * + * @param message the message + * @param arguments the arguments + */ + @Override + public void metrics(String message, Object... arguments) { + if (arguments.length == 1) { + displayMessage(className + " : " + message + " : " + arguments[0]); + } else { + displayMessage(OnapLoggingUtils.formatMessage(message, arguments)); + } + } + + /** * Returns transaction Id. * * @param transId the transaction ID |