1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.bin; |
22 |
|
|
23 |
|
import java.io.BufferedOutputStream; |
24 |
|
import java.io.File; |
25 |
|
import java.io.FileNotFoundException; |
26 |
|
import java.io.FileOutputStream; |
27 |
|
import java.io.PrintStream; |
28 |
|
import java.util.Locale; |
29 |
|
|
30 |
|
import jalview.log.JLogger; |
31 |
|
import jalview.log.JLoggerI.LogLevel; |
32 |
|
import jalview.log.JLoggerLog4j; |
33 |
|
import jalview.util.ChannelProperties; |
34 |
|
import jalview.util.LaunchUtils; |
35 |
|
|
|
|
| 0% |
Uncovered Elements: 203 (203) |
Complexity: 71 |
Complexity Density: 0.62 |
|
36 |
|
public class Console |
37 |
|
{ |
38 |
|
|
39 |
|
public static JLoggerLog4j log; |
40 |
|
|
41 |
|
private static PrintStream out = System.out; |
42 |
|
|
43 |
|
private static PrintStream err = System.err; |
44 |
|
|
45 |
|
private static File logfile = null; |
46 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
47 |
0 |
public static PrintStream getOut()... |
48 |
|
{ |
49 |
0 |
return out; |
50 |
|
} |
51 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
0 |
public static PrintStream getErr()... |
53 |
|
{ |
54 |
0 |
return err; |
55 |
|
} |
56 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
0 |
public static void setOut(PrintStream p)... |
58 |
|
{ |
59 |
0 |
out = p; |
60 |
|
} |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
0 |
public static void setErr(PrintStream p)... |
63 |
|
{ |
64 |
0 |
err = p; |
65 |
|
} |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 4 |
Complexity Density: 0.27 |
|
67 |
0 |
public static boolean setLogFile(String filename, boolean append)... |
68 |
|
{ |
69 |
0 |
boolean usingLogfile = false; |
70 |
0 |
if (filename != null) |
71 |
|
{ |
72 |
0 |
if (filename.startsWith("~/")) |
73 |
|
{ |
74 |
0 |
filename = System.getProperty("user.home") + File.separator |
75 |
|
+ filename.substring(2); |
76 |
|
} |
77 |
0 |
logfile = new File(filename); |
78 |
|
|
79 |
0 |
try |
80 |
|
{ |
81 |
0 |
PrintStream logFilePrintStream = new PrintStream( |
82 |
|
new BufferedOutputStream( |
83 |
|
new FileOutputStream(logfile, append)), |
84 |
|
true); |
85 |
|
|
86 |
0 |
Console.setOut(logFilePrintStream); |
87 |
0 |
Console.setErr(logFilePrintStream); |
88 |
|
|
89 |
0 |
Console.info(LaunchUtils.LOGFILE_HANDOVER); |
90 |
|
|
91 |
0 |
Console.info(ChannelProperties.getProperty("app_name") |
92 |
|
.toUpperCase(Locale.ROOT) + " start of logging"); |
93 |
0 |
Console.debug(ChannelProperties.getProperty("app_name") |
94 |
|
+ " logging to " + filename); |
95 |
|
|
96 |
0 |
usingLogfile = true; |
97 |
|
} catch (FileNotFoundException e) |
98 |
|
{ |
99 |
0 |
Console.errPrintln("Error opening logfile: " + e.getMessage()); |
100 |
|
} |
101 |
|
} |
102 |
0 |
return usingLogfile; |
103 |
|
} |
104 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
105 |
0 |
public static void debug(String message, Throwable t)... |
106 |
|
{ |
107 |
0 |
if (Console.initLogger()) |
108 |
|
{ |
109 |
0 |
log.debug(message, t); |
110 |
|
} |
111 |
|
else |
112 |
|
{ |
113 |
0 |
outPrintln(message); |
114 |
0 |
Console.printStackTrace(t); |
115 |
|
} |
116 |
|
} |
117 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
118 |
0 |
public static void info(String message)... |
119 |
|
{ |
120 |
0 |
if (Console.initLogger()) |
121 |
|
{ |
122 |
0 |
log.info(message, null); |
123 |
|
} |
124 |
|
else |
125 |
|
{ |
126 |
0 |
outPrintln(message); |
127 |
|
} |
128 |
|
|
129 |
|
} |
130 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
131 |
0 |
public static void trace(String message, Throwable t)... |
132 |
|
{ |
133 |
0 |
if (Console.initLogger()) |
134 |
|
{ |
135 |
0 |
log.trace(message, t); |
136 |
|
} |
137 |
|
else |
138 |
|
{ |
139 |
0 |
outPrintln(message); |
140 |
0 |
Console.printStackTrace(t); |
141 |
|
} |
142 |
|
} |
143 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
144 |
0 |
public static void debug(String message)... |
145 |
|
{ |
146 |
0 |
if (Console.initLogger()) |
147 |
|
{ |
148 |
0 |
log.debug(message, null); |
149 |
|
} |
150 |
|
else |
151 |
|
{ |
152 |
0 |
outPrintln(message); |
153 |
|
} |
154 |
|
|
155 |
|
} |
156 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
157 |
0 |
public static void info(String message, Throwable t)... |
158 |
|
{ |
159 |
0 |
if (Console.initLogger()) |
160 |
|
{ |
161 |
0 |
log.info(message, t); |
162 |
|
} |
163 |
|
else |
164 |
|
{ |
165 |
0 |
outPrintln(message); |
166 |
0 |
Console.printStackTrace(t); |
167 |
|
} |
168 |
|
|
169 |
|
} |
170 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
171 |
0 |
public static void warn(String message)... |
172 |
|
{ |
173 |
0 |
if (Console.initLogger()) |
174 |
|
{ |
175 |
0 |
log.warn(message, null); |
176 |
|
} |
177 |
|
else |
178 |
|
{ |
179 |
0 |
outPrintln(message); |
180 |
|
} |
181 |
|
|
182 |
|
} |
183 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
184 |
0 |
public static void trace(String message)... |
185 |
|
{ |
186 |
0 |
if (Console.initLogger()) |
187 |
|
{ |
188 |
0 |
log.trace(message, null); |
189 |
|
} |
190 |
|
else |
191 |
|
{ |
192 |
0 |
outPrintln(message); |
193 |
|
} |
194 |
|
} |
195 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
196 |
0 |
public static void warn(String message, Throwable t)... |
197 |
|
{ |
198 |
0 |
if (Console.initLogger()) |
199 |
|
{ |
200 |
0 |
log.warn(message, t); |
201 |
|
} |
202 |
|
else |
203 |
|
{ |
204 |
0 |
outPrintln(message); |
205 |
0 |
Console.printStackTrace(t); |
206 |
|
} |
207 |
|
|
208 |
|
} |
209 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
210 |
0 |
public static void error(String message)... |
211 |
|
{ |
212 |
0 |
if (Console.initLogger()) |
213 |
|
{ |
214 |
0 |
log.error(message, null); |
215 |
|
} |
216 |
|
else |
217 |
|
{ |
218 |
0 |
jalview.bin.Console.errPrintln(message); |
219 |
|
} |
220 |
|
|
221 |
|
} |
222 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
223 |
0 |
public static void error(String message, Throwable t)... |
224 |
|
{ |
225 |
0 |
if (Console.initLogger()) |
226 |
|
{ |
227 |
0 |
log.error(message, t); |
228 |
|
} |
229 |
|
else |
230 |
|
{ |
231 |
0 |
jalview.bin.Console.errPrintln(message); |
232 |
0 |
Console.printStackTrace(t); |
233 |
|
} |
234 |
|
|
235 |
|
} |
236 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
237 |
0 |
public static void fatal(String message)... |
238 |
|
{ |
239 |
0 |
if (Console.initLogger()) |
240 |
|
{ |
241 |
0 |
log.fatal(message, null); |
242 |
|
} |
243 |
|
else |
244 |
|
{ |
245 |
0 |
jalview.bin.Console.errPrintln(message); |
246 |
|
} |
247 |
|
|
248 |
|
} |
249 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
250 |
0 |
public static void fatal(String message, Throwable t)... |
251 |
|
{ |
252 |
0 |
if (Console.initLogger()) |
253 |
|
{ |
254 |
0 |
log.fatal(message, t); |
255 |
|
} |
256 |
|
else |
257 |
|
{ |
258 |
0 |
jalview.bin.Console.errPrintln(message); |
259 |
0 |
Console.printStackTrace(t); |
260 |
|
} |
261 |
|
|
262 |
|
} |
263 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
264 |
0 |
public static boolean isDebugEnabled()... |
265 |
|
{ |
266 |
0 |
return log == null ? false : log.isDebugEnabled(); |
267 |
|
} |
268 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
269 |
0 |
public static boolean isTraceEnabled()... |
270 |
|
{ |
271 |
0 |
return log == null ? false : log.isTraceEnabled(); |
272 |
|
} |
273 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
274 |
0 |
public static JLogger.LogLevel getCachedLogLevel()... |
275 |
|
{ |
276 |
0 |
return Console.getCachedLogLevel(Cache.JALVIEWLOGLEVEL); |
277 |
|
} |
278 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
279 |
0 |
public static JLogger.LogLevel getCachedLogLevel(String key)... |
280 |
|
{ |
281 |
0 |
return getLogLevel(Cache.getDefault(key, "INFO")); |
282 |
|
} |
283 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
284 |
0 |
public static JLogger.LogLevel getLogLevel(String level)... |
285 |
|
{ |
286 |
0 |
return JLogger.toLevel(level); |
287 |
|
} |
288 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
289 |
0 |
public static JLogger getLogger()... |
290 |
|
{ |
291 |
0 |
return log; |
292 |
|
} |
293 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
294 |
0 |
public static boolean initLogger()... |
295 |
|
{ |
296 |
0 |
return initLogger(null); |
297 |
|
} |
298 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 7 |
Complexity Density: 0.39 |
|
299 |
0 |
public static boolean initLogger(String providedLogLevel)... |
300 |
|
{ |
301 |
0 |
if (log != null) |
302 |
|
{ |
303 |
0 |
return true; |
304 |
|
} |
305 |
0 |
try |
306 |
|
{ |
307 |
0 |
JLogger.LogLevel logLevel = JLogger.LogLevel.INFO; |
308 |
|
|
309 |
0 |
if (providedLogLevel != null && JLogger.isLevel(providedLogLevel)) |
310 |
|
{ |
311 |
0 |
logLevel = Console.getLogLevel(providedLogLevel); |
312 |
|
} |
313 |
|
else |
314 |
|
{ |
315 |
0 |
logLevel = getCachedLogLevel(); |
316 |
|
} |
317 |
|
|
318 |
0 |
JLoggerLog4j.setLogfile(logfile); |
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
0 |
JLoggerLog4j.getLogger("org.apache.axis", logLevel); |
324 |
|
|
325 |
|
|
326 |
0 |
log = JLoggerLog4j.getLogger(Cache.JALVIEW_LOGGER_NAME, logLevel); |
327 |
|
} catch (NoClassDefFoundError e) |
328 |
|
{ |
329 |
0 |
jalview.bin.Console |
330 |
|
.errPrintln("Could not initialise the logger framework"); |
331 |
0 |
Console.printStackTrace(e); |
332 |
|
} |
333 |
|
|
334 |
|
|
335 |
0 |
if (log != null) |
336 |
|
{ |
337 |
|
|
338 |
0 |
if (log.loggerExists()) |
339 |
0 |
log.debug(Console.LOGGING_TEST_MESSAGE); |
340 |
|
|
341 |
0 |
debug(ChannelProperties.getProperty("app_name") |
342 |
|
+ " Debugging Output Follows."); |
343 |
0 |
return true; |
344 |
|
} |
345 |
|
else |
346 |
|
{ |
347 |
0 |
return false; |
348 |
|
} |
349 |
|
} |
350 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
351 |
0 |
public static void setLogLevel(String logLevelString)... |
352 |
|
{ |
353 |
0 |
LogLevel l = null; |
354 |
0 |
try |
355 |
|
{ |
356 |
0 |
l = LogLevel.valueOf(logLevelString); |
357 |
|
} catch (IllegalArgumentException | NullPointerException e1) |
358 |
|
{ |
359 |
0 |
Console.debug("Invalid log level '" + logLevelString + "'"); |
360 |
0 |
return; |
361 |
|
} |
362 |
0 |
setLogLevel(l); |
363 |
|
} |
364 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
365 |
0 |
public static void setLogLevel(LogLevel l)... |
366 |
|
{ |
367 |
0 |
if (l != null) |
368 |
|
{ |
369 |
0 |
log.setLevel(l); |
370 |
0 |
JLoggerLog4j.getLogger("org.apache.axis", l); |
371 |
|
} |
372 |
|
} |
373 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
374 |
0 |
public static void outPrint()... |
375 |
|
{ |
376 |
0 |
outPrint(""); |
377 |
|
} |
378 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
379 |
0 |
public static void outPrintln()... |
380 |
|
{ |
381 |
0 |
outPrintln(""); |
382 |
|
} |
383 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
384 |
0 |
public static void outPrint(Object message)... |
385 |
|
{ |
386 |
0 |
outPrintMessage(message, false, false); |
387 |
|
} |
388 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
389 |
0 |
public static void outPrint(Object message, boolean forceStdout)... |
390 |
|
{ |
391 |
0 |
outPrintMessage(message, false, forceStdout); |
392 |
|
} |
393 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
394 |
0 |
public static void outPrintln(Object message)... |
395 |
|
{ |
396 |
0 |
outPrintMessage(message, true, false); |
397 |
|
} |
398 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 5 |
Complexity Density: 1.67 |
|
399 |
0 |
public static PrintStream outputStream(boolean forceStdout)... |
400 |
|
{ |
401 |
|
|
402 |
0 |
if (!forceStdout && Jalview.getInstance() != null |
403 |
|
&& Jalview.getInstance().getBootstrapArgs() != null |
404 |
|
&& Jalview.getInstance().getBootstrapArgs().outputToStdout()) |
405 |
|
{ |
406 |
0 |
return err; |
407 |
|
} |
408 |
|
else |
409 |
|
{ |
410 |
0 |
return out; |
411 |
|
} |
412 |
|
} |
413 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
414 |
0 |
public static void outPrintMessage(Object message, boolean newline,... |
415 |
|
boolean forceStdout) |
416 |
|
{ |
417 |
0 |
PrintStream ps = outputStream(forceStdout); |
418 |
0 |
if (newline) |
419 |
|
{ |
420 |
0 |
ps.println(message); |
421 |
|
} |
422 |
|
else |
423 |
|
{ |
424 |
0 |
ps.print(message); |
425 |
|
} |
426 |
|
} |
427 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
428 |
0 |
public static void errPrint()... |
429 |
|
{ |
430 |
0 |
errPrint(""); |
431 |
|
} |
432 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
433 |
0 |
public static void errPrintln()... |
434 |
|
{ |
435 |
0 |
errPrintln(""); |
436 |
|
} |
437 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
438 |
0 |
public static void errPrint(Object message)... |
439 |
|
{ |
440 |
0 |
err.print(message); |
441 |
|
} |
442 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
443 |
0 |
public static void errPrintln(Object message)... |
444 |
|
{ |
445 |
0 |
err.println(message); |
446 |
|
} |
447 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
448 |
0 |
public static void debugPrintStackTrace(Throwable t)... |
449 |
|
{ |
450 |
0 |
if (!isDebugEnabled()) |
451 |
|
{ |
452 |
0 |
return; |
453 |
|
} |
454 |
|
|
455 |
0 |
printStackTrace(t); |
456 |
|
} |
457 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
458 |
0 |
public static void printStackTrace(Throwable t)... |
459 |
|
{ |
460 |
|
|
461 |
0 |
t.printStackTrace(err); |
462 |
|
} |
463 |
|
|
464 |
|
public final static String LOGGING_TEST_MESSAGE = "Logging to STDERR"; |
465 |
|
|
466 |
|
} |