1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.util; |
22 |
|
|
23 |
|
import java.lang.reflect.InvocationTargetException; |
24 |
|
import java.lang.reflect.Method; |
25 |
|
|
|
|
| 41.2% |
Uncovered Elements: 40 (68) |
Complexity: 28 |
Complexity Density: 0.76 |
|
26 |
|
public class ErrorLog |
27 |
|
{ |
28 |
|
private static boolean hasConsole = true; |
29 |
|
|
30 |
|
private static Class console = null; |
31 |
|
|
32 |
|
private static Method initLogger = null; |
33 |
|
|
34 |
|
private static Method errPrintln = null; |
35 |
|
|
36 |
|
private static Method outPrintln = null; |
37 |
|
|
38 |
|
private static String prefix = null; |
39 |
|
|
40 |
|
private static boolean quiet = false; |
41 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
42 |
0 |
public static void setHasConsole(boolean b)... |
43 |
|
{ |
44 |
0 |
hasConsole = b; |
45 |
|
} |
46 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
47 |
0 |
public static void setQuiet(boolean b)... |
48 |
|
{ |
49 |
0 |
quiet = b; |
50 |
|
} |
51 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
0 |
public static void setPrefix(String s)... |
53 |
|
{ |
54 |
0 |
prefix = s; |
55 |
|
} |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
14 |
public static void outPrintln(String message)... |
58 |
|
{ |
59 |
14 |
println(message, false); |
60 |
|
} |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
110 |
public static void errPrintln(String message)... |
63 |
|
{ |
64 |
110 |
println(message, true); |
65 |
|
} |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
124 |
public static void println(String message, boolean err)... |
68 |
|
{ |
69 |
124 |
println(message, err, true); |
70 |
|
} |
71 |
|
|
|
|
| 38.2% |
Uncovered Elements: 34 (55) |
Complexity: 22 |
Complexity Density: 0.71 |
|
72 |
124 |
public static void println(String message0, boolean err,... |
73 |
|
boolean thisHasConsole) |
74 |
|
{ |
75 |
124 |
if (!err && quiet) |
76 |
|
{ |
77 |
0 |
return; |
78 |
|
} |
79 |
124 |
String message = prefix == null ? message0 : prefix + message0; |
80 |
124 |
if (thisHasConsole && hasConsole) |
81 |
|
{ |
82 |
5 |
try |
83 |
|
{ |
84 |
5 |
if (console == null) |
85 |
|
{ |
86 |
5 |
Class console = Class.forName("jalview.bin.Console"); |
87 |
|
} |
88 |
5 |
if (console == null) |
89 |
|
{ |
90 |
5 |
hasConsole = false; |
91 |
|
} |
92 |
|
else |
93 |
|
{ |
94 |
0 |
if (initLogger == null && console != null) |
95 |
|
{ |
96 |
0 |
initLogger = console.getMethod("initLogger"); |
97 |
|
} |
98 |
0 |
hasConsole = console == null || initLogger == null |
99 |
|
|| (Boolean) initLogger.invoke(null); |
100 |
0 |
if (hasConsole && console != null) |
101 |
|
{ |
102 |
0 |
if (err) |
103 |
|
{ |
104 |
0 |
if (errPrintln == null) |
105 |
|
{ |
106 |
0 |
errPrintln = console.getMethod("errPrintln", String.class); |
107 |
|
} |
108 |
0 |
errPrintln.invoke(null, message); |
109 |
|
} |
110 |
|
else |
111 |
|
{ |
112 |
0 |
if (outPrintln == null) |
113 |
|
{ |
114 |
0 |
outPrintln = console.getMethod("outPrintln", String.class); |
115 |
|
} |
116 |
0 |
outPrintln.invoke(null, message); |
117 |
|
} |
118 |
|
} |
119 |
|
} |
120 |
|
} catch (ClassNotFoundException | NoSuchMethodException e) |
121 |
|
{ |
122 |
0 |
hasConsole = false; |
123 |
0 |
System.err.println( |
124 |
|
"jalview.util.ErrorLog has no jalview.bin.Console.initLogger(). Using System.err and System.out."); |
125 |
|
} catch (IllegalAccessException | IllegalArgumentException |
126 |
|
| InvocationTargetException e) |
127 |
|
{ |
128 |
0 |
hasConsole = false; |
129 |
0 |
System.err.println( |
130 |
|
"jalview.util.ErrorLog had a problem calling a method of jalview.bin.Console. Using System.err and System.out."); |
131 |
|
} catch (Exception e) |
132 |
|
{ |
133 |
0 |
e.printStackTrace(); |
134 |
|
} catch (NoClassDefFoundError t) |
135 |
|
{ |
136 |
0 |
hasConsole = false; |
137 |
0 |
System.err.println( |
138 |
|
"jalview.util.ErrorLog has no jalview.bin.Console. Using System.err and System.out."); |
139 |
|
} |
140 |
|
} |
141 |
124 |
if (!(thisHasConsole && hasConsole)) |
142 |
|
{ |
143 |
124 |
if (err) |
144 |
|
{ |
145 |
110 |
System.err.println(message); |
146 |
|
} |
147 |
|
else |
148 |
|
{ |
149 |
14 |
System.out.println(message); |
150 |
|
|
151 |
|
} |
152 |
|
} |
153 |
|
} |
154 |
|
} |