2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2018 Amdocs
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.logging.ref.slf4j;
24 import org.slf4j.Marker;
25 import org.slf4j.MarkerFactory;
28 * Constants for standard ONAP headers, MDCs, etc.
31 * See <tt>package-info.java</tt>.
34 public final class ONAPLogConstants {
36 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
40 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
43 * Hide and forbid construction.
45 private ONAPLogConstants() {
46 throw new UnsupportedOperationException();
49 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
53 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58 public static final class Markers {
60 /** Marker reporting invocation. */
61 public static final Marker INVOKE = MarkerFactory.getMarker("INVOKE");
63 /** Marker reporting invocation return. */
64 public static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE_RETURN");
66 /** Marker reporting synchronous invocation. */
67 public static final Marker INVOKE_SYNCHRONOUS = build("INVOKE", "SYNCHRONOUS");
69 /** Marker reporting asynchronous invocation. */
70 public static final Marker INVOKE_ASYNCHRONOUS = build("INVOKE", "ASYNCHRONOUS");
72 /** Marker reporting entry into a component. */
73 public static final Marker ENTRY = MarkerFactory.getMarker("ENTRY");
75 /** Marker reporting exit from a component. */
76 public static final Marker EXIT = MarkerFactory.getMarker("EXIT");
79 * Build nested, detached marker.
81 * @param m1 top token.
82 * @param m2 sub-token.
83 * @return detached Marker.
85 private static Marker build(final String m1, final String m2) {
86 final Marker marker = MarkerFactory.getDetachedMarker(m1);
87 marker.add(MarkerFactory.getDetachedMarker(m2));
92 * Hide and forbid construction.
95 throw new UnsupportedOperationException();
100 * MDC name constants.
102 public static final class MDCs {
104 // Tracing. ////////////////////////////////////////////////////////////
106 /** MDC correlating messages for an invocation. */
107 public static final String INVOCATION_ID = "InvocationID";
109 /** MDC correlating messages for a logical transaction. */
110 public static final String REQUEST_ID = "RequestID";
112 /** MDC recording calling partner name. */
113 public static final String PARTNER_NAME = "PartnerName";
115 /** MDC recording current service. */
116 public static final String SERVICE_NAME = "ServiceName";
118 /** MDC recording target service. */
119 public static final String TARGET_SERVICE_NAME = "TargetServiceName";
121 /** MDC recording target entity. */
122 public static final String TARGET_ENTITY = "TargetEntity";
124 /** MDC recording target element. */
125 public static final String TARGET_ELEMENT = "TargetElement";
127 /** MDC recording current service instance id. */
128 public static final String SERVICE_INSTANCE_ID = "ServiceInstanceID";
130 /** MDC recording current instance id. */
131 public static final String INSTANCE_UUID = "InstanceID";
133 // Network. ////////////////////////////////////////////////////////////
135 /** MDC recording caller address. */
136 public static final String CLIENT_IP_ADDRESS = "ClientIPAddress";
138 /** MDC recording server IP address. */
139 public static final String SERVER_IP_ADDRESS = "ServerIPAddress";
141 /** MDC recording server FQDN. */
142 public static final String SERVER_FQDN = "ServerFQDN";
144 /** MDC recording virtual server name. */
145 public static final String VIRTUAL_SERVER_NAME = "VirtualServerName";
147 /** MDC recording context name. */
148 public static final String CONTEXT_NAME = "ContextName";
151 * MDC recording timestamp at the start of the current request,
152 * with the same scope as {@link #REQUEST_ID}.
158 * Easily confused with {@link #INVOKE_TIMESTAMP}.
161 * No mechanism for propagation between components, e.g. via HTTP headers.
164 * Whatever mechanism we define, it's going to be costly.
169 public static final String ENTRY_TIMESTAMP = "EntryTimestamp";
171 /** MDC recording timestamp at the start of the current invocation. */
172 public static final String INVOKE_TIMESTAMP = "InvokeTimestamp";
174 /** MDC recording elapsed time. */
175 public static final String ELAPSED_TIME = "ElapsedTime";
177 /** MDC recording log timestamp. */
178 public static final String LOG_TIMESTAMP = "LogTimestamp";
180 // Outcomes. ///////////////////////////////////////////////////////////
182 /** MDC reporting outcome code. */
183 public static final String RESPONSE_CODE = "ResponseCode";
185 /** MDC reporting outcome description. */
186 public static final String RESPONSE_DESCRIPTION = "ResponseDesc";
188 /** MDC reporting severity */
189 public static final String RESPONSE_SEVERITY = "Severity";
191 /** MDC reporting response status code */
192 public static final String RESPONSE_STATUS_CODE = "StatusCode";
194 /** MDC recording error code. */
195 public static final String ERROR_CODE = "ErrorCode";
197 /** MDC recording error description. */
198 public static final String ERROR_DESC = "ErrorDesc";
200 // Unsorted. ///////////////////////////////////////////////////////////
203 * Hide and forbid construction.
206 throw new UnsupportedOperationException();
211 * Header name constants.
213 public static final class Headers {
215 /** HTTP <tt>X-ONAP-RequestID</tt> header. */
216 public static final String REQUEST_ID = "X-ONAP-RequestID";
218 /** HTTP <tt>X-ONAP-InvocationID</tt> header. */
219 public static final String INVOCATION_ID = "X-ONAP-InvocationID";
221 /** HTTP <tt>X-ONAP-PartnerName</tt> header. */
222 public static final String PARTNER_NAME = "X-ONAP-PartnerName";
225 * Hide and forbid construction.
228 throw new UnsupportedOperationException();
232 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
236 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
239 * Response success or not, for setting <tt>StatusCode</tt>.
241 public enum ResponseStatus {
254 * Synchronous or asynchronous execution, for setting invocation marker.
256 public enum InvocationMode {
258 /** Synchronous, blocking. */
259 SYNCHRONOUS("SYNCHRONOUS", Markers.INVOKE_SYNCHRONOUS),
261 /** Asynchronous, non-blocking. */
262 ASYNCHRONOUS("ASYNCHRONOUS", Markers.INVOKE_ASYNCHRONOUS);
265 private String mString;
267 /** Corresponding marker. */
268 private Marker mMarker;
273 * @param s enum value.
274 * @param m corresponding Marker.
276 InvocationMode(final String s, final Marker m) {
282 * Get Marker for enum.
286 public Marker getMarker() {
294 public String toString() {