1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/*-
* ============LICENSE_START==========================================
* OPENECOMP - DCAE
* ===================================================================
* Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
* ===================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
*/
package org.openecomp.ncomp.sirius.manager.logging;
import org.eclipse.emf.ecore.EObject;
import org.slf4j.MDC;
import org.openecomp.entity.EcompOperationEnum;
import org.openecomp.entity.EcompSubComponentInstance;
import org.openecomp.logger.EcompLogger;
import org.openecomp.logger.EcompMessageEnum;
import org.openecomp.logger.LogCategoryEnum;
import org.openecomp.logger.StatusCodeEnum;
import org.openecomp.logger.Stopwatch;
import org.openecomp.ncomp.sirius.manager.ISiriusServer;
import org.openecomp.ncomp.sirius.manager.ManagementServer;
public class NcompLogger extends EcompLogger {
public static final String UNKNOWN_SERVICE_NAME = "UnknownServiceName";
private NcompLogger() {
super();
}
public static synchronized NcompLogger getNcompLogger() {
return new NcompLogger();
}
public void setInstanceId(ISiriusServer s, EObject o) {
String port = s.getServer().getProps().getProperty("server.port");
String path = ManagementServer.object2ref(o);
setInstanceId(EcompSubComponentInstance.getServerName() + ":" + port + path);
}
public boolean recordAuditEventStartIfNeeded(EcompOperationEnum op, ISiriusServer s, EObject o) {
if (MDC.get(UNKNOWN_SERVICE_NAME) == null)
return false;
if (op.toString().endsWith("@getRequestLogger"))
return false;
MDC.remove(UNKNOWN_SERVICE_NAME);
setOperation(op);
setInstanceId(s, o);
recordAuditEventStart();
return true;
}
public void startUnknownAuditEvent(String contextPath) {
MDC.put(UNKNOWN_SERVICE_NAME, contextPath);
}
@Override
protected void recordMetricEventEnd(StatusCodeEnum statusCode, LogCategoryEnum logCategoryEnum,
String[] customFields, EcompMessageEnum msg, String... args) {
// if service name is not know we ignore
// assuming this is is the getRequestLogger case that we want to ignore.
// System.out.println("WWWWWW METRICS END 1: " + MDC.getCopyOfContextMap());
if (MDC.get(UNKNOWN_SERVICE_NAME) != null)
return;
super.recordMetricEventEnd(statusCode, logCategoryEnum, customFields, msg, args);
// System.out.println("WWWWWW METRICS END 2: " + MDC.getCopyOfContextMap());
}
@Override
public void setClassName() {
StackTraceElement[] l = Thread.currentThread().getStackTrace();
for (StackTraceElement x : l) {
if (x.getClassName().equals("java.lang.Thread"))
continue;
if (x.getClassName().equals("org.openecomp.logger.EcompLogger"))
continue;
if (x.getClassName().equals("org.openecomp.ncomp.sirius.manager.logging.NcompLogger"))
continue;
if (x.getClassName().equals("org.openecomp.ncomp.sirius.manager.JavaHttpClient"))
continue;
if (x.getClassName().equals("org.openecomp.logger.Stopwatch"))
continue;
if (x.getClassName().equals("org.openecomp.ncomp.sirius.manager.AbstractClient"))
continue;
MDC.put(CLASS_NAME, x.getClassName() + "@" + x.getMethodName() + ":" + x.getLineNumber());
return;
}
}
public boolean isTargetSelf() {
String t = Stopwatch.getTopTarget();
return t == null || t.startsWith("self");
}
}
|