Fix logging issues
[clamp.git] / src / main / java / org / onap / clamp / flow / log / FlowLogOperation.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights
6  *                             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  */
23
24 package org.onap.clamp.flow.log;
25
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28
29 import javax.servlet.http.HttpServletRequest;
30
31 import org.apache.camel.Exchange;
32 import org.onap.clamp.clds.util.LoggingUtils;
33 import org.onap.clamp.clds.util.ONAPLogConstants;
34 import org.slf4j.event.Level;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.http.HttpStatus;
37 import org.springframework.stereotype.Component;
38
39 /**
40  * The Flow log operations.
41  */
42 @Component
43 public class FlowLogOperation {
44
45     protected static final EELFLogger logger = EELFManager.getInstance().getLogger(FlowLogOperation.class);
46     protected static final EELFLogger auditLogger = EELFManager.getInstance().getMetricsLogger();
47     private LoggingUtils util = new LoggingUtils(logger);
48
49     @Autowired
50     private HttpServletRequest request;
51
52     /**
53      * Generate the entry log.
54      *
55      * @param serviceDesc The service description
56      *        the loop name
57      */
58     public void startLog(Exchange exchange, String serviceDesc) {
59         util.entering(request, serviceDesc);
60         exchange.getIn().setHeader(ONAPLogConstants.Headers.REQUEST_ID, 
61             util.getProperties(ONAPLogConstants.MDCs.REQUEST_ID));
62         exchange.getIn().setHeader(ONAPLogConstants.Headers.INVOCATION_ID, 
63             util.getProperties(ONAPLogConstants.MDCs.INVOCATION_ID));
64         exchange.getIn().setHeader(ONAPLogConstants.Headers.PARTNER_NAME, 
65             util.getProperties(ONAPLogConstants.MDCs.PARTNER_NAME));
66     }
67
68     /**
69      * Generate the exiting log.
70      */
71     public void endLog() {
72         util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, 
73             ONAPLogConstants.ResponseStatus.COMPLETED);
74     }
75
76     /**
77      * Generate the error exiting log.
78      */
79     public void errorLog() {
80         util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "Failed",
81             Level.INFO, ONAPLogConstants.ResponseStatus.ERROR);
82     }
83     
84     /**
85      * Generate the error exiting log.
86      */
87     public void httpErrorLog() {
88
89     }
90
91     /**
92      * Generate the invoke log.
93      */
94     public void invokeLog(String targetEntity, String targetServiceName) {
95         util.invoke(targetEntity, targetServiceName);
96     }
97
98     /**
99      * Generate the invoke return marker.
100      */
101     public void invokeReturnLog() {
102         util.invokeReturn();
103     }
104 }