1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.log; |
22 |
|
|
23 |
|
import java.util.EnumSet; |
24 |
|
import java.util.HashMap; |
25 |
|
import java.util.Map; |
26 |
|
|
27 |
|
import jalview.bin.Console; |
28 |
|
import jalview.util.Platform; |
29 |
|
|
|
|
| 0% |
Uncovered Elements: 91 (91) |
Complexity: 37 |
Complexity Density: 0.76 |
|
30 |
|
public abstract class JLogger implements JLoggerI |
31 |
|
{ |
32 |
|
protected String name; |
33 |
|
|
34 |
|
protected LogLevel level; |
35 |
|
|
36 |
|
private Object logger = null; |
37 |
|
|
38 |
|
private static Map<String, JLogger> registry = new HashMap<>(); |
39 |
|
|
40 |
|
|
41 |
|
protected abstract void loggerSetup(); |
42 |
|
|
43 |
|
public abstract boolean loggerExists(); |
44 |
|
|
45 |
|
protected abstract void loggerSetLevel(LogLevel level); |
46 |
|
|
47 |
|
protected abstract void loggerLogMessage(LogLevel level, String message, |
48 |
|
Throwable t); |
49 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
50 |
0 |
public static boolean isLevel(String levelString)... |
51 |
|
{ |
52 |
0 |
for (LogLevel l : EnumSet.allOf(LogLevel.class)) |
53 |
|
{ |
54 |
0 |
if (l.name().equals(levelString)) |
55 |
0 |
return true; |
56 |
|
} |
57 |
0 |
return false; |
58 |
|
} |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
60 |
0 |
public static LogLevel toLevel(String levelString)... |
61 |
|
{ |
62 |
0 |
try |
63 |
|
{ |
64 |
0 |
return LogLevel.valueOf(levelString); |
65 |
|
} catch (IllegalArgumentException e) |
66 |
|
{ |
67 |
0 |
Console.error("Could not parse LogLevel '" + levelString + "'", e); |
68 |
0 |
return LogLevel.INFO; |
69 |
|
} |
70 |
|
} |
71 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
0 |
public static JLogger getLogger(Class c)... |
73 |
|
{ |
74 |
0 |
return getLogger(c, LogLevel.INFO); |
75 |
|
} |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
0 |
public static JLogger getLogger(Class c, LogLevel loglevel)... |
78 |
|
{ |
79 |
0 |
return getLogger(c.getCanonicalName(), loglevel); |
80 |
|
} |
81 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
0 |
public static JLogger getLogger(String name)... |
83 |
|
{ |
84 |
0 |
return getLogger(name, LogLevel.INFO); |
85 |
|
} |
86 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
87 |
0 |
public static JLogger getLogger(String name, LogLevel loglevel)... |
88 |
|
{ |
89 |
0 |
return registry.containsKey(name) ? (JLogger) registry.get(name) : null; |
90 |
|
} |
91 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
92 |
0 |
protected JLogger()... |
93 |
|
{ |
94 |
|
} |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
96 |
0 |
protected JLogger(String name, LogLevel level)... |
97 |
|
{ |
98 |
0 |
this.name = name; |
99 |
0 |
this.level = level; |
100 |
0 |
this.loggerSetup(); |
101 |
0 |
this.registryStore(); |
102 |
|
} |
103 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
104 |
0 |
protected void registryStore()... |
105 |
|
{ |
106 |
0 |
registry.put(this.name, this); |
107 |
|
} |
108 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
109 |
0 |
protected static boolean registryContainsKey(String name)... |
110 |
|
{ |
111 |
0 |
return registry.containsKey(name); |
112 |
|
} |
113 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
114 |
0 |
protected static JLogger registryGet(String name)... |
115 |
|
{ |
116 |
0 |
return registry.get(name); |
117 |
|
} |
118 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
119 |
0 |
@Override... |
120 |
|
public LogLevel getLevel() |
121 |
|
{ |
122 |
0 |
return this.level; |
123 |
|
} |
124 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
125 |
0 |
@Override... |
126 |
|
public void setLevel(LogLevel level) |
127 |
|
{ |
128 |
0 |
this.level = level; |
129 |
0 |
if (loggerExists()) |
130 |
0 |
loggerSetLevel(level); |
131 |
|
} |
132 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 6 |
Complexity Density: 0.5 |
|
133 |
0 |
private boolean println(LogLevel loglevel, String message, Throwable t)... |
134 |
|
{ |
135 |
0 |
if (loglevel.compareTo(this.level) < 0) |
136 |
|
{ |
137 |
0 |
return false; |
138 |
|
} |
139 |
0 |
if (!loggerExists() || Platform.isJS()) |
140 |
|
{ |
141 |
0 |
String logLine = String.format("%s: %s", loglevel.toString(), |
142 |
|
message); |
143 |
0 |
jalview.bin.Console.outPrintln(logLine); |
144 |
0 |
if (t != null) |
145 |
|
{ |
146 |
0 |
if (loglevel.compareTo(LogLevel.DEBUG) <= 0) |
147 |
0 |
t.printStackTrace(System.err); |
148 |
|
else |
149 |
0 |
jalview.bin.Console.errPrintln(t.getMessage()); |
150 |
|
} |
151 |
0 |
return false; |
152 |
|
} |
153 |
|
else |
154 |
|
{ |
155 |
0 |
loggerLogMessage(loglevel, message, t); |
156 |
0 |
return true; |
157 |
|
} |
158 |
|
} |
159 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
160 |
0 |
@Override... |
161 |
|
public void trace(String message) |
162 |
|
{ |
163 |
0 |
trace(message, null); |
164 |
|
} |
165 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
166 |
0 |
@Override... |
167 |
|
public void trace(String message, Throwable t) |
168 |
|
{ |
169 |
0 |
println(LogLevel.TRACE, message, t); |
170 |
|
} |
171 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
172 |
0 |
@Override... |
173 |
|
public void debug(String message) |
174 |
|
{ |
175 |
0 |
debug(message, null); |
176 |
|
} |
177 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
178 |
0 |
@Override... |
179 |
|
public void debug(String message, Throwable t) |
180 |
|
{ |
181 |
0 |
println(LogLevel.DEBUG, message, t); |
182 |
|
} |
183 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
184 |
0 |
@Override... |
185 |
|
public void info(String message) |
186 |
|
{ |
187 |
0 |
info(message, null); |
188 |
|
} |
189 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
190 |
0 |
@Override... |
191 |
|
public void info(String message, Throwable t) |
192 |
|
{ |
193 |
0 |
println(LogLevel.INFO, message, t); |
194 |
|
} |
195 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
196 |
0 |
@Override... |
197 |
|
public void warn(String message) |
198 |
|
{ |
199 |
0 |
warn(message, null); |
200 |
|
} |
201 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
202 |
0 |
@Override... |
203 |
|
public void warn(String message, Throwable t) |
204 |
|
{ |
205 |
0 |
println(LogLevel.WARN, message, t); |
206 |
|
} |
207 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
208 |
0 |
@Override... |
209 |
|
public void error(String message) |
210 |
|
{ |
211 |
0 |
error(message, null); |
212 |
|
} |
213 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
214 |
0 |
@Override... |
215 |
|
public void error(String message, Throwable t) |
216 |
|
{ |
217 |
0 |
println(LogLevel.ERROR, message, t); |
218 |
|
} |
219 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
220 |
0 |
@Override... |
221 |
|
public void fatal(String message) |
222 |
|
{ |
223 |
0 |
fatal(message, null); |
224 |
|
} |
225 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
226 |
0 |
@Override... |
227 |
|
public void fatal(String message, Throwable t) |
228 |
|
{ |
229 |
0 |
println(LogLevel.FATAL, message, t); |
230 |
|
} |
231 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
232 |
0 |
@Override... |
233 |
|
public boolean isDebugEnabled() |
234 |
|
{ |
235 |
0 |
return level.compareTo(LogLevel.DEBUG) <= 0; |
236 |
|
} |
237 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
238 |
0 |
@Override... |
239 |
|
public boolean isTraceEnabled() |
240 |
|
{ |
241 |
0 |
return level.compareTo(LogLevel.TRACE) <= 0; |
242 |
|
} |
243 |
|
} |