1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.util;
17
18 import java.util.Formatter;
19
20
21
22
23
24
25 public class PerformanceLogger {
26
27 private static final org.apache.log4j.Logger LOG =
28 org.apache.log4j.Logger.getLogger(PerformanceLogger.class);
29 private long startTime;
30 private String documentId;
31
32 public PerformanceLogger() {
33 recordStartTime();
34 }
35
36 public PerformanceLogger(String documentId) {
37 this();
38 this.documentId = documentId;
39 }
40
41 private void recordStartTime() {
42 this.startTime = System.currentTimeMillis();
43 }
44
45 public void log(String message) {
46 log(message, false);
47 }
48
49 public void log(String message, boolean terminalPoint) {
50 if ( LOG.isInfoEnabled() ) {
51 long endTime = System.currentTimeMillis();
52 long totalTime = endTime - startTime;
53 String logMessage = new Formatter().format("Time: %7dms, ", totalTime).toString();
54 if (documentId != null) {
55 logMessage+="docId="+documentId+", ";
56 }
57 logMessage += message;
58 if (terminalPoint) {
59 logMessage += "\n";
60 }
61 LOG.info(logMessage);
62 }
63 }
64
65 public void debug(String message) {
66 this.debug(message, false);
67 }
68
69 public void debug(String message, boolean terminalPoint) {
70 if ( LOG.isDebugEnabled() ) {
71 long endTime = System.currentTimeMillis();
72 long totalTime = endTime - startTime;
73 String logMessage = new Formatter().format("Time: %7dms, ", totalTime).toString();
74 if (documentId != null) {
75 logMessage+="docId="+documentId+", ";
76 }
77 logMessage += message;
78 if (terminalPoint) {
79 logMessage += "\n";
80 }
81 LOG.debug(logMessage);
82 }
83 }
84 }