2 ===============LICENSE_START=======================================================
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
12 http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.acumos.demo.logging.util;
22 import org.slf4j.Marker;
23 import org.slf4j.MarkerFactory;
28 * Constants for standard ACUMOS headers, MDCs, etc.
31 public final class ACUMOSLogConstants {
34 * Hide and forbid construction.
36 private ACUMOSLogConstants() {
37 throw new UnsupportedOperationException();
40 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
44 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
49 public static final class Markers {
51 /** Marker reporting invocation. */
52 public static final Marker INVOKE = MarkerFactory.getMarker("INVOKE");
54 /** Marker reporting invocation. */
55 public static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE_RETURN");
57 /** Marker reporting synchronous invocation. */
58 public static final Marker INVOKE_SYNCHRONOUS = build("INVOKE", "SYNCHRONOUS");
60 /** Marker reporting asynchronous invocation. */
61 public static final Marker INVOKE_ASYNCHRONOUS = build("INVOKE", "ASYNCHRONOUS");
63 /** Marker reporting entry into a component. */
64 public static final Marker ENTRY = MarkerFactory.getMarker("ENTRY");
66 /** Marker reporting exit from a component. */
67 public static final Marker EXIT = MarkerFactory.getMarker("EXIT");
70 * Build nested, detached marker.
76 * @return detached Marker.
78 private static Marker build(final String m1, final String m2) {
79 final Marker marker = MarkerFactory.getDetachedMarker(m1);
80 marker.add(MarkerFactory.getDetachedMarker(m2));
85 * Hide and forbid construction.
88 throw new UnsupportedOperationException();
95 public static final class MDCs {
97 // Tracing. ////////////////////////////////////////////////////////////
99 /** MDC correlating messages for a logical transaction. */
100 public static final String REQUEST_ID = "RequestID";
102 /** MDC recording target service. */
103 public static final String TARGET_SERVICE_NAME = "TargetServiceName";
105 /** MDC recording target entity. */
106 public static final String TARGET_ENTITY = "TargetEntity";
108 // Network. ////////////////////////////////////////////////////////////
110 /** MDC recording caller address. */
111 public static final String CLIENT_IP_ADDRESS = "ClientIPAddress";
113 /** MDC recording server address. */
114 public static final String SERVER_FQDN = "ServerFQDN";
116 /** MDC reporting outcome code. */
117 public static final String RESPONSE_CODE = "ResponseCode";
119 /** MDC reporting outcome description. */
120 public static final String RESPONSE_DESCRIPTION = "ResponseDescription";
122 /** MDC reporting outcome error level. */
123 public static final String RESPONSE_SEVERITY = "Severity";
125 /** MDC reporting outcome status of the request. */
126 public static final String STATUS_CODE = "StatusCode";
128 // Unsorted. ///////////////////////////////////////////////////////////
131 * Hide and forbid construction.
134 throw new UnsupportedOperationException();
139 * Header name constants.
141 public static final class Headers {
143 /** HTTP X-ACUMOS-RequestID header. */
144 public static final String REQUEST_ID = "X-ACUMOS-RequestID";
147 * Hide and forbid construction.
150 throw new UnsupportedOperationException();
155 * Overrideable method to set MDCs based on property values.
157 public static void setDefaultMDCs() {
158 MDC.put(MDCs.RESPONSE_CODE, "200");
159 MDC.put(MDCs.RESPONSE_DESCRIPTION, "200 OK");
160 MDC.put(MDCs.RESPONSE_SEVERITY, ResponseSeverity.INFO.toString());
161 MDC.put(MDCs.STATUS_CODE, ResponseStatus.INPROGRESS.toString());
164 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
168 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
171 * Response success or not, for setting StatusCode.
173 public enum ResponseStatus {
181 * Response of log level, for setting Severity.
183 public enum ResponseSeverity {
194 * Synchronous or asynchronous execution, for setting invocation marker.
196 public enum InvocationMode {
198 /** Synchronous, blocking. */
199 SYNCHRONOUS("SYNCHRONOUS", Markers.INVOKE_SYNCHRONOUS),
201 /** Asynchronous, non-blocking. */
202 ASYNCHRONOUS("ASYNCHRONOUS", Markers.INVOKE_ASYNCHRONOUS);
205 private String mString;
207 /** Corresponding marker. */
208 private Marker mMarker;
216 * corresponding Marker.
218 InvocationMode(final String s, final Marker m) {
224 * Get Marker for enum.
228 public Marker getMarker() {
233 public String toString() {