2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.common.log.elements;
24 import org.openecomp.sdc.common.log.api.ILogConfiguration;
25 import org.openecomp.sdc.common.log.api.ILogFieldsHandler;
26 import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
27 import org.openecomp.sdc.common.log.enums.LogMarkers;
28 import org.openecomp.sdc.common.log.enums.Severity;
29 import org.openecomp.sdc.common.log.enums.StatusCode;
30 import org.slf4j.Logger;
32 import org.slf4j.MarkerFactory;
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.Collections;
37 import java.util.List;
39 public class LoggerAudit extends LoggerBase {
40 private static ArrayList<String> mandatoryFields = new ArrayList<>(Arrays.asList(
41 ILogConfiguration.MDC_AUDIT_BEGIN_TIMESTAMP,
42 ILogConfiguration.MDC_END_TIMESTAMP,
43 ILogConfiguration.MDC_KEY_REQUEST_ID,
44 ILogConfiguration.MDC_SERVICE_NAME,
45 ILogConfiguration.MDC_PARTNER_NAME,
46 ILogConfiguration.MDC_STATUS_CODE,
47 ILogConfiguration.MDC_RESPONSE_CODE,
48 ILogConfiguration.MDC_SERVICE_INSTANCE_ID,
49 ILogConfiguration.MDC_RESPONSE_DESC,
50 ILogConfiguration.MDC_ELAPSED_TIME,
51 ILogConfiguration.MDC_SERVER_IP_ADDRESS,
52 ILogConfiguration.MDC_SERVER_FQDN));
54 private static ArrayList<String> optionalFields = new ArrayList<>(Arrays.asList(
55 ILogConfiguration.MDC_INSTANCE_UUID,
56 ILogConfiguration.MDC_ALERT_SEVERITY,
57 ILogConfiguration.MDC_REMOTE_HOST,
58 ILogConfiguration.MDC_CLASS_NAME,
59 ILogConfiguration.MDC_PROCESS_KEY,
60 ILogConfiguration.MDC_OPT_FIELD1,
61 ILogConfiguration.MDC_OPT_FIELD2,
62 ILogConfiguration.MDC_OPT_FIELD3,
63 ILogConfiguration.MDC_OPT_FIELD4));
65 LoggerAudit(ILogFieldsHandler ecompMdcWrapper, Logger logger) {
66 super (ecompMdcWrapper, MarkerFactory.getMarker(LogMarkers.AUDIT_MARKER.text()), logger);
67 //put the remote host and FQDN values from another thread if they are set
68 ecompMdcWrapper.setServerIPAddressInternally();
69 ecompMdcWrapper.setServerFQDNInternally();
73 public LoggerAudit startTimer() {
74 ecompLogFieldsHandler.startAuditTimer();
78 public LoggerAudit stopTimer() {
79 ecompLogFieldsHandler.stopAuditTimer();
83 public LoggerAudit setInstanceUUID(String instanceUUID) {
84 ecompLogFieldsHandler.setInstanceUUID(instanceUUID);
88 public LoggerAudit setOptClassName(String className) {
89 MDC.put("ClassName", className);
93 public LoggerAudit setOptProcessKey(String processKey) {
94 ecompLogFieldsHandler.setProcessKey(processKey);
98 public LoggerAudit setOptAlertSeverity(Severity alertSeverity) {
99 ecompLogFieldsHandler.setAlertSeverity(alertSeverity);
103 // log optional parameter
104 public LoggerAudit setOptCustomField1(String customField1) {
105 ecompLogFieldsHandler.setOptCustomField1(customField1);
109 // log optional parameter
110 public LoggerAudit setOptCustomField2(String customField2) {
111 ecompLogFieldsHandler.setOptCustomField2(customField2);
115 // log optional parameter
116 public LoggerAudit setOptCustomField3(String customField3) {
117 ecompLogFieldsHandler.setOptCustomField3(customField3);
121 public LoggerAudit setOptCustomField4(String customField4) {
122 ecompLogFieldsHandler.setOptCustomField4(customField4);
127 public LoggerAudit setKeyRequestId(String keyRequestId) {
128 return (LoggerAudit) super.setKeyRequestId(keyRequestId);
131 public LoggerAudit setRemoteHost(String remoteHost) {
132 ecompLogFieldsHandler.setRemoteHost(remoteHost);
136 public LoggerAudit setServiceName(String serviceName) {
137 ecompLogFieldsHandler.setServiceName(serviceName);
141 public LoggerAudit setStatusCode(String statusCode) {
142 // status code is either success (COMPLETE) or failure (ERROR) of the request.
143 String respStatus = Integer.parseInt(statusCode) / 100 == 2 ? StatusCode.COMPLETE.getStatusCodeEnum() : StatusCode.ERROR.getStatusCodeEnum();
144 ecompLogFieldsHandler.setStatusCode(respStatus);
148 public LoggerAudit setPartnerName(String partnerName) {
149 ecompLogFieldsHandler.setPartnerName(partnerName);
153 public LoggerAudit setResponseCode(EcompLoggerErrorCode responseCode) {
154 ecompLogFieldsHandler.setResponseCode(responseCode.getErrorCode());
158 public LoggerAudit setResponseDesc(String responseDesc) {
159 ecompLogFieldsHandler.setResponseDesc(responseDesc);
163 public LoggerAudit setOptServiceInstanceId(String serviceInstanceId) {
164 ecompLogFieldsHandler.setServiceInstanceId(serviceInstanceId);
168 public String getAuditMessage() {
169 return ecompLogFieldsHandler.getAuditMessage();
174 public List<String> getMandatoryFields() {
175 return Collections.unmodifiableList(mandatoryFields);
179 public LoggerAudit clear() {
181 ecompLogFieldsHandler.setServerFQDNInternally();
182 ecompLogFieldsHandler.setServerIPAddressInternally();