From f05c67c2d001d14b0ee564cd7650eea974e578e0 Mon Sep 17 00:00:00 2001 From: Kishore Reddy Dwaram Date: Fri, 23 Oct 2020 09:44:34 -0400 Subject: Getting stack trace in debug log and error message in error log Issue-ID: PORTAL-1008 Signed-off-by: Kishore Reddy Dwaram Change-Id: I59cf6773316316233157acfb0db7182381bdc8cd --- .../portalsdk/core/logging/logic/EELFLoggerDelegate.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java b/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java index b28bcf5a..f74571b5 100644 --- a/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java +++ b/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java @@ -47,6 +47,7 @@ import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME; import java.net.InetAddress; import java.text.MessageFormat; import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.Date; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -134,7 +135,14 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger { } if (logger.isErrorEnabled()) { - logger.log(level, msg, null, arguments); + Object[] transformedArgs = Arrays.stream(arguments).map(argument -> { + if (argument instanceof Throwable) + return ((Throwable) argument).getMessage(); + else + return argument; + }).toArray(); + logger.log(level, msg, null, transformedArgs); + debugLogger.error(msg, arguments); } else { logger.log(level, msg, th, arguments); } @@ -350,7 +358,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger { * @param th */ public void error(EELFLogger logger, String msg, Throwable th) { - logWrite(logger, Level.ERROR, msg, null); + logWrite(logger, Level.ERROR, msg, null, th); } /** @@ -407,6 +415,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger { } catch (Exception e) { validateErrorLogFields(); errorLogger.error("logEcompError failed " + e.getMessage()); + debugLogger.error("logEcompError failed " , e); } finally { MDC.remove(LoggerProperties.ERROR_CODE); MDC.remove(LoggerProperties.ERROR_DESCRIPTION); @@ -446,6 +455,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger { } catch (Exception e) { validateErrorLogFields(); errorLogger.error("setGlobalLoggingContext failed " + e.getMessage()); + debugLogger.error("setGlobalLoggingContext failed ", e); } } @@ -548,6 +558,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger { } catch (Exception e) { validateErrorLogFields(); errorLogger.error("calculateDateTimeDifference failed " + e.getMessage()); + debugLogger.error("calculateDateTimeDifference failed ", e); } } } -- cgit 1.2.3-korg