Fix audit, metric and error logs as per logging specification
[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 javax.servlet.http.HttpServletRequest;
27 import org.apache.camel.Exchange;
28 import org.onap.clamp.clds.util.LoggingUtils;
29 import org.onap.clamp.clds.util.OnapLogConstants;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.slf4j.event.Level;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.http.HttpStatus;
35 import org.springframework.stereotype.Component;
36
37 /**
38  * The Flow log operations.
39  */
40 @Component
41 public class FlowLogOperation {
42
43     protected static final Logger logger = LoggerFactory.getLogger(FlowLogOperation.class);
44     private LoggingUtils util = new LoggingUtils(logger);
45
46     @Autowired
47     private HttpServletRequest request;
48
49     /**
50      * Generate the entry log.
51      *
52      * @param serviceDesc
53      *        The service description the loop name
54      */
55     public void startLog(Exchange exchange, String serviceDesc) {
56         util.entering(request, serviceDesc);
57         exchange.setProperty(OnapLogConstants.Headers.REQUEST_ID,
58             util.getProperties(OnapLogConstants.Mdcs.REQUEST_ID));
59         exchange.setProperty(OnapLogConstants.Headers.INVOCATION_ID,
60             util.getProperties(OnapLogConstants.Mdcs.INVOCATION_ID));
61         exchange.setProperty(OnapLogConstants.Headers.PARTNER_NAME,
62             util.getProperties(OnapLogConstants.Mdcs.PARTNER_NAME));
63     }
64
65     /**
66      * Generate the exiting log.
67      */
68     public void endLog() {
69         util.exiting(HttpStatus.OK.value(), "Successful", Level.INFO,
70             OnapLogConstants.ResponseStatus.COMPLETE);
71     }
72
73     /**
74      * Generate the error exiting log.
75      */
76     public void errorLog() {
77         util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Failed", Level.INFO,
78             OnapLogConstants.ResponseStatus.ERROR);
79     }
80
81     /**
82      * Generate the error exiting log.
83      */
84     public void httpErrorLog() {
85
86     }
87
88     /**
89      * Generate the invoke log.
90      */
91     public void invokeLog(String targetEntity, String targetServiceName) {
92         util.invoke(targetEntity, targetServiceName);
93     }
94
95     /**
96      * Generate the invoke return marker.
97      */
98     public void invokeReturnLog() {
99         util.invokeReturn();
100     }
101 }