| 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: 212 (212) |
Complexity: 73 |
Complexity Density: 0.6 |
|
| 36 |
|
public class Console |
| 37 |
|
{ |
| 38 |
|
|
| 39 |
|
public static JLoggerLog4j log = null; |
| 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: 9 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 294 |
0 |
public static boolean initLogger()... |
| 295 |
|
{ |
| 296 |
0 |
String level = null; |
| 297 |
0 |
try |
| 298 |
|
{ |
| 299 |
0 |
level = System.getProperty("jalview.loglevel"); |
| 300 |
0 |
if (level != null) |
| 301 |
|
{ |
| 302 |
0 |
level = JLogger.LogLevel.valueOf(level).toString(); |
| 303 |
|
} |
| 304 |
|
} catch (Exception x) |
| 305 |
|
{ |
| 306 |
0 |
Console.errPrintln( |
| 307 |
|
"Ignoring value of jalview.loglevel '" + level + "'"); |
| 308 |
|
} |
| 309 |
0 |
return initLogger(level); |
| 310 |
|
} |
| 311 |
|
|
| |
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 7 |
Complexity Density: 0.37 |
|
| 312 |
0 |
public static boolean initLogger(String providedLogLevel)... |
| 313 |
|
{ |
| 314 |
0 |
if (log != null) |
| 315 |
|
{ |
| 316 |
0 |
return true; |
| 317 |
|
} |
| 318 |
0 |
try |
| 319 |
|
{ |
| 320 |
0 |
JLogger.LogLevel logLevel = JLogger.LogLevel.INFO; |
| 321 |
|
|
| 322 |
0 |
if (providedLogLevel != null && JLogger.isLevel(providedLogLevel)) |
| 323 |
|
{ |
| 324 |
0 |
logLevel = Console.getLogLevel(providedLogLevel); |
| 325 |
|
} |
| 326 |
|
else |
| 327 |
|
{ |
| 328 |
0 |
logLevel = getCachedLogLevel(); |
| 329 |
|
} |
| 330 |
|
|
| 331 |
0 |
JLoggerLog4j.setLogfile(logfile); |
| 332 |
|
|
| 333 |
|
|
| 334 |
|
|
| 335 |
|
|
| 336 |
0 |
JLoggerLog4j.getLogger("org.apache.axis", logLevel); |
| 337 |
|
|
| 338 |
|
|
| 339 |
0 |
log = JLoggerLog4j.getLogger(Cache.JALVIEW_LOGGER_NAME, logLevel); |
| 340 |
0 |
log.info("Logging initialised at level: " + logLevel); |
| 341 |
|
} catch (NoClassDefFoundError e) |
| 342 |
|
{ |
| 343 |
0 |
jalview.bin.Console |
| 344 |
|
.errPrintln("Could not initialise the logger framework"); |
| 345 |
0 |
Console.printStackTrace(e); |
| 346 |
|
} |
| 347 |
|
|
| 348 |
|
|
| 349 |
0 |
if (log != null) |
| 350 |
|
{ |
| 351 |
|
|
| 352 |
0 |
if (log.loggerExists()) |
| 353 |
0 |
log.debug(Console.LOGGING_TEST_MESSAGE); |
| 354 |
|
|
| 355 |
0 |
debug(ChannelProperties.getProperty("app_name") |
| 356 |
|
+ " Debugging Output Follows."); |
| 357 |
0 |
return true; |
| 358 |
|
} |
| 359 |
|
else |
| 360 |
|
{ |
| 361 |
0 |
return false; |
| 362 |
|
} |
| 363 |
|
} |
| 364 |
|
|
| |
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 365 |
0 |
public static void setLogLevel(String logLevelString)... |
| 366 |
|
{ |
| 367 |
0 |
LogLevel l = null; |
| 368 |
0 |
try |
| 369 |
|
{ |
| 370 |
0 |
l = LogLevel.valueOf(logLevelString); |
| 371 |
|
} catch (IllegalArgumentException | NullPointerException e1) |
| 372 |
|
{ |
| 373 |
0 |
Console.debug("Invalid log level '" + logLevelString + "'"); |
| 374 |
0 |
return; |
| 375 |
|
} |
| 376 |
0 |
setLogLevel(l); |
| 377 |
|
} |
| 378 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 379 |
0 |
public static void setLogLevel(LogLevel l)... |
| 380 |
|
{ |
| 381 |
0 |
if (l != null) |
| 382 |
|
{ |
| 383 |
0 |
log.setLevel(l); |
| 384 |
0 |
JLoggerLog4j.getLogger("org.apache.axis", l); |
| 385 |
|
} |
| 386 |
|
} |
| 387 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 388 |
0 |
public static void outPrint()... |
| 389 |
|
{ |
| 390 |
0 |
outPrint(""); |
| 391 |
|
} |
| 392 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 393 |
0 |
public static void outPrintln()... |
| 394 |
|
{ |
| 395 |
0 |
outPrintln(""); |
| 396 |
|
} |
| 397 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 398 |
0 |
public static void outPrint(Object message)... |
| 399 |
|
{ |
| 400 |
0 |
outPrintMessage(message, false, false); |
| 401 |
|
} |
| 402 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 403 |
0 |
public static void outPrint(Object message, boolean forceStdout)... |
| 404 |
|
{ |
| 405 |
0 |
outPrintMessage(message, false, forceStdout); |
| 406 |
|
} |
| 407 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 408 |
0 |
public static void outPrintln(Object message)... |
| 409 |
|
{ |
| 410 |
0 |
outPrintMessage(message, true, false); |
| 411 |
|
} |
| 412 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 5 |
Complexity Density: 1.67 |
|
| 413 |
0 |
public static PrintStream outputStream(boolean forceStdout)... |
| 414 |
|
{ |
| 415 |
|
|
| 416 |
0 |
if (!forceStdout && Jalview.instanceExists() |
| 417 |
|
&& Jalview.getInstance().getBootstrapArgs() != null |
| 418 |
|
&& Jalview.getInstance().getBootstrapArgs().outputToStdout()) |
| 419 |
|
{ |
| 420 |
0 |
return err; |
| 421 |
|
} |
| 422 |
|
else |
| 423 |
|
{ |
| 424 |
0 |
return out; |
| 425 |
|
} |
| 426 |
|
} |
| 427 |
|
|
| |
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 428 |
0 |
public static void outPrintMessage(Object message, boolean newline,... |
| 429 |
|
boolean forceStdout) |
| 430 |
|
{ |
| 431 |
0 |
PrintStream ps = outputStream(forceStdout); |
| 432 |
0 |
if (newline) |
| 433 |
|
{ |
| 434 |
0 |
ps.println(message); |
| 435 |
|
} |
| 436 |
|
else |
| 437 |
|
{ |
| 438 |
0 |
ps.print(message); |
| 439 |
|
} |
| 440 |
|
} |
| 441 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 442 |
0 |
public static void errPrint()... |
| 443 |
|
{ |
| 444 |
0 |
errPrint(""); |
| 445 |
|
} |
| 446 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 447 |
0 |
public static void errPrintln()... |
| 448 |
|
{ |
| 449 |
0 |
errPrintln(""); |
| 450 |
|
} |
| 451 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 452 |
0 |
public static void errPrint(Object message)... |
| 453 |
|
{ |
| 454 |
0 |
err.print(message); |
| 455 |
|
} |
| 456 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 457 |
0 |
public static void errPrintln(Object message)... |
| 458 |
|
{ |
| 459 |
0 |
err.println(message); |
| 460 |
|
} |
| 461 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 462 |
0 |
public static void debugPrintStackTrace(Throwable t)... |
| 463 |
|
{ |
| 464 |
0 |
if (!isDebugEnabled()) |
| 465 |
|
{ |
| 466 |
0 |
return; |
| 467 |
|
} |
| 468 |
|
|
| 469 |
0 |
printStackTrace(t); |
| 470 |
|
} |
| 471 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 472 |
0 |
public static void printStackTrace(Throwable t)... |
| 473 |
|
{ |
| 474 |
|
|
| 475 |
0 |
t.printStackTrace(err); |
| 476 |
|
} |
| 477 |
|
|
| 478 |
|
public final static String LOGGING_TEST_MESSAGE = "Logging to STDERR"; |
| 479 |
|
|
| 480 |
|
} |