diff options
author | Brittany Plummer (bp896r) <bp896r@att.com> | 2019-10-02 15:04:38 -0400 |
---|---|---|
committer | Brittany Plummer <bp896r@att.com> | 2019-10-08 19:08:11 +0000 |
commit | 5912e180ee78b969df71ade8fdd731bfe71c9f0e (patch) | |
tree | 8e83f221af42e63505fb02cf7c96c0bb16f181b7 /reference/logging-filter | |
parent | 2fa1397e5b73644f3d32903a606e4a53308ca047 (diff) |
Added catching error when calculating elapsedTime.
Issue-ID: LOG-1148
Change-Id: I8f94b066e1841322199c95f7de82c1a4e76fcd2f
Signed-off-by: Brittany Plummer (bp896r) <bp896r@att.com>
Diffstat (limited to 'reference/logging-filter')
-rw-r--r-- | reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java index 93c16a8..1a0c3b4 100644 --- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java +++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java @@ -146,23 +146,33 @@ public class MDCSetup { } public void setElapsedTime() { - DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME; - ZonedDateTime entryTimestamp = - ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP), timeFormatter); - ZonedDateTime endTimestamp = ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP), timeFormatter); - - MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME, - Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp))); + try { + DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME; + ZonedDateTime entryTimestamp = + ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP), timeFormatter); + ZonedDateTime endTimestamp = + ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP), timeFormatter); + + MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME, + Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp))); + } catch (Exception e) { + logger.warn("Unable to calculate elapsed time due to error: {}", e.getMessage()); + } } public void setElapsedTimeInvokeTimestamp() { - DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME; - ZonedDateTime entryTimestamp = - ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP), timeFormatter); - ZonedDateTime endTimestamp = ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP), timeFormatter); - - MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME, - Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp))); + try { + DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME; + ZonedDateTime entryTimestamp = + ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP), timeFormatter); + ZonedDateTime endTimestamp = + ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP), timeFormatter); + + MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME, + Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp))); + } catch (Exception e) { + logger.warn("Unable to calculate elapsed time due to error: {}", e.getMessage()); + } } public void setResponseStatusCode(int code) { |