Update logging Rest API
[platform-oam.git] / logging-rest-library / src / main / java / com / logging / rest / example / springbootswagger2 / controller / LoggingController.java
1 package com.logging.rest.example.springbootswagger2.controller;
2
3 import java.net.InetAddress;
4 import java.util.UUID;
5
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8
9 import org.slf4j.MDC;
10 import org.slf4j.Marker;
11 import org.slf4j.MarkerFactory;
12 import org.acumos.logging.library.util.ACUMOSLogConstants;
13 import org.acumos.logging.library.util.LogConfig;
14 import org.acumos.logging.library.util.LoggingConstant;
15 import org.acumos.logging.library.util.ACUMOSLogConstants.InvocationMode;
16 import org.acumos.logging.library.util.ACUMOSLogConstants.MDCs;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19 import org.springframework.http.MediaType;
20 import org.springframework.web.bind.annotation.PathVariable;
21 import org.springframework.web.bind.annotation.RequestMapping;
22 import org.springframework.web.bind.annotation.RequestMethod;
23 import org.springframework.web.bind.annotation.ResponseBody;
24 import org.springframework.web.bind.annotation.RestController;
25
26 import com.fasterxml.jackson.databind.ObjectMapper;
27
28 import io.swagger.annotations.Api;
29 import io.swagger.annotations.ApiOperation;
30
31 @Api(value = "Swagger2DemoRestController", description = "Looging Apis related to Logging jar!!!!")
32 @RestController
33 public class LoggingController {
34
35
36
37         private static final Logger logger = LoggerFactory.getLogger(LoggingController.class);
38         private ObjectMapper mapper = new ObjectMapper();
39                 
40         
41
42         @ApiOperation(value = "Get Logging publish GetInfo requests.")
43         @RequestMapping(value = { "getInfo" }, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
44         @ResponseBody
45         public String getInformation(HttpServletRequest request, HttpServletResponse response) throws Exception {
46                 
47                 LogConfig.setEnteringMDCs("first", "second","","","");
48                 //LogConfig.setEnteringMDCs("elk-client", APINames.DEBUG_TEST,"test",LoggingConstant.MDC_INPROGRESS,LoggingConstant.MDC_INFO);
49
50                 
51                 logger.info(InvocationMode.SYNCHRONOUS.getmMarker(), "platform-oam");
52                 logger.debug("Inside getInfo Service");
53                 logger.info(InvocationMode.ASYNCHRONOUS.getmMarker(), "platform-oam");
54                 logger.info("Inside getInfo Service");
55
56                 logger.info(InvocationMode.SYNCHRONOUS.getmMarker(), "platform-oam");
57                 logger.debug("Inside getDebug Service");
58                 logger.info(ACUMOSLogConstants.MDCs.getREQUEST_ID());
59                 ACUMOSLogConstants.Markers.getINVOKE();
60         
61         
62         
63                 logger.info(InvocationMode.SYNCHRONOUS.getmMarker(), "platform-oam");
64                 logger.info(ACUMOSLogConstants.ResponseStatus.COMPLETED.toString(), "platform-oam");
65                 ACUMOSLogConstants.ResponseStatus.COMPLETED.toString();
66                 
67                 logger.debug("Inside getInfo Service");
68                 logger.info(InvocationMode.ASYNCHRONOUS.getmMarker(), "platform-oam");
69                 logger.info(ACUMOSLogConstants.ResponseStatus.ERROR.toString(), "platform-oam");
70                 logger.info(ACUMOSLogConstants.ResponseStatus.INPROGRESS.toString(), "platform-oam");
71                 
72                 logger.info(ACUMOSLogConstants.ResponseSeverity.DEBUG.toString(), "platform-oam");
73                 logger.info(ACUMOSLogConstants.ResponseSeverity.ERROR.toString(), "platform-oam");
74                 logger.info(ACUMOSLogConstants.ResponseSeverity.FATAL.toString(), "platform-oam");
75                 logger.info(ACUMOSLogConstants.ResponseSeverity.INFO.toString(), "platform-oam");
76                 logger.info(ACUMOSLogConstants.ResponseSeverity.TRACE.toString(), "platform-oam");
77                 logger.info(ACUMOSLogConstants.MDCs.REQUEST_ID.toString(), "platform-oam");
78                 logger.info(ACUMOSLogConstants.MDCs.RESPONSE_DESCRIPTION.toString(), "platform-oam");
79         
80                 logger.info("Inside getInfo Service");
81                 LogConfig.getHostDetails();
82                 LogConfig.clearMDCDetails();
83                 logger.info("method call ended.");
84                 logger.debug("method call ended.");
85
86                 return "";
87         }
88         
89         @ApiOperation(value = "Get Logging publish debug requests.")
90         @RequestMapping(value = { APINames.DEBUG_TEST }, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
91         @ResponseBody
92         public String getDebug(@PathVariable String markerInput, @PathVariable("markerInput1") String markerInput1, @PathVariable("user") String user) throws Exception {
93                 
94                 
95                 LogConfig.setEnteringMDCs("elk-client", APINames.DEBUG_TEST,user,LoggingConstant.MDC_COMPLETED,LoggingConstant.MDC_INFO);
96         
97                 logger.info(InvocationMode.SYNCHRONOUS.getmMarker(), "platform-oam");
98                 MarkerFactory.getIMarkerFactory();
99                 logger.debug("Inside getDebug Service");
100                 String markerInputVal=markerInput;
101                 String markerInput1Val=markerInput1;
102                 
103                 logger.info(InvocationMode.SYNCHRONOUS.getmMarker(), "platform-oam");
104                 logger.info(InvocationMode.SYNCHRONOUS.getmMarker(), "platform-oam");
105                 
106                 logger.info(ACUMOSLogConstants.MDCs.ResponseSeverityMDC.MDC_DEBUG.toString());
107         
108                 logger.info(InvocationMode.SYNCHRONOUS.getmMarker(), "platform-oam");
109                 
110                 MarkerFactory.getMarker(markerInputVal);
111     
112         logger.error(MarkerFactory.getMarker(markerInputVal),
113                           "This is a serious an User Input Marker error requiring the admin's attention",
114                            new Exception("Just testing"));
115         
116                 logger.info(InvocationMode.ASYNCHRONOUS.getmMarker(), "platform-oam");
117                 logger.info("Inside getDebug Service");
118                 ACUMOSLogConstants.ResponseStatus.COMPLETED.toString();
119                 logger.info(ACUMOSLogConstants.ResponseSeverity.INFO.toString(), "platform-oam");
120                 logger.info("method call ended.");
121                 logger.debug("method call ended.");
122                 LogConfig.getHostDetails();
123                 LogConfig.clearMDCDetails();
124         
125
126                 return "";
127         }
128         
129         
130           @ApiOperation(value = "Gets MDC details.")
131             @RequestMapping(value = { APINames.GET_TEST }, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
132             @ResponseBody
133             public String getTest(@PathVariable("markerInput") String markerInput,@PathVariable("user") String user) {
134          
135                 try {
136                         LogConfig.setEnteringMDCs("test", "test",user,LoggingConstant.MDC_ERROR,LoggingConstant.MDC_TRACE);
137                         String markerInputVal=markerInput;
138                         String marker="ENTRY";
139              
140                         Marker marker1=ACUMOSLogConstants.Markers.INVOKE_RETURN;
141                         
142                         MarkerFactory.getMarker(marker);
143                         System.out.println(MarkerFactory.getMarker(marker));
144                         
145                         MarkerFactory.getMarker(markerInputVal);
146              
147                         
148                         logger.info(marker1,"This is a confidential message....");
149                         
150                         Marker notifyAdmin = MarkerFactory.getMarker("NOTIFY_ADMIN");
151                         logger.error(notifyAdmin,
152                           "This is a serious an NOTIFY_ADMIN error requiring the admin's NOTIFY_ADMIN attention",
153                            new Exception("Just testing"));
154                         
155                         //Marker notifyAdmin = MarkerFactory.getMarker("NOTIFY_ADMIN");
156                         logger.error(MarkerFactory.getMarker(markerInputVal),
157                           "This is a serious an User Input Marker error requiring the admin's attention",
158                            new Exception("Just testing"));
159                         
160                         logger.info(InvocationMode.SYNCHRONOUS.getmMarker(), "platform-oam");
161                         logger.debug("Inside getWarn Service");
162                         LogConfig.getHostDetails();
163                         LogConfig.clearMDCDetails();
164             
165                     }
166                  catch (Exception e) {            
167                    
168                 }
169                 return "";
170             }
171         
172         @ApiOperation(value = "Get Logging publish warn requests.")
173         @RequestMapping(value = { "/warn" }, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
174         @ResponseBody
175         public String getWarn() throws Exception {
176                 
177         //      LogConfig.setEnteringMDCs("first", "second","test",LoggingConstant.MDC_INPROGRESS,LoggingConstant.MDC_ERROR);
178                 LogConfig.setEnteringMDCs("first", "second","","","");
179                 logger.info(InvocationMode.SYNCHRONOUS.getmMarker(), "platform-oam");
180                 logger.debug("Inside getWarn Service");
181                 logger.info(InvocationMode.ASYNCHRONOUS.getmMarker(), "platform-oam");
182                 logger.info("Inside getWarn Service");
183                 String marker="ENTRY";
184         Marker marker1=ACUMOSLogConstants.Markers.INVOKE_RETURN;
185         logger.error(marker1,
186                   "This is a serious an error requiring the admin's attention",
187                    new Exception("Just testing"));
188         logger.info(marker1,"This is a confidential message....");
189         logger.debug(marker1,"This is a confidential message....");
190         
191         MarkerFactory.getMarker(marker);
192         
193         Marker notifyAdmin = MarkerFactory.getMarker("NOTIFY_ADMIN");
194         logger.error(notifyAdmin,
195           "This is a serious an error requiring the admin's attention",
196            new Exception("Just testing"));
197    
198                 logger.info("method call ended.");
199                 logger.warn("method call ended.");
200                 LogConfig.getHostDetails();
201                 LogConfig.clearMDCDetails();
202
203                 return "";
204         }
205         
206         
207         
208 }