Reputation: 2563
I have a logging.properties file that I load at runtime into my java application:
final InputStream logFileInputStream= this.getClass().getResourceAsStream("mylogging.properties");
LogManager.getLogManager().readConfiguration(logFileInputStream);
This logging.properties file specifies a custom formatter:
.level = INFO
handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler
java.util.logging.ConsoleHandler.formatter = mycustom.logging.OneLineFormatter
java.util.logging.ConsoleHandler.level = FINEST
java.util.logging.FileHandler.pattern = ./logs/blubb.%g.log
java.util.logging.FileHandler.count = 31
java.util.logging.FileHandler.formatter = mycustom.logging.OneLineFormatter
java.util.logging.FileHandler.level = FINEST
This works well when run from the commandline. However, when starting the application with Java Webstart, the formatters are replaced by SimpleFormatter for the ConsoleHandler and XMLFormat for the FileHandler. The logging.properties is still being read as for example the logfiles name pattern is respected.
How can I avoid Webstart replacing my formatters?!
Upvotes: 2
Views: 218
Reputation: 11
I was facing the exact same problem. I can't tell how to stop Webstart replacing the formatter (or why it doesn't recognize it in the first place). Couldn't find a solution for it, but finally that's how I get things working for me with Webstart. I simply reassigned my custom formatter (LoggerFormatter) to the handlers during runtime:
InputStream is = this.getClass().getClassLoader().getResourceAsStream("conf/logging.properties");
LogManager.getLogManager().readConfiguration(is);
Handler[] handlers = Logger.getGlobal().getParent().getHandlers();
Formatter formatter = new LoggerFormatter();
for (Handler h : handlers) {
h.setFormatter(formatter);
}
Upvotes: 1
Reputation: 11045
LogManager.readConfiguration requires LoggingPermission("control")
when running under the security manager. By Default, WebStart runs under the security manager and console does not. It is likely that your configuration is rejected rather than your formatters being replaced.
Try granting LoggingPermission("control")
in your JNLP file as described here.
Upvotes: 0