diff options
author | vasraz <vasyl.razinkov@est.tech> | 2021-03-22 15:33:06 +0000 |
---|---|---|
committer | Christophe Closset <christophe.closset@intl.att.com> | 2021-03-24 06:59:47 +0000 |
commit | d378c37fbd1ecec7b43394926f1ca32a695e07de (patch) | |
tree | 5c8a085f8732f980d871d966ac49361644efa698 /openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapper.java | |
parent | a6ae7294ecd336d7e88f915710b08e2658eaee00 (diff) |
Reformat openecomp-be
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Issue-ID: SDC-3449
Change-Id: I13e02322f8e00820cc5a1d85752caaeda9bf10d1
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapper.java')
-rw-r--r-- | openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapper.java | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapper.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapper.java index 54026098c1..80ca807f2b 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapper.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapper.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.slf4j; import java.text.SimpleDateFormat; @@ -34,7 +33,6 @@ class SLF4JLoggerWrapper implements Logger { //The specified format presents time in UTC formatted per ISO 8601, as required by ONAP logging guidelines private static final String DATE_TIME_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"; - private final org.slf4j.Logger logger; // May cause http://www.slf4j.org/codes.html#loggerNameMismatch @@ -50,6 +48,16 @@ class SLF4JLoggerWrapper implements Logger { this(LoggerFactory.getLogger(className)); } + private static void unsafePutOnMdc(MDCField field, String value) { + MDC.put(field.asKey(), value); + } + + private static void safePutOnMdc(MDCField field, String value) { + if (value != null) { + unsafePutOnMdc(field, value); + } + } + @Override public String getName() { return logger.getName(); @@ -67,11 +75,9 @@ class SLF4JLoggerWrapper implements Logger { @Override public void metrics(MetricsData data) { - if (data == null) { return; // not going to fail because of null } - try { putMetricsOnMdc(data); logger.info(Markers.METRICS, ""); @@ -81,7 +87,6 @@ class SLF4JLoggerWrapper implements Logger { } private void putMetricsOnMdc(MetricsData metrics) { - SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_TIME_PATTERN); unsafePutOnMdc(MetricsField.BEGIN_TIMESTAMP, dateFormat.format(metrics.getStartTime())); unsafePutOnMdc(MetricsField.END_TIMESTAMP, dateFormat.format(metrics.getEndTime())); @@ -91,7 +96,6 @@ class SLF4JLoggerWrapper implements Logger { safePutOnMdc(MetricsField.CLIENT_IP_ADDRESS, metrics.getClientIpAddress()); safePutOnMdc(MetricsField.TARGET_ENTITY, metrics.getTargetEntity()); safePutOnMdc(MetricsField.TARGET_VIRTUAL_ENTITY, metrics.getTargetVirtualEntity()); - if (metrics.getStatusCode() != null) { unsafePutOnMdc(MetricsField.STATUS_CODE, metrics.getStatusCode().name()); } @@ -103,16 +107,6 @@ class SLF4JLoggerWrapper implements Logger { } } - private static void unsafePutOnMdc(MDCField field, String value) { - MDC.put(field.asKey(), value); - } - - private static void safePutOnMdc(MDCField field, String value) { - if (value != null) { - unsafePutOnMdc(field, value); - } - } - @Override public boolean isAuditEnabled() { return logger.isInfoEnabled(Markers.EXIT); @@ -120,11 +114,9 @@ class SLF4JLoggerWrapper implements Logger { @Override public void auditEntry(AuditData data) { - if (data == null) { return; // not failing if null } - try { putAuditOnMdc(data); logger.info(Markers.ENTRY, ""); @@ -133,14 +125,11 @@ class SLF4JLoggerWrapper implements Logger { } } - @Override public void auditExit(AuditData data) { - if (data == null) { return; // not failing if null } - try { putAuditOnMdc(data); logger.info(Markers.EXIT, ""); @@ -150,7 +139,6 @@ class SLF4JLoggerWrapper implements Logger { } private void putAuditOnMdc(AuditData audit) { - SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_TIME_PATTERN); unsafePutOnMdc(AuditField.BEGIN_TIMESTAMP, dateFormat.format(audit.getStartTime())); unsafePutOnMdc(AuditField.END_TIMESTAMP, dateFormat.format(audit.getEndTime())); @@ -159,7 +147,6 @@ class SLF4JLoggerWrapper implements Logger { safePutOnMdc(AuditField.RESPONSE_DESCRIPTION, audit.getResponseDescription()); safePutOnMdc(AuditField.CLIENT_IP_ADDRESS, audit.getClientIpAddress()); unsafePutOnMdc(AuditField.INVOCATION_ID, UUID.randomUUID().toString()); - if (audit.getStatusCode() != null) { unsafePutOnMdc(AuditField.STATUS_CODE, audit.getStatusCode().name()); } |