Reduce the number of problems in aai-common by removing unused imports
[aai/aai-common.git] / aai-els-onap-logging / src / main / java / org / onap / aai / aailog / logs / AaiScheduledTaskAuditLog.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.logging
4  * ================================================================================
5  * Copyright © 2018 Amdocs
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *    http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.aai.aailog.logs;
23
24 import java.util.UUID;
25
26 import javax.ws.rs.core.Response;
27
28 import org.onap.logging.filter.base.MDCSetup;
29 import org.onap.logging.ref.slf4j.ONAPLogConstants;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.slf4j.MDC;
33 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
34 import org.springframework.context.annotation.Scope;
35 import org.springframework.stereotype.Component;
36
37 @Component
38 @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
39 public class AaiScheduledTaskAuditLog extends MDCSetup {
40     protected static Logger logger = LoggerFactory.getLogger(AaiScheduledTaskAuditLog.class);
41
42     public void logBefore(String serviceName, String partnerName) {
43         try {
44             String requestId = UUID.randomUUID().toString();
45             MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId);
46             setInvocationIdFromMDC();
47             MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, serviceName);
48             MDC.put(ONAPLogConstants.MDCs.PARTNER_NAME, partnerName);
49             setServerFQDN();
50             setClientIPAddress(null);
51             setInstanceID();
52             setEntryTimeStamp();
53             MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.INPROGRESS.toString());
54             setLogTimestamp();
55             setElapsedTime();
56             logger.info(ONAPLogConstants.Markers.ENTRY, "Entering");
57         } catch (Exception e) {
58             logger.warn("Error in AaiScheduledTaskAuditLog logBefore", e.getMessage());
59         }
60
61     }
62
63     public void logAfter() {
64         try {
65             // TODO: how do we know if there was an error
66             setResponseStatusCode(Response.Status.OK.getStatusCode());
67             setLogTimestamp();
68             setElapsedTime();
69             logger.info(ONAPLogConstants.Markers.EXIT, "Exiting.");
70         } catch (Exception e) {
71             logger.warn("Error in AaiScheduledTaskAuditLog logAfter", e.getMessage());
72         } finally {
73             MDC.clear();
74         }
75     }
76 }