Skip to content

Commit e3453f2

Browse files
committed
StderrLogService: use stdout non-severe messages
The logging page at http://imagej.net/Logging states that severe logging messages (WARN and ERROR levels) are emitted to stderr, while less severe ones (INFO and DEBUG levels) are emitted to stdout. This was not actually true with the default LogService implementation. This commit addresses the situation. Originally, I planned to make this change with SciJava Common 3.0.0, because I thought we would need to break backwards compatibility to achieve it. But actually, the change was easy to make in a smooth manner. SJC3 will see a cleanup of the logging API, but that cleanup is not a prerequisite to fixing the situation with stdout + stderr. Thanks to Florian Jug for spurring this change.
1 parent a94ff04 commit e3453f2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/main/java/org/scijava/log/StderrLogService.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,27 @@
3737

3838
/**
3939
* Implementation of {@link LogService} using the standard error stream.
40+
* <p>
41+
* Actually, this service is somewhat misnamed now, since it prints {@code WARN}
42+
* and {@code ERROR} messages to stderr, but messages at lesser severities to
43+
* stdout.
44+
* </p>
4045
*
4146
* @author Johannes Schindelin
4247
* @author Curtis Rueden
4348
*/
4449
@Plugin(type = Service.class, priority = Priority.LOW_PRIORITY)
4550
public class StderrLogService extends AbstractLogService {
4651

52+
@Override
53+
protected void log(final int level, final Object msg) {
54+
final String prefix = getPrefix(level);
55+
final String message = (prefix == null ? "" : prefix + " ") + msg;
56+
// NB: Emit severe messages to stderr, and less severe ones to stdout.
57+
if (level <= WARN) System.err.println(message);
58+
else System.out.println(message);
59+
}
60+
4761
/**
4862
* Prints a message to stderr.
4963
*

0 commit comments

Comments
 (0)