Skip to content

Commit a6b68aa

Browse files
committed
ServiceHelper: fall back to stderr if there is no LogService yet
At the stage of the ServiceHelper, we cannot realistically assume that the LogService has been created yet: there might have been an error initializing it, it might not have been initialized yet, or there might not be any LogService available to begin with. We should fail gracefully in all those cases and simply fall back to printing to stderr instead. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 5006d2d commit a6b68aa

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/main/java/org/scijava/service/ServiceHelper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,24 +229,34 @@ private void findServiceClasses(
229229
private void info(final String msg) {
230230
final LogService log = getContext().getService(LogService.class);
231231
if (log != null) log.info(msg);
232+
else System.err.println("[INFO] " + msg);
232233
}
233234

234235
/** Logs the given warning, if a {@link LogService} is available. */
235236
private void warn(final String msg) {
236237
final LogService log = getContext().getService(LogService.class);
237238
if (log != null) log.warn(msg);
239+
else System.err.println("[WARNING] " + msg);
238240
}
239241

240242
/** Logs the given error, if a {@link LogService} is available. */
241243
private void error(final String msg, final Throwable t) {
242244
final LogService log = getContext().getService(LogService.class);
243245
if (log != null) log.error(msg, t);
246+
else {
247+
System.err.println("[ERROR] " + msg);
248+
if (t != null) t.printStackTrace();
249+
}
244250
}
245251

246252
/** Logs the given debug message, if a {@link LogService} is available. */
247253
private void debug(final String msg, final Throwable t) {
248254
final LogService log = getContext().getService(LogService.class);
249255
if (log != null) log.debug(msg, t);
256+
else {
257+
System.err.println("[DEBUG] " + msg);
258+
if (t != null) t.printStackTrace();
259+
}
250260
}
251261

252262
}

0 commit comments

Comments
 (0)