1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.util;
18
19
20
21
22
23
24 public class PerformanceLogger {
25
26 private static final org.apache.log4j.Logger LOG =
27 org.apache.log4j.Logger.getLogger(PerformanceLogger.class);
28 private long startTime;
29 private String documentId;
30
31 public PerformanceLogger() {
32 recordStartTime();
33 }
34
35 public PerformanceLogger(String documentId) {
36 this();
37 this.documentId = documentId;
38 }
39
40 private void recordStartTime() {
41 this.startTime = System.currentTimeMillis();
42 }
43
44 public void log(String message) {
45 log(message, false);
46 }
47
48 public void log(String message, boolean terminalPoint) {
49 if ( LOG.isInfoEnabled() ) {
50 long endTime = System.currentTimeMillis();
51 long totalTime = endTime - startTime;
52 String logMessage = "Time: "+totalTime+" ms, ";
53 if (documentId != null) {
54 logMessage+="docId="+documentId+", ";
55 }
56 logMessage += message;
57 if (terminalPoint) {
58 logMessage += "\n";
59 }
60 LOG.info(logMessage);
61 }
62 }
63
64 }