blob: 457da14bd2d6959b60d96904a58a5ad653dd991d (
plain)
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
|
/*-
* ============LICENSE_START=======================================================
* Common Logging Library
* ================================================================================
* 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.cl.eelf;
import org.openecomp.cl.api.LogLine;
import org.openecomp.cl.mdc.MdcContext;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/** This class is used to help standardize how log lines are written and provide
* profiling info. */
public class AuditLogLine extends LogLine {
/** (non-Javadoc)
* @see org.openecomp.cl.api.LogLine#getFormattedLine()
*/
public String getFormattedLine() {
// calculate start/end/elapsed times
Date currentDateTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
String startTimeString = getMdcValue(MdcContext.MDC_START_TIME);
String endTimeString = formatter.format(currentDateTime);
long elapsedTime = 0;
Date startDateTime;
try {
startDateTime = formatter.parse(startTimeString);
elapsedTime = currentDateTime.getTime() - startDateTime.getTime();
} catch (ParseException e) {
// Leave an elapsed time of 0 if the start time was not properly formatted
}
String elapsedTimeString = Long.toString(elapsedTime);
return startTimeString + "|" + // 1 start time
endTimeString + "|" + // 2 end time
getMdcValue(MdcContext.MDC_REQUEST_ID) + "|" + // 3 transaction id
getMdcValue(MdcContext.MDC_SERVICE_INSTANCE_ID) + "|" + // 4 service instance
Thread.currentThread().getName() + "|" + // 5 thread id
getMdcValue(MdcContext.MDC_SERVER_FQDN) + "|" + // 6 physical/virtual server name
getMdcValue(MdcContext.MDC_SERVICE_NAME) + "|" + // 7 service name
getMdcValue(MdcContext.MDC_PARTNER_NAME) + "|" + // 8 partner name
fieldValue(DefinedFields.STATUS_CODE) + "|" + // 9 status code
fieldValue(DefinedFields.RESPONSE_CODE) + "|" + // 10 response code
fieldValue(DefinedFields.RESPONSE_DESCRIPTION) + "|" + // 11 response description
fieldValue(DefinedFields.INSTANCE_UUID) + "|" + // 12 instance UUID
level + "|" + // 13 log level
fieldValue(DefinedFields.SEVERITY) + "|" + // 14 log severity
fieldValue(DefinedFields.SERVER_IP) + "|" + // 15 server ip
elapsedTimeString + "|" + // 16 elapsed time
getMdcValue(MdcContext.MDC_SERVER_FQDN) + "|" + // 17 server name
getMdcValue(MdcContext.MDC_CLIENT_ADDRESS) + "|" + // 18 client ip address
fieldValue(DefinedFields.CLASS_NAME) + "|" + // 19 class name
"" + "|" + // 20 deprecated
fieldValue(DefinedFields.PROCESS_KEY) + "|" + // 21 process key
fieldValue(DefinedFields.CUSTOM_1) + "|" + // 22 custom 1
fieldValue(DefinedFields.CUSTOM_2) + "|" + // 23 custom 2
fieldValue(DefinedFields.CUSTOM_3) + "|" + // 24 custom 3
fieldValue(DefinedFields.CUSTOM_4) + "|" + // 25 custom 4
message; // 26 details
}
}
|