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.
30 * <p>See <tt>package-info.java</tt>.</p>
32 public final class ONAPLogConstants {
34 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
38 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
41 * Hide and forbid construction.
43 private ONAPLogConstants() {
44 throw new UnsupportedOperationException();
47 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
51 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
56 public static final class Markers {
58 /** Marker reporting invocation. */
59 public static final Marker INVOKE = MarkerFactory.getMarker("INVOKE");
61 /** Marker reporting invocation. */
62 public static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE_RETURN");
64 /** Marker reporting synchronous invocation. */
65 public static final Marker INVOKE_SYNCHRONOUS = build("INVOKE", "SYNCHRONOUS");
67 /** Marker reporting asynchronous invocation. */
68 public static final Marker INVOKE_ASYNCHRONOUS = build("INVOKE", "ASYNCHRONOUS");
70 /** Marker reporting entry into a component. */
71 public static final Marker ENTRY = MarkerFactory.getMarker("ENTRY");
73 /** Marker reporting exit from a component. */
74 public static final Marker EXIT = MarkerFactory.getMarker("EXIT");
77 * Build nested, detached marker.
78 * @param m1 top token.
79 * @param m2 sub-token.
80 * @return detached Marker.
82 private static Marker build(final String m1, final String m2) {
83 final Marker marker = MarkerFactory.getDetachedMarker(m1);
84 marker.add(MarkerFactory.getDetachedMarker(m2));
89 * Hide and forbid construction.
92 throw new UnsupportedOperationException();
99 public static final class MDCs {
101 // Tracing. ////////////////////////////////////////////////////////////
103 /** MDC correlating messages for an invocation. */
104 public static final String INVOCATION_ID = "InvocationID";
106 /** MDC correlating messages for a logical transaction. */
107 public static final String REQUEST_ID = "RequestID";
109 /** MDC recording calling service. */
110 public static final String PARTNER_NAME = "PartnerName";
112 /** MDC recording current service. */
113 public static final String SERVICE_NAME = "ServiceName";
115 /** MDC recording target service. */
116 public static final String TARGET_SERVICE_NAME = "TargetServiceName";
118 /** MDC recording target entity. */
119 public static final String TARGET_ENTITY = "TargetEntity";
121 /** MDC recording current service instance. */
122 public static final String INSTANCE_UUID = "InstanceUUID";
124 // Network. ////////////////////////////////////////////////////////////
126 /** MDC recording caller address. */
127 public static final String CLIENT_IP_ADDRESS = "ClientIPAddress";
129 /** MDC recording server address. */
130 public static final String SERVER_FQDN = "ServerFQDN";
133 * MDC recording timestamp at the start of the current request,
134 * with the same scope as {@link #REQUEST_ID}.
138 * <ul>Easily confused with {@link #INVOKE_TIMESTAMP}.</ul>
139 * <ul>No mechanism for propagation between components, e.g. via HTTP headers.</ul>
140 * <ul>Whatever mechanism we define, it's going to be costly.</ul>
144 public static final String ENTRY_TIMESTAMP = "EntryTimestamp";
146 /** MDC recording timestamp at the start of the current invocation. */
147 public static final String INVOKE_TIMESTAMP = "InvokeTimestamp";
149 // Outcomes. ///////////////////////////////////////////////////////////
151 /** MDC reporting outcome code. */
152 public static final String RESPONSE_CODE = "ResponseCode";
154 /** MDC reporting outcome description. */
155 public static final String RESPONSE_DESCRIPTION = "ResponseDescription";
157 /** MDC reporting outcome error level. */
158 public static final String RESPONSE_SEVERITY = "Severity";
160 /** MDC reporting outcome error level. */
161 public static final String RESPONSE_STATUS_CODE = "StatusCode";
163 // Unsorted. ///////////////////////////////////////////////////////////
166 * Hide and forbid construction.
169 throw new UnsupportedOperationException();
174 * Header name constants.
176 public static final class Headers {
178 /** HTTP <tt>X-ONAP-RequestID</tt> header. */
179 public static final String REQUEST_ID = "X-ONAP-RequestID";
181 /** HTTP <tt>X-ONAP-InvocationID</tt> header. */
182 public static final String INVOCATION_ID = "X-ONAP-InvocationID";
184 /** HTTP <tt>X-ONAP-PartnerName</tt> header. */
185 public static final String PARTNER_NAME = "X-ONAP-PartnerName";
188 * Hide and forbid construction.
191 throw new UnsupportedOperationException();
195 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
199 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
202 * Response success or not, for setting <tt>StatusCode</tt>.
204 public enum ResponseStatus {
217 * Synchronous or asynchronous execution, for setting invocation marker.
219 public enum InvocationMode {
221 /** Synchronous, blocking. */
222 SYNCHRONOUS("SYNCHRONOUS", Markers.INVOKE_SYNCHRONOUS),
224 /** Asynchronous, non-blocking. */
225 ASYNCHRONOUS("ASYNCHRONOUS", Markers.INVOKE_ASYNCHRONOUS);
228 private String mString;
230 /** Corresponding marker. */
231 private Marker mMarker;
236 * @param s enum value.
237 * @param m corresponding Marker.
239 InvocationMode(final String s, final Marker m) {
245 * Get Marker for enum.
249 public Marker getMarker() {
257 public String toString() {