Removed response code and description from default
[platform-oam.git] / logging-demo / src / main / java / org / acumos / demo / logging / 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.demo.logging.util;
21
22 import org.slf4j.Marker;
23 import org.slf4j.MarkerFactory;
24 import org.slf4j.MDC;
25
26
27 /**
28  * Constants for standard ACUMOS headers, MDCs, etc.
29  *
30  */
31 public final class ACUMOSLogConstants {
32
33         /**
34          * Hide and forbid construction.
35          */
36         private ACUMOSLogConstants() {
37                 throw new UnsupportedOperationException();
38         }
39
40         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
41         //
42         // Inner classes.
43         //
44         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
45
46         /**
47          * Marker constants.
48          */
49         public static final class Markers {
50
51                 /** Marker reporting invocation. */
52                 public static final Marker INVOKE = MarkerFactory.getMarker("INVOKE");
53
54                 /** Marker reporting invocation. */
55                 public static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE_RETURN");
56
57                 /** Marker reporting synchronous invocation. */
58                 public static final Marker INVOKE_SYNCHRONOUS = build("INVOKE", "SYNCHRONOUS");
59
60                 /** Marker reporting asynchronous invocation. */
61                 public static final Marker INVOKE_ASYNCHRONOUS = build("INVOKE", "ASYNCHRONOUS");
62
63                 /** Marker reporting entry into a component. */
64                 public static final Marker ENTRY = MarkerFactory.getMarker("ENTRY");
65
66                 /** Marker reporting exit from a component. */
67                 public static final Marker EXIT = MarkerFactory.getMarker("EXIT");
68
69                 /**
70                  * Build nested, detached marker.
71                  * 
72                  * @param m1
73                  *            top token.
74                  * @param m2
75                  *            sub-token.
76                  * @return detached Marker.
77                  */
78                 private static Marker build(final String m1, final String m2) {
79                         final Marker marker = MarkerFactory.getDetachedMarker(m1);
80                         marker.add(MarkerFactory.getDetachedMarker(m2));
81                         return marker;
82                 }
83
84                 /**
85                  * Hide and forbid construction.
86                  */
87                 private Markers() {
88                         throw new UnsupportedOperationException();
89                 }
90         }
91
92         /**
93          * MDC name constants.
94          */
95         public static final class MDCs {
96
97                 // Tracing. ////////////////////////////////////////////////////////////
98
99                 /** MDC correlating messages for a logical transaction. */
100                 public static final String REQUEST_ID = "RequestID";
101
102                 /** MDC recording target service. */
103                 public static final String TARGET_SERVICE_NAME = "TargetServiceName";
104
105                 /** MDC recording target entity. */
106                 public static final String TARGET_ENTITY = "TargetEntity";
107
108                 // Network. ////////////////////////////////////////////////////////////
109
110                 /** MDC recording caller address. */
111                 public static final String CLIENT_IP_ADDRESS = "ClientIPAddress";
112
113                 /** MDC recording server address. */
114                 public static final String SERVER_FQDN = "ServerFQDN";
115
116                 /** MDC reporting outcome code. */
117                 public static final String RESPONSE_CODE = "ResponseCode";
118
119                 /** MDC reporting outcome description. */
120                 public static final String RESPONSE_DESCRIPTION = "ResponseDescription";
121
122                 /** MDC reporting outcome error level. */
123                 public static final String RESPONSE_SEVERITY = "Severity";
124
125                 /** MDC reporting outcome status of the request. */
126                 public static final String STATUS_CODE = "StatusCode";
127
128                 // Unsorted. ///////////////////////////////////////////////////////////
129
130                 /**
131                  * Hide and forbid construction.
132                  */
133                 private MDCs() {
134                         throw new UnsupportedOperationException();
135                 }
136         }
137
138         /**
139          * Header name constants.
140          */
141         public static final class Headers {
142
143                 /** HTTP X-ACUMOS-RequestID header. */
144                 public static final String REQUEST_ID = "X-ACUMOS-RequestID";
145
146                 /**
147                  * Hide and forbid construction.
148                  */
149                 private Headers() {
150                         throw new UnsupportedOperationException();
151                 }
152         }
153
154         /**
155          * Overrideable method to set MDCs based on property values.
156          */
157         public static void setDefaultMDCs() {
158                 MDC.put(MDCs.RESPONSE_SEVERITY, ResponseSeverity.INFO.toString());
159                 MDC.put(MDCs.STATUS_CODE, ResponseStatus.INPROGRESS.toString());
160         }
161
162         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
163         //
164         // Enums.
165         //
166         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
167
168         /**
169          * Response success or not, for setting StatusCode.
170          */
171         public enum ResponseStatus {
172                 
173                 COMPLETED,
174                 ERROR,
175                 INPROGRESS
176         }
177
178         /**
179          * Response of log level, for setting Severity.
180          */
181         public enum ResponseSeverity {
182
183                 INFO,
184                 ERROR,
185                 TRACE,
186                 DEBUG,
187                 WARN,
188                 FATAL
189         }
190
191         /**
192          * Synchronous or asynchronous execution, for setting invocation marker.
193          */
194         public enum InvocationMode {
195
196                 /** Synchronous, blocking. */
197                 SYNCHRONOUS("SYNCHRONOUS", Markers.INVOKE_SYNCHRONOUS),
198
199                 /** Asynchronous, non-blocking. */
200                 ASYNCHRONOUS("ASYNCHRONOUS", Markers.INVOKE_ASYNCHRONOUS);
201
202                 /** Enum value. */
203                 private String mString;
204
205                 /** Corresponding marker. */
206                 private Marker mMarker;
207
208                 /**
209                  * Construct enum.
210                  *
211                  * @param s
212                  *            enum value.
213                  * @param m
214                  *            corresponding Marker.
215                  */
216                 InvocationMode(final String s, final Marker m) {
217                         this.mString = s;
218                         this.mMarker = m;
219                 }
220
221                 /**
222                  * Get Marker for enum.
223                  *
224                  * @return Marker.
225                  */
226                 public Marker getMarker() {
227                         return this.mMarker;
228                 }
229
230                 @Override
231                 public String toString() {
232                         return this.mString;
233                 }
234         }
235
236 }