45 * (defaults to no <tt>Filter</tt>). </li> 46 * <li> <handler-name>.formatter 47 * specifies the name of a <tt>Formatter</tt> class to use 48 * (defaults to <tt>java.util.logging.SimpleFormatter</tt>). </li> 49 * <li> <handler-name>.encoding 50 * the name of the character set encoding to use (defaults to 51 * the default platform encoding). </li> 52 * </ul> 53 * <p> 54 * For example, the properties for {@code ConsoleHandler} would be: 55 * <ul> 56 * <li> java.util.logging.ConsoleHandler.level=INFO </li> 57 * <li> java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter </li> 58 * </ul> 59 * <p> 60 * For a custom handler, e.g. com.foo.MyHandler, the properties would be: 61 * <ul> 62 * <li> com.foo.MyHandler.level=INFO </li> 63 * <li> com.foo.MyHandler.formatter=java.util.logging.SimpleFormatter </li> 64 * </ul> 65 * <p> 66 * @since 1.4 67 */ 68 public class ConsoleHandler extends StreamHandler { 69 70 /** 71 * Create a <tt>ConsoleHandler</tt> for <tt>System.err</tt>. 72 * <p> 73 * The <tt>ConsoleHandler</tt> is configured based on 74 * <tt>LogManager</tt> properties (or their default values). 75 * 76 */ 77 public ConsoleHandler() { 78 // configure with specific defaults for ConsoleHandler 79 super(Level.INFO, new SimpleFormatter(), null); 80 81 setOutputStreamPrivileged(System.err); 82 } 83 84 /** 85 * Publish a <tt>LogRecord</tt>. 86 * <p> 87 * The logging request was made initially to a <tt>Logger</tt> object, 88 * which initialized the <tt>LogRecord</tt> and forwarded it here. 89 * <p> 90 * @param record description of the log event. A null record is 91 * silently ignored and is not published 92 */ 93 @Override 94 public void publish(LogRecord record) { 95 super.publish(record); 96 flush(); 97 } 98 99 /** 100 * Override <tt>StreamHandler.close</tt> to do a flush but not 101 * to close the output stream. That is, we do <b>not</b> 102 * close <tt>System.err</tt>. 103 */ 104 @Override 105 public void close() { 106 flush(); 107 } 108 } | 45 * (defaults to no <tt>Filter</tt>). </li> 46 * <li> <handler-name>.formatter 47 * specifies the name of a <tt>Formatter</tt> class to use 48 * (defaults to <tt>java.util.logging.SimpleFormatter</tt>). </li> 49 * <li> <handler-name>.encoding 50 * the name of the character set encoding to use (defaults to 51 * the default platform encoding). </li> 52 * </ul> 53 * <p> 54 * For example, the properties for {@code ConsoleHandler} would be: 55 * <ul> 56 * <li> java.util.logging.ConsoleHandler.level=INFO </li> 57 * <li> java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter </li> 58 * </ul> 59 * <p> 60 * For a custom handler, e.g. com.foo.MyHandler, the properties would be: 61 * <ul> 62 * <li> com.foo.MyHandler.level=INFO </li> 63 * <li> com.foo.MyHandler.formatter=java.util.logging.SimpleFormatter </li> 64 * </ul> 65 * 66 * @since 1.4 67 */ 68 public class ConsoleHandler extends StreamHandler { 69 70 /** 71 * Create a <tt>ConsoleHandler</tt> for <tt>System.err</tt>. 72 * <p> 73 * The <tt>ConsoleHandler</tt> is configured based on 74 * <tt>LogManager</tt> properties (or their default values). 75 * 76 */ 77 public ConsoleHandler() { 78 // configure with specific defaults for ConsoleHandler 79 super(Level.INFO, new SimpleFormatter(), null); 80 81 setOutputStreamPrivileged(System.err); 82 } 83 84 /** 85 * Publish a <tt>LogRecord</tt>. 86 * <p> 87 * The logging request was made initially to a <tt>Logger</tt> object, 88 * which initialized the <tt>LogRecord</tt> and forwarded it here. 89 * 90 * @param record description of the log event. A null record is 91 * silently ignored and is not published 92 */ 93 @Override 94 public void publish(LogRecord record) { 95 super.publish(record); 96 flush(); 97 } 98 99 /** 100 * Override <tt>StreamHandler.close</tt> to do a flush but not 101 * to close the output stream. That is, we do <b>not</b> 102 * close <tt>System.err</tt>. 103 */ 104 @Override 105 public void close() { 106 flush(); 107 } 108 } |