Remove the demo from logging-library
[platform-oam.git] / logging-library / src / main / java / org / acumos / logging / library / util / ACUMOSLogConstants.java
1 /*
2   ===============LICENSE_START=======================================================
3   Acumos
4   ===================================================================================
5   Copyright (C) 2019 AT&T Intellectual Property & Tech Mahindra. All rights reserved.
6   ===================================================================================
7   This Acumos software file is distributed by AT&T and Tech Mahindra
8   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   This file 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=========================================================
19   */
20 package org.acumos.logging.library.util;
21
22 import org.slf4j.Marker;
23 import org.slf4j.MarkerFactory;
24
25 import java.util.Properties;
26
27 import org.slf4j.MDC;
28
29 /**
30  * Constants for standard ACUMOS headers, MDCs, etc.
31  *
32  */
33 public class ACUMOSLogConstants {
34
35         /**
36          * Hide and forbid construction.
37          */
38
39         private ACUMOSLogConstants() {
40
41                 throw new UnsupportedOperationException();
42         }
43
44         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
45         //
46         // Inner classes.
47         //
48         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
49
50         /**
51          * Marker constants.
52          */
53         public static class Markers {
54
55                 /** Marker reporting invocation. */
56                 public static Marker INVOKE = MarkerFactory.getMarker(LoggingConstant.INVOKE);
57
58                 /** Marker reporting invocation. */
59                 public static Marker INVOKE_RETURN = MarkerFactory.getMarker(LoggingConstant.INVOKE_RETURN);
60
61                 /** Marker reporting synchronous invocation. */
62                 public static Marker INVOKE_SYNCHRONOUS = build(LoggingConstant.INVOKE, LoggingConstant.SYNCHRONOUS);
63
64                 /** Marker reporting asynchronous invocation. */
65                 public static Marker INVOKE_ASYNCHRONOUS = build(LoggingConstant.INVOKE, LoggingConstant.ASYNCHRONOUS);
66
67                 /** Marker reporting entry into a component. */
68                 public static Marker ENTRY = MarkerFactory.getMarker(LoggingConstant.ENTRY);
69
70                 /** Marker reporting exit from a component. */
71                 public static Marker EXIT = MarkerFactory.getMarker(LoggingConstant.EXIT);
72
73                 public static Marker getINVOKE() {
74                         return INVOKE;
75                 }
76
77                 public static void setINVOKE(Marker iNVOKE) {
78                         INVOKE = iNVOKE;
79                 }
80
81                 public static Marker getINVOKE_RETURN() {
82                         return INVOKE_RETURN;
83                 }
84
85                 public static void setINVOKE_RETURN(Marker iNVOKE_RETURN) {
86                         INVOKE_RETURN = iNVOKE_RETURN;
87                 }
88
89                 public static Marker getINVOKE_SYNCHRONOUS() {
90                         return INVOKE_SYNCHRONOUS;
91                 }
92
93                 public static void setINVOKE_SYNCHRONOUS(Marker iNVOKE_SYNCHRONOUS) {
94                         INVOKE_SYNCHRONOUS = iNVOKE_SYNCHRONOUS;
95                 }
96
97                 public static Marker getINVOKE_ASYNCHRONOUS() {
98                         return INVOKE_ASYNCHRONOUS;
99                 }
100
101                 public static void setINVOKE_ASYNCHRONOUS(Marker iNVOKE_ASYNCHRONOUS) {
102                         INVOKE_ASYNCHRONOUS = iNVOKE_ASYNCHRONOUS;
103                 }
104
105                 public static Marker getENTRY() {
106                         return ENTRY;
107                 }
108
109                 public static void setENTRY(Marker eNTRY) {
110                         ENTRY = eNTRY;
111                 }
112
113                 public static Marker getEXIT() {
114                         return EXIT;
115                 }
116
117                 public static void setEXIT(Marker eXIT) {
118                         EXIT = eXIT;
119                 }
120
121                 /**
122                  * Build nested, detached marker.
123                  * 
124                  * @param m1
125                  *            top token.
126                  * @param m2
127                  *            sub-token.
128                  * @return detached Marker.
129                  */
130                 private static Marker build(String m1, String m2) {
131                         Marker marker = MarkerFactory.getDetachedMarker(m1);
132                         marker.add(MarkerFactory.getDetachedMarker(m2));
133                         return marker;
134                 }
135
136                 /**
137                  * Hide and forbid construction.
138                  */
139                 private Markers() {
140                         throw new UnsupportedOperationException();
141                 }
142         }
143
144         /**
145          * MDC name constants.
146          */
147         public static class MDCs {
148
149                 public enum ResponseStatusMDC {
150
151                         MDC_COMPLETED, MDC_ERROR, MDC_INPROGRESS;
152
153                         /** Enum value. */
154
155                 }
156
157                 public enum ResponseSeverityMDC {
158
159                         
160                         /** Enum value. */
161
162                         MDC_INFO, MDC_ERROR, MDC_TRACE, MDC_DEBUG, MDC_WARN, MDC_FATAL;
163
164                         /** Enum value. */
165
166                 }
167
168                 // Tracing. ////////////////////////////////////////////////////////////
169
170                 /** MDC correlating messages for a logical transaction. */
171                 public static String REQUEST_ID = LoggingConstant.REQUEST_ID;
172
173                 /** MDC recording target service. */
174                 public static String TARGET_SERVICE_NAME = LoggingConstant.TARGET_SERVICE_NAME;
175
176                 /** MDC recording target entity. */
177                 public static String TARGET_ENTITY = LoggingConstant.TARGET_ENTITY;
178
179                 // Network. ////////////////////////////////////////////////////////////
180
181                 /** MDC recording caller address. */
182                 public static String CLIENT_IP_ADDRESS = LoggingConstant.CLIENT_IP_ADDRESS;
183
184                 /** MDC recording server address. */
185                 public static String SERVER_FQDN = LoggingConstant.SERVER_FQDN;
186
187                 /** MDC reporting outcome code. */
188                 public static String RESPONSE_CODE = LoggingConstant.RESPONSE_CODE;
189
190                 /** MDC reporting outcome description. */
191                 public static String RESPONSE_DESCRIPTION = LoggingConstant.RESPONSE_DESCRIPTION;
192
193                 /** MDC reporting outcome error level. */
194                 public static String RESPONSE_SEVERITY = LoggingConstant.RESPONSE_SEVERITY;
195
196                 /** MDC reporting outcome status of the request. */
197                 public static String STATUS_CODE = LoggingConstant.STATUS_CODE;
198
199                 public static String USER = LoggingConstant.USER;
200
201                 public static String getUSER() {
202                         return USER;
203                 }
204
205                 public static void setUSER(String uSER) {
206                         USER = uSER;
207                 }
208
209                 public static String getREQUEST_ID() {
210                         return REQUEST_ID;
211                 }
212
213                 public static void setREQUEST_ID(String rEQUEST_ID) {
214                         REQUEST_ID = rEQUEST_ID;
215                 }
216
217                 public static String getTARGET_SERVICE_NAME() {
218                         return TARGET_SERVICE_NAME;
219                 }
220
221                 public static void setTARGET_SERVICE_NAME(String tARGET_SERVICE_NAME) {
222                         TARGET_SERVICE_NAME = tARGET_SERVICE_NAME;
223                 }
224
225                 public static String getTARGET_ENTITY() {
226                         return TARGET_ENTITY;
227                 }
228
229                 public static void setTARGET_ENTITY(String tARGET_ENTITY) {
230                         TARGET_ENTITY = tARGET_ENTITY;
231                 }
232
233                 public static String getCLIENT_IP_ADDRESS() {
234                         return CLIENT_IP_ADDRESS;
235                 }
236
237                 public static void setCLIENT_IP_ADDRESS(String cLIENT_IP_ADDRESS) {
238                         CLIENT_IP_ADDRESS = cLIENT_IP_ADDRESS;
239                 }
240
241                 public static String getSERVER_FQDN() {
242                         return SERVER_FQDN;
243                 }
244
245                 public static void setSERVER_FQDN(String sERVER_FQDN) {
246                         SERVER_FQDN = sERVER_FQDN;
247                 }
248
249                 public static String getRESPONSE_CODE() {
250                         return RESPONSE_CODE;
251                 }
252
253                 public static void setRESPONSE_CODE(String rESPONSE_CODE) {
254                         RESPONSE_CODE = rESPONSE_CODE;
255                 }
256
257                 public static String getRESPONSE_DESCRIPTION() {
258                         return RESPONSE_DESCRIPTION;
259                 }
260
261                 public static void setRESPONSE_DESCRIPTION(String rESPONSE_DESCRIPTION) {
262                         RESPONSE_DESCRIPTION = rESPONSE_DESCRIPTION;
263                 }
264
265                 public static String getRESPONSE_SEVERITY() {
266                         return RESPONSE_SEVERITY;
267                 }
268
269                 public static void setRESPONSE_SEVERITY(String rESPONSE_SEVERITY) {
270                         RESPONSE_SEVERITY = rESPONSE_SEVERITY;
271                 }
272
273                 public static String getSTATUS_CODE() {
274                         return STATUS_CODE;
275                 }
276
277                 public static void setSTATUS_CODE(String sTATUS_CODE) {
278                         STATUS_CODE = sTATUS_CODE;
279                 }
280
281                 // Unsorted. ///////////////////////////////////////////////////////////
282
283                 /**
284                  * Hide and forbid construction.
285                  */
286                 private MDCs() {
287                         throw new UnsupportedOperationException();
288                 }
289         }
290
291         /**
292          * Header name constants.
293          */
294         public static class Headers {
295
296                 /** HTTP X-ACUMOS-RequestID header. */
297                 public static String REQUEST_ID = "X-ACUMOS-RequestID";
298
299                 /**
300                  * Hide and forbid construction.
301                  */
302                 private Headers() {
303                         throw new UnsupportedOperationException();
304                 }
305         }
306
307         /**
308          * Overrideable method to set MDCs based on property values.
309          */
310         public static void setDefaultMDCs() {
311                 MDC.put(MDCs.RESPONSE_SEVERITY, ResponseSeverity.INFO.toString());
312                 MDC.put(MDCs.STATUS_CODE, ResponseStatus.INPROGRESS.toString());
313         }
314
315         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
316         //
317         // Enums.
318         //
319         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
320
321         /**
322          * Response success or not, for setting StatusCode.
323          */
324         public enum ResponseStatus {
325
326                 COMPLETED, ERROR, INPROGRESS
327         }
328
329         /**
330          * Response of log level, for setting Severity.
331          */
332         public enum ResponseSeverity {
333
334                 INFO, ERROR, TRACE, DEBUG, WARN, FATAL
335         }
336
337         /**
338          * Synchronous or asynchronous execution, for setting invocation marker.
339          */
340         public enum InvocationMode {
341
342                 /** Synchronous, blocking. */
343                 SYNCHRONOUS(LoggingConstant.SYNCHRONOUS, Markers.INVOKE_SYNCHRONOUS),
344
345                 /** Asynchronous, non-blocking. */
346                 ASYNCHRONOUS(LoggingConstant.ASYNCHRONOUS, Markers.INVOKE_ASYNCHRONOUS);
347
348                 /** Enum value. */
349                 private String mString;
350
351                 /** Corresponding marker. */
352                 private Marker mMarker;
353
354                 public String getmString() {
355                         return mString;
356                 }
357
358                 public void setmString(String mString) {
359                         this.mString = mString;
360                 }
361
362                 public Marker getmMarker() {
363                         return this.mMarker;
364                 }
365
366                 public void setmMarker(Marker mMarker) {
367                         this.mMarker = mMarker;
368                 }
369
370                 /**
371                  * Construct enum.
372                  *
373                  * @param s
374                  *            enum value.
375                  * @param m
376                  *            corresponding Marker.
377                  */
378                 InvocationMode(String s, Marker m) {
379                         this.mString = s;
380                         this.mMarker = m;
381                 }
382
383                 /**
384                  * Get Marker for enum.
385                  *
386                  * @return Marker.
387                  */
388
389                 @Override
390                 public String toString() {
391                         return this.mString;
392                 }
393         }
394
395 }