src/share/classes/java/util/logging/ConsoleHandler.java
Print this page
@@ -24,10 +24,13 @@
*/
package java.util.logging;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
/**
* This <tt>Handler</tt> publishes log records to <tt>System.err</tt>.
* By default the <tt>SimpleFormatter</tt> is used to generate brief summaries.
* <p>
* <b>Configuration:</b>
@@ -64,16 +67,18 @@
* </ul>
* <p>
* @since 1.4
*/
public class ConsoleHandler extends StreamHandler {
- // Private method to configure a ConsoleHandler from LogManager
+ // Private PrivilegedAction to configure a ConsoleHandler from LogManager
// properties and/or default values as specified in the class
// javadoc.
- private void configure() {
+ private class ConfigureAction implements PrivilegedAction<Void> {
+ @Override
+ public Void run() {
LogManager manager = LogManager.getLogManager();
- String cname = getClass().getName();
+ String cname = ConsoleHandler.this.getClass().getName();
setLevel(manager.getLevelProperty(cname +".level", Level.INFO));
setFilter(manager.getFilterProperty(cname +".filter", null));
setFormatter(manager.getFormatterProperty(cname +".formatter", new SimpleFormatter()));
try {
@@ -84,24 +89,24 @@
} catch (Exception ex2) {
// doing a setEncoding with null should always work.
// assert false;
}
}
+ setOutputStream(System.err);
+ return null;
+ }
}
/**
* Create a <tt>ConsoleHandler</tt> for <tt>System.err</tt>.
* <p>
* The <tt>ConsoleHandler</tt> is configured based on
* <tt>LogManager</tt> properties (or their default values).
*
*/
public ConsoleHandler() {
- sealed = false;
- configure();
- setOutputStream(System.err);
- sealed = true;
+ AccessController.doPrivileged(new ConfigureAction(), null, LogManager.controlPermission);
}
/**
* Publish a <tt>LogRecord</tt>.
* <p>