SLF4J adapter (in 'common') + call graph demo
[logging-analytics.git] / reference / slf4j-reference / src / main / java / org / onap / logging / ref / slf4j / common / 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.common;
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 synchronous invocation. */
62         public static final Marker INVOKE_SYNCHRONOUS = build("INVOKE", "SYNCHRONOUS");
63
64         /** Marker reporting asynchronous invocation. */
65         public static final Marker INVOKE_ASYNCHRONOUS = build("INVOKE", "ASYNCHRONOUS");
66
67         /** Marker reporting entry into a component. */
68         public static final Marker ENTRY = MarkerFactory.getMarker("ENTRY");
69
70         /** Marker reporting exit from a component. */
71         public static final Marker EXIT = MarkerFactory.getMarker("EXIT");
72
73         /**
74          * Build nested, detached marker.
75          * @param m1 top token.
76          * @param m2 sub-token.
77          * @return detached Marker.
78          */
79         private static Marker build(final String m1, final String m2) {
80             final Marker marker = MarkerFactory.getDetachedMarker(m1);
81             marker.add(MarkerFactory.getDetachedMarker(m2));
82             return marker;
83         }
84
85         /**
86          * Hide and forbid construction.
87          */
88         private Markers() {
89             throw new UnsupportedOperationException();
90         }
91     }
92
93     /**
94      * MDC name constants.
95      */
96     public static final class MDCs {
97
98         /** MDC correlating messages for a logical transaction. */
99         public static final String REQUEST_ID = "RequestID";
100
101         /** MDC correlating messages for an invocation. */
102         public static final String INVOCATION_ID = "InvocationID";
103
104         /** MDC recording current service. */
105         public static final String SERVICE_NAME = "ServiceName";
106
107         /** MDC recording calling service. */
108         public static final String PARTNER_NAME = "PartnerName";
109
110         /** MDC recording current service instance. */
111         public static final String INSTANCE_UUID = "InstanceUUID";
112
113         /** MDC recording caller address. */
114         public static final String CLIENT_IP_ADDRESS = "ClientIPAddress";
115
116         /** MDC recording server address. */
117         public static final String SERVER_FQDN = "ServerFQDN";
118
119         /** MDC recording timestamp at the start of the current invocation. */
120         public static final String ENTRY_TIMESTAMP = "EntryTimestamp";
121
122         /** MDC reporting outcome code. */
123         public static final String RESPONSE_CODE = "ResponseCode";
124
125         /** MDC reporting outcome description. */
126         public static final String RESPONSE_DESCRIPTION = "ResponseDescription";
127
128         /** MDC reporting outcome error level. */
129         public static final String RESPONSE_SEVERITY = "Severity";
130
131         /** MDC reporting outcome error level. */
132         public static final String RESPONSE_STATUS = "StatusCode";
133
134         /**
135          * Hide and forbid construction.
136          */
137         private MDCs() {
138             throw new UnsupportedOperationException();
139         }
140     }
141
142     /**
143      * Header name constants.
144      */
145     public static final class Headers {
146
147         /** HTTP <tt>X-ONAP-RequestID</tt> header. */
148         public static final String REQUEST_ID = "X-ONAP-RequestID";
149
150         /** HTTP <tt>X-ONAP-InvocationID</tt> header. */
151         public static final String INVOCATION_ID = "X-ONAP-InvocationID";
152
153         /** HTTP <tt>X-ONAP-PartnerName</tt> header. */
154         public static final String PARTNER_NAME = "X-ONAP-PartnerName";
155
156         /**
157          * Hide and forbid construction.
158          */
159         private Headers() {
160             throw new UnsupportedOperationException();
161         }
162     }
163
164     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
165     //
166     // Enums.
167     //
168     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
169
170     /**
171      * Response success or not, for setting <tt>StatusCode</tt>.
172      */
173     public enum ResponseStatus {
174
175         /** Success. */
176         COMPLETED,
177
178         /** Not. */
179         ERROR,
180     }
181
182     /**
183      * Synchronous or asynchronous execution, for setting invocation marker.
184      */
185     public enum InvocationMode {
186
187         /** Synchronous, blocking. */
188         SYNCHRONOUS("SYNCHRONOUS", Markers.INVOKE_SYNCHRONOUS),
189
190         /** Asynchronous, non-blocking. */
191         ASYNCHRONOUS("", Markers.INVOKE_ASYNCHRONOUS);
192
193         /** Enum value. */
194         private String mString;
195
196         /** Corresponding marker. */
197         private Marker mMarker;
198
199         /**
200          * Construct enum.
201          *
202          * @param s enum value.
203          * @param m corresponding Marker.
204          */
205         InvocationMode(final String s, final Marker m) {
206             this.mString = s;
207             this.mMarker = m;
208         }
209
210         /**
211          * Get Marker for enum.
212          *
213          * @return Marker.
214          */
215         public Marker getMarker() {
216             return this.mMarker;
217         }
218
219         /**
220          * {@inheritDoc}
221          */
222         @Override
223         public String toString() {
224             return this.mString;
225         }
226     }
227
228 }