我正在尝试来自wiki责任链文章的Logger 示例。在它打印的想法中运行示例:
Sending to stderr: An error has occurred.
Writing to stdout: Entering function y.
Writing to stdout: Step1 completed.
Sending via email: Step1 completed.
Writing to stdout: An error has occurred.
Sending via email: An error has occurred.
但是当我在 stderrs writeMessage 中设置一个断点时
class StderrLogger extends Logger {
public StderrLogger(int mask) {
this.mask = mask;
}
protected void writeMessage(String msg) {
System.err.println("Sending to stderr: " + msg);//break out here
}
}
它打印除了 std err 之外的所有消息,这里没有涉及线程,那么为什么它在运行案例的第一行打印 stderr?