Interaction of Configuration.setLogger() and Configuration.setStandardErrorOutput()
This is a spin-off of bug #4760
Configuration.setStandardErrorOutput() seem to be relics of two different attempts to allow applications to redirect system messages, but neither has been well tested, and they don't play nicely together.
If I set an initializer that calls Configuration.setLogger(), then Verifier fails with an NPE trying to display the license message. The license message is sent to config.getStandardErrorOutput(), which is null if a Logger has been set. The implication is that config.setLogger() simply doesn't work. At any rate, the relationship of config.setStandardErrorOutput() and config.setLogger() is complex and poorly explained.
Tried getting around this by making the Logger extend StandardErrorLogger, but that doesn't work either, because the ErrorReporter used by the run-time Controller doesn't use the Logger registered with the Configuration.
So I'm coming to the conclusion that when running from the command line, there's no way to redirect run-time transformation warnings to a destination other than System.err.
#2 Updated by Michael Kay about 1 year ago
Working on the Saxon 11 branch, I've started by creating a test in TransformTests that uses setLogger() with a custom logger; this provides a way of testing the content of messages that would normally go to System.err (from a simulated command line call) in a JUnit test.
This shows up the NPE when reporting the license file serial number.
I'm now going to try and ensure that all such messages go via the Logger.
#3 Updated by Michael Kay about 1 year ago
Most messages sent to
System.err are now changed to go via
Help messages from CommandLineOptions in response to -? go directly to
System.err, because they are output before a
Configurationhas been created.
Messages from the (default)
MessageEmitter(for xsl:message) go to
Messages that are never output except when doing internal debugging
Some messages for fatal error conditions where no Configuration is available
#4 Updated by Michael Kay about 1 year ago
So what to do about get/set StandardErrorOutput in Configuration?
The only place it's now used is for xsl:message output, and I'm handling that by adding a Logger.asWriter() method (with a default implementation) that supplies a Writer which writes to the Logger, and the default MessageEmitter will use this by default.
We have a write-only configuration property Feature.STANDARD_ERROR_OUTPUT_FILE which can be used (in principle) to redirect standard error output. I propose that this property, and the method Configuration.setStandardErrorOutput(), should take no action unless the Logger is a StandardLogger, in which case they should set the output destination for the standard logger.
Configuration.getStandardErrorOutput() so it returns the output destination of the
Logger if it's a
StandardLogger, or System.err otherwise.
Please register to edit this issue