* ============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.
return requestContext;
}
+ /**
+ * Create message text replace {} place holder with data
+ * if last argument is throwable/exception, pass it as argument to logger.
+ * @param format message format can contains text and {}
+ * @param arguments output arguments
+ * @return
+ */
+ public static String formatMessage(String format, Object ...arguments) {
+ if (arguments.length <= 0 || arguments[0] == null) {
+ return format;
+ }
+ int index;
+ StringBuilder builder = new StringBuilder();
+ String[] token = format.split("[{][}]");
+ for (index = 0; index < arguments.length; index++) {
+ if (index < token.length) {
+ builder.append(token[index]);
+ builder.append(arguments[index]);
+ } else {
+ break;
+ }
+ }
+ for (int index2 = index; index2 < token.length; index2++) {
+ builder.append(token[index2]);
+ }
+
+ return builder.toString();
+ }
+
+ /**
+ * Check object is throwable.
+ * @param obj to verify
+ * @return true if object is throwable or false otherwise
+ */
+ public static boolean isThrowable(Object obj) {
+ return (obj instanceof Throwable);
+ }
}
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.Instant;
+import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Consumer;
import org.apache.commons.lang3.StringUtils;
+import org.onap.policy.common.logging.OnapLoggingUtils;
import org.onap.policy.common.logging.flexlogger.LoggerType;
import org.slf4j.MDC;
* Set Timestamps for start, end and duration of logging a transaction.
*/
private static void seTimeStamps() {
-
MDC.put(MDC_INSTANCE_UUID, "");
MDC.put(MDC_ALERT_SEVERITY, "");
debugLogger.info(msg, arguments);
}
- /**
- * Records only one String message with its class name.
- *
- * @param className the class name
- * @param arg0 the message
- */
- public static void info(String className, String arg0) {
- MDC.put(classNameProp, className);
- debugLogger.info(MessageCodes.GENERAL_INFO, arg0);
- }
-
-
/**
* Records only one String message.
*
}
/**
- * Records only one String message with its class name.
+ * Records a message with passed in message text and variable number of arguments.
*
- * @param arg0 log message
- * @param className class name
+ * @param message class name if one argument, otherwise message text
+ * @param arguments variable number of arguments
*/
- public static void warn(String className, String arg0) {
- MDC.put(classNameProp, className);
- debugLogger.warn(MessageCodes.GENERAL_INFO, arg0);
+ public static void info(String message, Object... arguments) {
+ if (!debugLogger.isInfoEnabled()) {
+ return;
+ }
+ if (arguments.length == 1 && !OnapLoggingUtils.isThrowable(arguments[0])) {
+ MDC.put(classNameProp, message);
+ debugLogger.info(MessageCodes.GENERAL_INFO,
+ arguments[0] == null ? "" : arguments[0].toString());
+ return;
+ }
+ if (arguments.length == 1 && OnapLoggingUtils.isThrowable(arguments[0])) {
+ String arguments2 = getNormalizedStackTrace((Throwable)arguments[0], "");
+ debugLogger.info(MessageCodes.GENERAL_INFO, message + arguments2);
+ return;
+ }
+
+ MDC.put(classNameProp, "");
+ debugLogger.info(message, arguments);
}
/**
}
/**
- * Records only one String message with its class name.
+ * Records a message with passed in message text and variable number of arguments.
*
- * @param className class name
- * @param arg0 log message
+ * @param message class name if one argument, otherwise message text
+ * @param arguments variable number of arguments
*/
- public static void error(String className, String arg0) {
- MDC.put(classNameProp, className);
- setErrorCode(MessageCodes.GENERAL_ERROR);
- errorLogger.error(MessageCodes.GENERAL_ERROR, arg0);
+ public static void warn(String message, Object... arguments) {
+ if (!debugLogger.isWarnEnabled()) {
+ return;
+ }
+ if (arguments.length == 1 && !OnapLoggingUtils.isThrowable(arguments[0])) {
+ MDC.put(classNameProp, message);
+ debugLogger.warn(MessageCodes.GENERAL_INFO,
+ arguments[0] == null ? "" : arguments[0].toString());
+ return;
+ }
+ if (arguments.length == 1 && OnapLoggingUtils.isThrowable(arguments[0])) {
+ String arguments2 = getNormalizedStackTrace((Throwable)arguments[0], "");
+ debugLogger.warn(MessageCodes.GENERAL_INFO, message + arguments2);
+ return;
+ }
+ MDC.put(classNameProp, "");
+ debugLogger.warn(message, arguments);
}
/**
}
/**
- * Records a message with passed in message code and a list of string values.
+ * Records a message with passed in message text and variable number of arguments.
*
- * @param msg the message code
- * @param arguments the messages
+ * @param message class name if one argument, otherwise message text
+ * @param arguments variable number of arguments
*/
- public static void debug(MessageCodes msg, String... arguments) {
+ public static void error(String message, Object... arguments) {
+ if (!errorLogger.isErrorEnabled()) {
+ return;
+ }
+ if (arguments.length == 1 && !OnapLoggingUtils.isThrowable(arguments[0])) {
+ MDC.put(classNameProp, message);
+ setErrorCode(MessageCodes.GENERAL_ERROR);
+ errorLogger.error(MessageCodes.GENERAL_ERROR,
+ arguments[0] == null ? "" : arguments[0].toString());
+ return;
+ }
+ if (arguments.length == 1 && OnapLoggingUtils.isThrowable(arguments[0])) {
+ String arguments2 = getNormalizedStackTrace((Throwable)arguments[0], "");
+ errorLogger.error(MessageCodes.GENERAL_ERROR, message + arguments2);
+ return;
+ }
MDC.put(classNameProp, "");
- debugLogger.debug(msg, arguments);
+ setErrorCode(MessageCodes.GENERAL_ERROR);
+ errorLogger.error(message, arguments);
}
/**
- * Records only one String message with its class name.
+ * Records a message with passed in message code and a list of string values.
*
- * @param className the class name
- * @param arg0 the message
+ * @param msg the message code
+ * @param arguments the messages
*/
- public static void debug(String className, String arg0) {
- MDC.put(classNameProp, className);
- debugLogger.debug(MessageCodes.GENERAL_INFO, arg0);
+ public static void debug(MessageCodes msg, String... arguments) {
+ MDC.put(classNameProp, "");
+ debugLogger.debug(msg, arguments);
}
/**
}
/**
- * Records only one String message with its class name.
+ * Records a message with passed in message text and variable number of arguments.
*
- * @param className the class name
- * @param arg0 the message
+ * @param message class name if one argument, otherwise message text
+ * @param arguments variable number of arguments
*/
- public static void audit(String className, Object arg0) {
- MDC.put(INVOCATION_ID, MDC.get(MDC_KEY_REQUEST_ID));
- MDC.put(STATUS_CODE, COMPLETE_STATUS);
- MDC.put(RESPONSE_CODE, "0");
- MDC.put(classNameProp, className);
- auditLogger.info("" + arg0);
+ public static void debug(String message, Object... arguments) {
+ if (!debugLogger.isDebugEnabled()) {
+ return;
+ }
+ if (arguments.length == 1 && !OnapLoggingUtils.isThrowable(arguments[0])) {
+ MDC.put(classNameProp, message);
+ debugLogger.debug(MessageCodes.GENERAL_INFO,
+ arguments[0] == null ? "" : arguments[0].toString());
+ return;
+ }
+ if (arguments.length == 1 && OnapLoggingUtils.isThrowable(arguments[0])) {
+ String arguments2 = getNormalizedStackTrace((Throwable)arguments[0], "");
+ debugLogger.debug(MessageCodes.GENERAL_INFO, message + arguments2);
+ return;
+ }
+ MDC.put(classNameProp, "");
+ debugLogger.debug(message, arguments);
}
/**
auditLogger.info("" + arg0);
}
+ /**
+ * Records a message with passed in message text and variable number of arguments.
+ *
+ * @param message class name if one argument, otherwise message text
+ * @param arguments variable number of arguments
+ */
+ public static void audit(String message, Object... arguments) {
+ if (!auditLogger.isInfoEnabled()) {
+ return;
+ }
+ MDC.put(INVOCATION_ID, postMdcInfoForEvent(null));
+ MDC.put(STATUS_CODE, COMPLETE_STATUS);
+ MDC.put(RESPONSE_CODE, "0");
+ if (arguments.length == 1 && !OnapLoggingUtils.isThrowable(arguments[0])) {
+ MDC.put(classNameProp, message);
+ auditLogger.info(arguments[0] == null ? "" : arguments[0].toString());
+ return;
+ }
+
+ MDC.put(classNameProp, "");
+ auditLogger.info(message, arguments);
+ }
+
/**
* returns true for enabled, false for not enabled.
*/
* @param arg0 the message
*/
public static void metrics(String arg0) {
+ seTimeStamps();
MDC.put(INVOCATION_ID, MDC.get(MDC_KEY_REQUEST_ID));
MDC.put(RESPONSE_CODE, "0");
String serviceName = MDC.get(MDC_SERVICE_NAME);
}
/**
- * Records the metrics event with a class name and a String message.
+ * Records the metrics event with a String message.
*
* @param arg0 the message
*/
- public static void metrics(String className, Object arg0) {
+ public static void metrics(Object arg0) {
seTimeStamps();
MDC.put(INVOCATION_ID, MDC.get(MDC_KEY_REQUEST_ID));
MDC.put(RESPONSE_CODE, "0");
- MDC.put(classNameProp, className);
+ MDC.put(classNameProp, "");
String serviceName = MDC.get(MDC_SERVICE_NAME);
metricsLogger.info(MessageCodes.RULE_METRICS_INFO, serviceName, "" + arg0);
}
/**
- * Records the metrics event with a String message.
+ * Records a message with passed in message text and variable number of arguments.
*
- * @param arg0 the message
+ * @param message class name if one argument, otherwise message text
+ * @param arguments variable number of arguments
*/
- public static void metrics(Object arg0) {
+ public static void metrics(String message, Object... arguments) {
+ if (!metricsLogger.isInfoEnabled()) {
+ return;
+ }
seTimeStamps();
MDC.put(INVOCATION_ID, MDC.get(MDC_KEY_REQUEST_ID));
MDC.put(RESPONSE_CODE, "0");
+ if (arguments.length == 1 && !OnapLoggingUtils.isThrowable(arguments[0])) {
+ MDC.put(classNameProp, message);
+ String serviceName = MDC.get(MDC_SERVICE_NAME);
+ metricsLogger.info(MessageCodes.RULE_METRICS_INFO, serviceName,
+ arguments[0] == null ? "" : arguments[0].toString());
+ return;
+ }
+ if (arguments.length == 1 && OnapLoggingUtils.isThrowable(arguments[0])) {
+ String arguments2 = getNormalizedStackTrace((Throwable)arguments[0], "");
+ metricsLogger.info(MessageCodes.RULE_METRICS_INFO, message + arguments2);
+ return;
+ }
+
MDC.put(classNameProp, "");
- String serviceName = MDC.get(MDC_SERVICE_NAME);
- metricsLogger.info(MessageCodes.RULE_METRICS_INFO, serviceName, "" + arg0);
+ metricsLogger.info(message, arguments);
}
/**
* ============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.
PolicyLogger.debug(MessageCodes.GENERAL_INFO, throwable, message.toString());
}
+ /**
+ * 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.
*
PolicyLogger.error(msg, arguments);
}
+ /**
+ * 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.
*
PolicyLogger.info(MessageCodes.GENERAL_INFO, throwable, message.toString());
}
+ /**
+ * 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.
*
PolicyLogger.warn(msg, className, throwable, arguments);
}
+ /**
+ * 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.
*
PolicyLogger.audit(message);
}
+ /**
+ * 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.
*
PolicyLogger.metrics(className, message);
}
+ /**
+ * 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.
*
* ============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.
*/
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(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, Throwable throwable);
+ /**
+ * Prints messages with the level.INFO
+ */
+ public void info(String message, Object... arguments);
+
/**
* Prints messages with the level.WARN
*/
*/
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 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 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.
*/
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;
log.debug(message, throwable);
}
+ /**
+ * 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.
*
log.error(transId + "|" + className + "|" + "MessageCode:" + msg + Arrays.asList(arguments));
}
+ /**
+ * 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.
*
log.info(message, throwable);
}
+ /**
+ * 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.
*
log.warn(className + "|" + "MessageCodes:" + msg + Arrays.asList(arguments));
}
+ /**
+ * 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.
*
log.info(message, throwable);
}
+ /**
+ * 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.
*
log.info(message);
}
+ /**
+ * 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.
*
// look up associated logger
log = Logger.getLogger(className);
}
+
}
* ============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.
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;
displayMessage(transId + "|" + className + " : " + message + ":" + throwable);
}
+ /**
+ * 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.
*
*/
@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.
*
* 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);
}
/**
displayMessage(transId + "|" + className + " : " + "MessageCodes:" + msg + Arrays.asList(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);
+ }
+
/**
* Records a message.
*
}
+ /**
+ * 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.
*
displayMessage(transId + "|" + className + " : " + message + ":" + throwable);
}
+ /**
+ * 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.
*
displayMessage(className + " : " + message);
}
+ /**
+ * 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.
*
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
import static org.onap.policy.common.logging.eelf.OnapConfigProperties.PARTNER_NAME;
import static org.onap.policy.common.logging.eelf.OnapConfigProperties.RESPONSE_CODE;
import static org.onap.policy.common.logging.eelf.OnapConfigProperties.RESPONSE_DESCRIPTION;
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.info("str1", "str2");
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
+ PolicyLogger.info("str1", "str2");
Mockito.verify(mockLogger).info(MessageCodes.GENERAL_INFO, "str2");
}
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn("str1", "str2");
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isWarnEnabled()).thenReturn(true);
+ PolicyLogger.warn("str1", "str2");
Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_INFO, "str2");
}
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error("str1", "str2");
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isErrorEnabled()).thenReturn(true);
+ PolicyLogger.error("str1", "str2");
Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "str2");
assertEquals("500", MDC.get("ErrorCode"));
assertEquals("This is a general error message during the process. Please check the error message for detail "
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug("str1", "str2");
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isDebugEnabled()).thenReturn(true);
+ PolicyLogger.debug("str1", "str2");
Mockito.verify(mockLogger).debug(MessageCodes.GENERAL_INFO, "str2");
}
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "auditLogger", mockLogger);
PolicyLogger.audit("PolicyLoggerTest", 1);
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
+ PolicyLogger.audit("PolicyLoggerTest", 1);
assertEquals("PolicyLoggerTest", MDC.get("ClassName"));
assertEquals("COMPLETE", MDC.get("StatusCode"));
Mockito.verify(mockLogger).info("1");
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.metrics("PolicyLoggerTest", 1);
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
+ PolicyLogger.metrics("PolicyLoggerTest", 1);
Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
Mockito.eq("1"));
}
* ONAP-Logging
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-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.
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.never;
import com.att.eelf.configuration.EELFLogger;
import java.util.UUID;
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.debug("message");
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isDebugEnabled()).thenReturn(true);
+ eelfLogger.debug("message");
Mockito.verify(mockLogger).debug(MessageCodes.GENERAL_INFO, "message");
}
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
eelfLogger.error("message");
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isErrorEnabled()).thenReturn(true);
+ eelfLogger.error("message");
Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "message");
}
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.info("message");
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
+ eelfLogger.info("message");
Mockito.verify(mockLogger).info(MessageCodes.GENERAL_INFO, "message");
}
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.warn("message");
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isWarnEnabled()).thenReturn(true);
+ eelfLogger.warn("message");
Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_INFO, "message");
}
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.info("message", new NullPointerException());
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
Mockito.verify(mockLogger).info((MessageCodes) Mockito.any(),
Mockito.startsWith("message:java.lang.NullPointerException"));
}
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "metricsLogger", mockLogger);
eelfLogger.metrics(1);
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
+ eelfLogger.metrics(1);
Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
Mockito.eq("1"));
}
try {
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
- systemOutLogger.debug(1, new NullPointerException());
+ systemOutLogger.debug("1", new NullPointerException());
assertTrue(baos.toString(),
baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
} finally {
try {
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
- systemOutLogger.error(1, new NullPointerException());
+ systemOutLogger.error("1", new NullPointerException());
assertTrue(baos.toString(),
baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
} finally {
try {
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
- systemOutLogger.info(1, new NullPointerException());
+ systemOutLogger.info("1", new NullPointerException());
assertTrue(baos.toString(),
baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
} finally {
try {
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
- systemOutLogger.warn(1, new NullPointerException());
+ systemOutLogger.warn("1", new NullPointerException());
assertTrue(baos.toString(),
baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
} finally {
try {
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
- systemOutLogger.audit(1, new NullPointerException());
+ systemOutLogger.audit("1", new NullPointerException());
assertTrue(baos.toString(),
baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
} finally {