5357f4079e1adf3781fc5e866cac3969b67c560c
[logging-analytics.git] / reference / logging-slf4j / src / main / java / org / onap / logging / ref / slf4j / ONAPLogConstants.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.logging
4  * ================================================================================
5  * Copyright © 2018 Amdocs
6  * All rights 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 package org.onap.logging.ref.slf4j;
23
24 import org.slf4j.Marker;
25 import org.slf4j.MarkerFactory;
26
27 /**
28  * Constants for standard ONAP headers, MDCs, etc.
29  *
30  * <p>See <tt>package-info.java</tt>.</p>
31  */
32 public final class ONAPLogConstants {
33
34     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
35     //
36     // Constructors.
37     //
38     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
39
40     /**
41      * Hide and forbid construction.
42      */
43     private ONAPLogConstants() {
44         throw new UnsupportedOperationException();
45     }
46
47     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
48     //
49     // Inner classes.
50     //
51     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
52
53     /**
54      * Marker constants.
55      */
56     public static final class Markers {
57
58         /** Marker reporting invocation. */
59         public static final Marker INVOKE = MarkerFactory.getMarker("INVOKE");
60         
61         /** Marker reporting invocation return. */
62         public static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE_RETURN");
63
64         /** Marker reporting synchronous invocation. */
65         public static final Marker INVOKE_SYNCHRONOUS = build("INVOKE", "SYNCHRONOUS");
66
67         /** Marker reporting asynchronous invocation. */
68         public static final Marker INVOKE_ASYNCHRONOUS = build("INVOKE", "ASYNCHRONOUS");
69
70         /** Marker reporting entry into a component. */
71         public static final Marker ENTRY = MarkerFactory.getMarker("ENTRY");
72
73         /** Marker reporting exit from a component. */
74         public static final Marker EXIT = MarkerFactory.getMarker("EXIT");
75
76         /**
77          * Build nested, detached marker.
78          * @param m1 top token.
79          * @param m2 sub-token.
80          * @return detached Marker.
81          */
82         private static Marker build(final String m1, final String m2) {
83             final Marker marker = MarkerFactory.getDetachedMarker(m1);
84             marker.add(MarkerFactory.getDetachedMarker(m2));
85             return marker;
86         }
87
88         /**
89          * Hide and forbid construction.
90          */
91         private Markers() {
92             throw new UnsupportedOperationException();
93         }
94     }
95
96     /**
97      * MDC name constants.
98      */
99     public static final class MDCs {
100
101         // Tracing. ////////////////////////////////////////////////////////////
102
103         /** MDC correlating messages for an invocation. */
104         public static final String INVOCATION_ID = "InvocationID";
105
106         /** MDC correlating messages for a logical transaction. */
107         public static final String REQUEST_ID = "RequestID";
108
109         /** MDC recording calling partner name. */
110         public static final String PARTNER_NAME = "PartnerName";
111
112         /** MDC recording current service. */
113         public static final String SERVICE_NAME = "ServiceName";
114
115         /** MDC recording target service. */
116         public static final String TARGET_SERVICE_NAME = "TargetServiceName";
117         
118         /** MDC recording target entity. */
119         public static final String TARGET_ENTITY = "TargetEntity";
120
121         /** MDC recording target element. */
122         public static final String TARGET_ELEMENT = "TargetElement";
123
124         /** MDC recording current service instance id. */
125         public static final String SERVICE_INSTANCE_ID = "ServiceInstanceID";
126
127         /** MDC recording current  instance id. */
128         public static final String INSTANCE_UUID = "InstanceID";
129
130         // Network. ////////////////////////////////////////////////////////////
131
132         /** MDC recording caller address. */
133         public static final String CLIENT_IP_ADDRESS = "ClientIPAddress";
134
135         /** MDC recording server IP address. */
136         public static final String SERVER_IP_ADDRESS = "ServerIPAddress";
137
138         /** MDC recording server FQDN. */
139         public static final String SERVER_FQDN = "ServerFQDN";
140
141         /** MDC recording virtual server name. */
142         public static final String VIRTUAL_SERVER_NAME = "VirtualServerName";
143
144         /** MDC recording context name. */
145         public static final String CONTEXT_NAME = "ContextName";
146
147         /**
148          * MDC recording timestamp at the start of the current request,
149          * with the same scope as {@link #REQUEST_ID}.
150          *
151          * <p>Open issues:
152          * <ul>
153          *     <ul>Easily confused with {@link #INVOKE_TIMESTAMP}.</ul>
154          *     <ul>No mechanism for propagation between components, e.g. via HTTP headers.</ul>
155          *     <ul>Whatever mechanism we define, it's going to be costly.</ul>
156          * </ul>
157          * </p>
158          * */
159         public static final String ENTRY_TIMESTAMP = "EntryTimestamp";
160
161         /** MDC recording timestamp at the start of the current invocation. */
162         public static final String INVOKE_TIMESTAMP = "InvokeTimestamp";
163
164         /** MDC recording elapsed time. */
165         public static final String ELAPSED_TIME = "ElapsedTime";
166
167         /** MDC recording log timestamp. */     
168         public static final String LOG_TIMESTAMP = "LogTimestamp";
169
170         // Outcomes. ///////////////////////////////////////////////////////////
171
172         /** MDC reporting outcome code. */
173         public static final String RESPONSE_CODE = "ResponseCode";
174
175         /** MDC reporting outcome description. */
176         public static final String RESPONSE_DESCRIPTION = "ResponseDesc";
177
178         /** MDC reporting severity */
179         public static final String RESPONSE_SEVERITY = "Severity";
180
181         /** MDC reporting response status code */
182         public static final String RESPONSE_STATUS_CODE = "StatusCode";
183
184         /** MDC recording error code. */
185         public static final String ERROR_CODE = "ErrorCode";       
186         
187         /** MDC recording error description. */
188         public static final String ERROR_DESC = "ErrorDesc";
189
190         // Unsorted. ///////////////////////////////////////////////////////////
191
192         /**
193          * Hide and forbid construction.
194          */
195         private MDCs() {
196             throw new UnsupportedOperationException();
197         }
198     }
199
200     /**
201      * Header name constants.
202      */
203     public static final class Headers {
204
205         /** HTTP <tt>X-ONAP-RequestID</tt> header. */
206         public static final String REQUEST_ID = "X-ONAP-RequestID";
207
208         /** HTTP <tt>X-InvocationID</tt> header. */
209         public static final String INVOCATION_ID = "X-InvocationID";
210
211         /** HTTP <tt>X-ONAP-PartnerName</tt> header. */
212         public static final String PARTNER_NAME = "X-ONAP-PartnerName";
213
214         /**
215          * Hide and forbid construction.
216          */
217         private Headers() {
218             throw new UnsupportedOperationException();
219         }
220     }
221
222     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
223     //
224     // Enums.
225     //
226     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
227
228     /**
229      * Response success or not, for setting <tt>StatusCode</tt>.
230      */
231     public enum ResponseStatus {
232
233         /** Success. */
234         COMPLETE,
235
236         /** Not. */
237         ERROR,
238         
239         /** In Progress. */
240         INPROGRESS
241     }
242
243     /**
244      * Synchronous or asynchronous execution, for setting invocation marker.
245      */
246     public enum InvocationMode {
247
248         /** Synchronous, blocking. */
249         SYNCHRONOUS("SYNCHRONOUS", Markers.INVOKE_SYNCHRONOUS),
250
251         /** Asynchronous, non-blocking. */
252         ASYNCHRONOUS("ASYNCHRONOUS", Markers.INVOKE_ASYNCHRONOUS);
253
254         /** Enum value. */
255         private String mString;
256
257         /** Corresponding marker. */
258         private Marker mMarker;
259
260         /**
261          * Construct enum.
262          *
263          * @param s enum value.
264          * @param m corresponding Marker.
265          */
266         InvocationMode(final String s, final Marker m) {
267             this.mString = s;
268             this.mMarker = m;
269         }
270
271         /**
272          * Get Marker for enum.
273          *
274          * @return Marker.
275          */
276         public Marker getMarker() {
277             return this.mMarker;
278         }
279
280         /**
281          * {@inheritDoc}
282          */
283         @Override
284         public String toString() {
285             return this.mString;
286         }
287     }
288
289 }