diff options
author | Arul.Nambi <arul.nambi@amdocs.com> | 2017-09-14 15:30:00 -0400 |
---|---|---|
committer | Arul.Nambi <arul.nambi@amdocs.com> | 2017-09-14 15:30:51 -0400 |
commit | 2d211f3e1943ded3a0ab59553b12bee602079398 (patch) | |
tree | cbc3fc4ba4a463b94d4532b8641199d8bcf9e79f /eelf-logging/src/main/java/org/onap/aai/cl/eelf/AuditLogLine.java | |
parent | c8ed19f31ae454dab4cd9ce59886a3578b24f58b (diff) |
Renaming openecomp to onap
Issue-ID: AAI-208
Change-Id: I11d428593971c665f0ebdf56465d87161ef7d112
Signed-off-by: Arul.Nambi <arul.nambi@amdocs.com>
Diffstat (limited to 'eelf-logging/src/main/java/org/onap/aai/cl/eelf/AuditLogLine.java')
-rw-r--r-- | eelf-logging/src/main/java/org/onap/aai/cl/eelf/AuditLogLine.java | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/eelf-logging/src/main/java/org/onap/aai/cl/eelf/AuditLogLine.java b/eelf-logging/src/main/java/org/onap/aai/cl/eelf/AuditLogLine.java new file mode 100644 index 0000000..1a5d23b --- /dev/null +++ b/eelf-logging/src/main/java/org/onap/aai/cl/eelf/AuditLogLine.java @@ -0,0 +1,83 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 Amdocs + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.aai.cl.eelf; + +import org.onap.aai.cl.api.LogLine; +import org.onap.aai.cl.mdc.MdcContext; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** This class is used to help standardize how log lines are written and provide + * profiling info. */ +public class AuditLogLine extends LogLine { + + /** (non-Javadoc) + * @see org.onap.aai.cl.api.LogLine#getFormattedLine() + */ + public String getFormattedLine() { + + // calculate start/end/elapsed times + Date currentDateTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); + String startTimeString = getMdcValue(MdcContext.MDC_START_TIME); + String endTimeString = formatter.format(currentDateTime); + long elapsedTime = 0; + Date startDateTime; + try { + startDateTime = formatter.parse(startTimeString); + elapsedTime = currentDateTime.getTime() - startDateTime.getTime(); + } catch (ParseException e) { + // Leave an elapsed time of 0 if the start time was not properly formatted + } + String elapsedTimeString = Long.toString(elapsedTime); + + return startTimeString + "|" + // 1 start time + endTimeString + "|" + // 2 end time + getMdcValue(MdcContext.MDC_REQUEST_ID) + "|" + // 3 transaction id + getMdcValue(MdcContext.MDC_SERVICE_INSTANCE_ID) + "|" + // 4 service instance + Thread.currentThread().getName() + "|" + // 5 thread id + getMdcValue(MdcContext.MDC_SERVER_FQDN) + "|" + // 6 physical/virtual server name + getMdcValue(MdcContext.MDC_SERVICE_NAME) + "|" + // 7 service name + getMdcValue(MdcContext.MDC_PARTNER_NAME) + "|" + // 8 partner name + fieldValue(DefinedFields.STATUS_CODE) + "|" + // 9 status code + fieldValue(DefinedFields.RESPONSE_CODE) + "|" + // 10 response code + fieldValue(DefinedFields.RESPONSE_DESCRIPTION) + "|" + // 11 response description + fieldValue(DefinedFields.INSTANCE_UUID) + "|" + // 12 instance UUID + level + "|" + // 13 log level + fieldValue(DefinedFields.SEVERITY) + "|" + // 14 log severity + fieldValue(DefinedFields.SERVER_IP) + "|" + // 15 server ip + elapsedTimeString + "|" + // 16 elapsed time + getMdcValue(MdcContext.MDC_SERVER_FQDN) + "|" + // 17 server name + getMdcValue(MdcContext.MDC_CLIENT_ADDRESS) + "|" + // 18 client ip address + fieldValue(DefinedFields.CLASS_NAME) + "|" + // 19 class name + "" + "|" + // 20 deprecated + fieldValue(DefinedFields.PROCESS_KEY) + "|" + // 21 process key + fieldValue(DefinedFields.CUSTOM_1) + "|" + // 22 custom 1 + fieldValue(DefinedFields.CUSTOM_2) + "|" + // 23 custom 2 + fieldValue(DefinedFields.CUSTOM_3) + "|" + // 24 custom 3 + fieldValue(DefinedFields.CUSTOM_4) + "|" + // 25 custom 4 + message; // 26 details + } +} |