1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.common.ui.client.logging; |
17 |
|
|
18 |
|
import java.util.ArrayList; |
19 |
|
import java.util.HashMap; |
20 |
|
import java.util.List; |
21 |
|
import java.util.Map; |
22 |
|
|
23 |
|
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
24 |
|
import org.kuali.student.common.ui.client.service.LogRpcService; |
25 |
|
import org.kuali.student.common.ui.client.service.LogRpcServiceAsync; |
26 |
|
|
27 |
|
import com.google.gwt.core.client.GWT; |
28 |
|
import com.google.gwt.user.client.Command; |
29 |
|
import com.google.gwt.user.client.DeferredCommand; |
30 |
|
|
|
|
| 0% |
Uncovered Elements: 80 (80) |
Complexity: 28 |
Complexity Density: 0.58 |
|
31 |
|
public class Logger { |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
static LogLevel logLevel = LogLevel.WARN; |
36 |
|
static LogBuffer buffer = new LogBuffer(); |
37 |
|
static Map<String, String> clientContextInfo = new HashMap<String, String>(); |
38 |
|
static int maxBufferSize = Integer.MAX_VALUE; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
@param |
43 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
44 |
0
|
public static void setMaxBufferSize(int maxSize) {... |
45 |
0
|
LogBuffer tmp = new LogBuffer(maxSize); |
46 |
0
|
for (LogMessage m : buffer.getLogMessages()) { |
47 |
0
|
tmp.add(m); |
48 |
|
} |
49 |
0
|
buffer = tmp; |
50 |
|
} |
51 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
0
|
public static void setLogLevel(LogLevel level) {... |
53 |
0
|
logLevel = level; |
54 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
55 |
0
|
public static LogLevel getLogLevel() {... |
56 |
0
|
return logLevel; |
57 |
|
} |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
58 |
0
|
public static void log(LogMessage message) {... |
59 |
0
|
if (message.getLogLevel().getLevel() >= logLevel.getLevel()) { |
60 |
0
|
buffer.add(message); |
61 |
|
} |
62 |
|
} |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
64 |
0
|
public static void log(LogLevel level, String message) {... |
65 |
0
|
if (level.getLevel() >= logLevel.getLevel()) { |
66 |
0
|
buffer.add(new LogMessage(level, message, (Throwable) null)); |
67 |
|
} |
68 |
|
} |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
70 |
0
|
public static void log(LogLevel level, String message, Throwable error) {... |
71 |
0
|
if (level.getLevel() >= logLevel.getLevel()) { |
72 |
0
|
buffer.add(new LogMessage(level, message, error)); |
73 |
|
} |
74 |
|
} |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
0
|
public static void debug(String message) {... |
77 |
0
|
log(LogLevel.DEBUG, message); |
78 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
0
|
public static void debug(String message, Throwable error) {... |
80 |
0
|
log(LogLevel.DEBUG, message, error); |
81 |
|
} |
82 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
0
|
public static void info(String message) {... |
84 |
0
|
log(LogLevel.INFO, message); |
85 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
86 |
0
|
public static void info(String message, Throwable error) {... |
87 |
0
|
log(LogLevel.INFO, message, error); |
88 |
|
} |
89 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
90 |
0
|
public static void warn(String message) {... |
91 |
0
|
log(LogLevel.WARN, message); |
92 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
93 |
0
|
public static void warn(String message, Throwable error) {... |
94 |
0
|
log(LogLevel.WARN, message, error); |
95 |
|
} |
96 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
97 |
0
|
public static void error(String message) {... |
98 |
0
|
log(LogLevel.ERROR, message); |
99 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
100 |
0
|
public static void error(String message, Throwable error) {... |
101 |
0
|
log(LogLevel.ERROR, message, error); |
102 |
|
} |
103 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
104 |
0
|
public static void fatal(String message) {... |
105 |
0
|
log(LogLevel.FATAL, message); |
106 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
107 |
0
|
public static void fatal(String message, Throwable error) {... |
108 |
0
|
log(LogLevel.FATAL, message, error); |
109 |
|
} |
110 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
111 |
0
|
public static void reset() {... |
112 |
0
|
buffer = new LogBuffer(maxBufferSize); |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
117 |
0
|
public static Map<String, String> getClientContextInfo() {... |
118 |
0
|
return clientContextInfo; |
119 |
|
} |
120 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
121 |
0
|
public static void sendLogs() {... |
122 |
0
|
final List<LogMessage> messages = new ArrayList<LogMessage>(buffer.getLogMessages()); |
123 |
0
|
final Map<String, String> context = new HashMap<String, String>(clientContextInfo); |
124 |
0
|
reset(); |
125 |
0
|
DeferredCommand.addCommand(new Command() { |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
126 |
0
|
public void execute() {... |
127 |
0
|
String log = formatLog(messages); |
128 |
0
|
LogRpcServiceAsync logService = (LogRpcServiceAsync) GWT .create(LogRpcService.class); |
129 |
|
|
130 |
0
|
logService.sendLog(context, log, new KSAsyncCallback<Boolean>() { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
131 |
0
|
public void handleFailure(Throwable caught) {... |
132 |
0
|
GWT.log("sendLog Failed", caught); |
133 |
|
|
134 |
|
} |
135 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
136 |
0
|
public void onSuccess(Boolean result) {... |
137 |
|
|
138 |
0
|
GWT.log("sendLog OK", null); |
139 |
|
} |
140 |
|
}); |
141 |
|
} |
142 |
|
}); |
143 |
|
} |
144 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
145 |
0
|
private static String formatLog(List<LogMessage> messages) {... |
146 |
0
|
StringBuilder s = new StringBuilder(); |
147 |
0
|
for (LogMessage lm : messages) { |
148 |
0
|
s.append(lm.getLogLevel().toString()); |
149 |
0
|
s.append(":\t"); |
150 |
0
|
s.append(lm.getMessage()); |
151 |
0
|
Throwable t = lm.getError(); |
152 |
0
|
if (t != null) { |
153 |
0
|
appendStackTrace(t, s); |
154 |
|
} |
155 |
|
} |
156 |
0
|
return s.toString(); |
157 |
|
} |
158 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
159 |
0
|
private static void appendStackTrace(Throwable t, StringBuilder s) {... |
160 |
0
|
s.append(t.toString()); |
161 |
0
|
s.append(": at\n"); |
162 |
0
|
StackTraceElement[] stack = t.getStackTrace(); |
163 |
0
|
for (StackTraceElement frame : stack) { |
164 |
0
|
s.append(frame.toString()); |
165 |
0
|
s.append("\n"); |
166 |
|
} |
167 |
|
} |
168 |
|
} |